**DESCRIPTION** This page is made to share your tips and tricks on this page that can help in making Android applications using [AndroWish]. Please try to be as specific as you can about AndroWish specific commands e.g. [borg] and [sdltk] . and touch screen events Please give as many relevant examples as you can. [Superlinux]: An example on using `<>` . A simple way to zoom the size of your app by changing the default font of the whole GUI made by Tk : ====== set font_size 3 ;# default starting font size is set to 3 . set old_fingers_pinch_to_zoom_distance 0 ;# keeps track of the distance between the pinching fingers before moving the fingers to do the pinch move proc pinch_to_zoom { fingers_distance } { global old_fingers_pinch_to_zoom_distance global font_size if { $fingers_distance > $old_fingers_pinch_to_zoom_distance } { incr font_size font configure TkDefaultFont -size $font_size set old_fingers_pinch_to_zoom_distance $fingers_distance return } if { $fingers_distance < $old_fingers_pinch_to_zoom_distance } { if { $font_size <=3 } { set font_size 3 return } incr font_size -1 font configure TkDefaultFont -size $font_size set old_fingers_pinch_to_zoom_distance $fingers_distance return } } font configure TkDefaultFont -size $font_size bind . <> { pinch_to_zoom %x } ;# remember that %x is the distance between pinching fingers ====== ---- [JM] 3/21/2014, If you use Windows PC to edit your scripts, having SSHDroid on your Android device works very well with http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html%|%pscp%|% launched like this from the DOS command line: pscp -P 2222 C:\Tcl\code\logo2.tcl root@192.168.1.64:/sdcard/ In the example I am copying my logo2.tcl script to /sdcard/ on the Android device which IP address is 192.168.1.64 in this case. "admin" is the default password. ---- [JM] 8/9/2014, my set of rc files...<
> .wishrc set env(HOME) /sdcard cd ~ source wishrc.tcl "copywrc.tcl", which I only use when I install a new [Androwish] version: file delete /data/data/tk.tcl.wish/files/.wishrc file copy .wishrc /data/data/tk.tcl.wish/files "wishrc.tcl", this is used to immediately get a file browser dialog to select the script I want to run: sdltk textinput on set script [tk_getOpenFile] if {$script != ""} { source $script console hide } else { puts "hello!" } ---- [JM] 8/9/2014, Connecting to an Andriod device when it is running SSHDroid:<
> I am using Ubuntu: ssh -p 2222 root@192.168.1.71 See you specific port an ip address on the SSHDroid screen running on your Android.<
> default password is "admin" ---- '''[Superlinux] - 2014-03-27 10:35:07''' This is an example on how to send your text or HTML file to printing on paper using PrintBot. You can find PrintBot in this link http://play.google.com/store/apps/details?id=net.jsecurity.printbot%|%here%|% PrinterBot is a network printer driver for Android. It can run Internet Printing Protocol (IPP). On Linux, as a test, install CUPS-PDF and CUPS printer server and make it shared on the local network. ====== borg activity net.jsecurity.printbot.action.PRINT "file:///mnt/sdcard/test-page.txt" "text/html" {} {} { borg toast "Printing completed" } ====== ----- [ET] Well, AW made my first android tablet purchase worth every penny. So, here's my .wishrc, with some console fun. Also handy for fat fingers. It adds buttons to the console window. Warning, '''careful here''' if you mangle this, you might not have a console to use to correct your .wishrc file in the protected zone. I have followed the lead here of having files in /sdcard/home which I can modify, and then copy as needed to the protected AW zone. So, it goes there first, and if wishrc.tcl is found, sources it after it modifies the console window. The copyit button on the console window will do that for you if you use these folder conventions. It does want a confirmation. Same with exit. The +x/-x resize the x size of the console window. Bottom scrolls you to the bottom, and you can disable scrolling with the checkbox. I also increase the number of lines to 1000. update: Fixed problem with width adjustments, seems wm geom . is different here than on my winxp system ====== if { $tcl_platform(os) != "Windows NT" } { # to test on winxp before going live on android set env(HOME) /sdcard/home cd ~ } else { console show } package require Tk # a menu item runs this, it's defined here, not inside the console eval proc menudo {} { puts "pressed-menu" } if [catch { console eval { if { ![info exist ::tk::do_scroll] } { set menuincr 0 ;# some consoles have an extra item in the edit menu (a font...) AW doesn't, so leave at 0 for now set fontsz {times 9} pack forget .console .sb .consoleframe pack [frame .frame -bg black] -side left -fill y -ipady 2 -pady 2 pack [button .frame.clear -bg blue -fg white -text Clear -command {.menubar.file invoke 2} -font $fontsz] -side top -fill x pack [button .frame.smaller -bg white -text {font -} -font $fontsz -command {.menubar.edit invoke [expr ( $menuincr+6 )];after 100 {.frame.repos invoke}}] -side top -fill x pack [button .frame.bigger -bg white -text {font +} -font $fontsz -command {.menubar.edit invoke [expr ( $menuincr+5 )];after 100 {.frame.repos invoke}}] -side top -fill x pack [button .frame.exit -bg red -fg white -text Exit -font $fontsz -command {exiter}] -side top -fill x pack [button .frame.repos -bg white -text Bottom -font $fontsz -command {.console see end; .console mark set insert end}] -side top -fill x pack [frame .frame.frame -bg black] -side top -fill x pack [button .frame.frame.m10 -bg gray -fg white -font $fontsz -text -x -command { if { [.console cget -width] > 30 } { .console config -width [expr ( [.console cget -width]-10 )] } }] -side top -fill x -expand 1 pack [button .frame.frame.p10 -bg gray -fg white -font $fontsz -text +x -command { if { [.console cget -width] < 120 } { .console config -width [expr ([.console cget -width]+10)] } }] -side top -fill x -expand 1 pack [checkbutton .frame.scroll -bg white -fg black -text scroll -font $fontsz -variable ::tk::do_scroll] -side top -fill x pack [button .frame.frame.mit -bg green -fg white -font $fontsz -text copyit -command copyit] -side top -fill x -expand 1 pack .consoleframe -in . -anchor center -expand 1 -fill both -ipadx 0 -ipady 0 -padx 0 -pady 0 -side left pack .console -in .consoleframe -anchor center -expand 1 -fill both -ipadx 0 -ipady 0 -padx 1 -pady 1 -side left pack .sb -in .consoleframe -anchor center -expand 1 -fill both -ipadx 0 -ipady 0 -padx 1 -pady 1 -side right #puts "console width now [.console config -width] [wm geom .]" ;# hmmm, seems wm geom different across platforms here proc copyit {} { set answer [tk_messageBox -message "Please confirm\nto copy .wishrc" -icon question -type yesno] if { $answer == "yes" } { file copy -force .wishrc /data/data/tk.tcl.wish/files/ puts copied } } proc exiter {} { set answer [tk_messageBox -message "Please confirm to Exit." -icon question -type yesno] if { $answer == "yes" } { exit } } set ::tk::console::maxLines 1000 .menubar add casc -label Extra -menu [menu .menubar.extra -tearoff 0] proc menu+ {head label cmd} { set cmd2 [list consoleinterp eval $cmd] .menubar.$head add command -label $label -command $cmd2 ;# note this is defined outside the console eval... its in the normal namespace } menu+ extra menu menudo proc ::tk::ConsoleOutput {dest string} { set w .console $w insert output $string $dest ::tk::console::ConstrainBuffer $w $::tk::console::maxLines if {$::tk::do_scroll} {$w see insert} } set ::tk::do_scroll 1 } } } err_code] { puts $err_code } if { $tcl_platform(os) != "Windows NT" } { if { [file exist wishrc.tcl] } { puts "sourcing wishrc.tcl" source wishrc.tcl } else { puts stderr "wishrc.tcl not found" } } ====== Here's some more fun with the console and a little test of flashing a button. It should run on any 8.6 setup. I call it wishrc.tcl to test it on my tablet. ====== button .b -text "push me\nafter I stop" -command {wm wi .} -bg black -fg white pack .b -fill both -expand true proc uniqkey { } { set key [ expr { pow(2,31) + [ clock clicks ] } ] set key [ string range $key end-8 end-3 ] set key [ clock seconds ]$key return $key } proc sleep { ms } { set uniq [ uniqkey ] set ::__sleep__tmp__$uniq 0 after $ms set ::__sleep__tmp__$uniq 1 vwait ::__sleep__tmp__$uniq unset ::__sleep__tmp__$uniq } proc cputs {dest string} { if { ! [info exist ::tk::my_color_set] } { set ::tk::my_color_set 1 console eval { .console tag configure green -foreground \#00ff00 -background black .console tag configure yellowonblack -foreground yellow -background black -font {courier 14 bold} .console tag configure yellow -foreground yellow .console tag configure whiteonred -foreground white -background red .console tag configure red -foreground red } } console eval [list ::tk::ConsoleOutput $dest $string] } sleep 1000 wm geom . 200x200+100+100 sleep 2000 for {set m 0} {$m < 5} {incr m} { .b config -bg red -fg white sleep 50 .b config -bg white -fg red sleep 50 } parray env console show cputs whiteonred "white on red " cputs yellowonblack " And yellow on black and big\n" ====== ---- '''[Superlinux] - 2014-05-05 12:29:55''' I want to highlight a little thing which comes handy, and I know to any programmer this would look silly after you read it. Now how about hearing the message of [[ tk_messageBox ]] ? Yes! I know there's [[ borg speak $message ]] ; but this is how you should utilize it: * If you want to hear the $message ''while'' the [[tk_messageBox]] is still on the screen first you start [[borg speak $message]] then run [[tk_messageBox]] . Example: ====== set message "Warning! You are trespassing Java in Android using Tcl/Tk and AndroWish!" borg speak $message tk_messageBox -message $message -icon warning ====== * If you want to hear the $message ''after'' the [[tk_messageBox]] vanishes from the screen first you start [[tk_messageBox]] then run [[borg speak $message]] . Example: ====== set message "Warning! You are trespassing Java in Android using Tcl/Tk and AndroWish!" tk_messageBox -message $message -icon warning borg speak $message ====== This should show and prove you that [[borg speak]] works in a separate thread. -- [RS] 2014-05-08: As I just tested in an interactive [wish] on Windows 7, [tk_messageBox] just blocks until dismissed with the OK button. <>Android