Version 3 of Making Tk apps look native

Updated 2002-07-19 14:43:18

With a compiler, and a modified tclAppInit, it is of course pretty easy to make a executable to run a particular set of tcl/tk code. However, it is nice to be able to write pure tcl/tk as much as possible to accomplish the same task. There are a few aspects to this:

  • provide an icon for the application which can be double-clicked on to run
  • allow drag-n-drop of documents onto the icon to interact with them
  • allow other applications to send files to the application.
  • ...

Obviously there may be some platform-specific aspects to correct "native" behaviour as well (for example on Windows, we might want to add a shortcut to the application and its help/readme to the Start->Programs menu).

Windows

On Windows, any .tcl file can be double-click to launch wish by default. We can also easily add the application to the Programs menu as follows:

    windows::CreateGroup Alphatk ~/Apps/Alphatk8.1 alphatk.tcl AlphaCore/alpha.icr

    package require dde
    proc windows::CreateGroup {name root script icon} {
        # This won't work with a scripted document.  In that case
        # we will have to be a bit cleverer...
        windows::ProgmanExecute CreateGroup $name
        windows::ProgmanExecute AddItem [file join $root $script] \
          $name $iconfile
        windows::ProgmanExecute AddItem [file join $root Readme.txt] \
          Readme
    }

    proc windows::ProgmanExecute {name args} {
        eval [list windows::DdeExecute PROGMAN PROGMAN $name] $args
    }

    proc windows::DdeExecute {service topic name args} {
        set cmd "\[$name\("
        set subcmds [list]
        foreach a $args {
            lappend subcmds "\"$a\""
        }
        append cmd [join $subcmds ","] "\)\]"
        dde execute $service $topic $cmd
    }

But how can we allow 'drag-n-drop' onto an icon for our application?

Unix

please fill in

MacOS

please fill in

MacOS X

please fill in


[Wasn't someone intending to write up a bunch of options to mollify Tk's appearance? I remember things like fiddling with borderwidths on Windows, and so on ...]