[PD-cvs] SF.net SVN: pure-data:[10539] branches/pd-devel/0.41.4/src

eighthave at users.sourceforge.net eighthave at users.sourceforge.net
Tue Jan 13 19:39:26 CET 2009


Revision: 10539
          http://pure-data.svn.sourceforge.net/pure-data/?rev=10539&view=rev
Author:   eighthave
Date:     2009-01-13 18:39:26 +0000 (Tue, 13 Jan 2009)

Log Message:
-----------
- replaced [tk windowingsystem] with $::windowingsystem to make supporting
  Tcl/Tk 8.3 easy and the code easier to read for non-Tclers

- moved config procs out of 'namespace eval' because its cleaner and is needed
  to support the global variable $::windowingsystem

- moved some commented bits of code around to more appropriate places

Modified Paths:
--------------
    branches/pd-devel/0.41.4/src/pd.tk
    branches/pd-devel/0.41.4/src/pd_bindings.tcl
    branches/pd-devel/0.41.4/src/pd_menus.tcl
    branches/pd-devel/0.41.4/src/pdtk_text.tcl
    branches/pd-devel/0.41.4/src/wheredoesthisgo.tcl

Modified: branches/pd-devel/0.41.4/src/pd.tk
===================================================================
--- branches/pd-devel/0.41.4/src/pd.tk	2009-01-13 18:14:05 UTC (rev 10538)
+++ branches/pd-devel/0.41.4/src/pd.tk	2009-01-13 18:39:26 UTC (rev 10539)
@@ -14,14 +14,22 @@
 package require Tcl 8.3
 package require Tk
 
-## replace Tk widgets with Ttk widgets
+## replace Tk widgets with Tile/Ttk widgets (Tile/Ttk is included in Tcl/Tk 8.5)
 #package require tile
 #namespace import -force ttk::*
 
-# set . as first dir in auto_path
-set auto_path [linsert $auto_path 0 "/Users/hans/code/pure-data/branches/pd-devel/0.41.4/src"]
-set auto_path [linsert $auto_path 0 "."]
+#------------------------------------------------------------------------------#
+# global variables
 
+
+# file types for Open/Save panels
+set filetypes ""
+
+# for testing which platform we are running on ("aqua", "win32", or "x11")
+set windowingsystem ""
+
+#------------------------------------------------------------------------------#
+# packages for this project
 package require pd_connect
 package require pd_menus
 package require pd_bindings
@@ -43,9 +51,10 @@
 #
 # - when possible use "" doublequotes to delimit messages
 # - instead of 'global myvar' use '$::myvar'
+# - for the sake of clarity, there should not be any inline code, everything 
+#   should be in a procedure that is ultimately triggered from main()
 #
 #
-#
 ## Names for Common Variables
 #----------------------------
 #
@@ -57,36 +66,6 @@
 #   $mycanvas = 'canvas'
 #   $canvasitem = 'canvas' item
 
-
-
-#------------------------------------------------------------------------------#
-# global variables
-
-
-# file types for Open/Save panels
-set filetypes ""
-
-# for the sake of clarity, I think there should not be any inline code,
-# everything should be in a procedure that is ultimately triggered from main()
-# -hans at eds.org
-
-#array set cmd_ops {}
-
-# the only arg for pd.tk is the port number to connect to 'pd' on, but this
-# code would be useful for opening files via drag-n-drop, the open panel, etc.
-#for {set i 0} {$i < $argc} {incr i} {
-#	global cmd_ops files_to_open
-#	set o [lindex $argv $i]
-#	switch -regexp -- $o {
-#		^-lang\$ {incr i; set cmd_ops(lang) [lindex $argv $i]}
-#		default {lappend files_to_open [lindex $argv $i]}
-#	}
-#}
-
-# no english support yet, so I am commenting this out
-#if {![info exists cmd_ops(lang)]} {set cmd_ops(lang) "en"}
-#init_locale
-
 # ------------------------------------------------------------------------------
 # quoting functions
 
@@ -101,7 +80,13 @@
 # init functions
 
 proc init {} {
-	switch -- [tk windowingsystem] {
+	# we are not using Tk scaling, so fix it to 1 on all platforms.  This
+	# guarantees that patches will be pixel-exact on every platform
+	tk scaling 1
+
+	# Tcl/Tk 8.3 doesn't have [tk windowingsystem]
+	set ::windowingsystem [tk windowingsystem]
+	switch -- $::windowingsystem {
 		"x11" {
 			# add control to show/hide hidden files in the open panel (load
 			# the tk_getOpenFile dialog once, otherwise it will not work)
@@ -172,7 +157,7 @@
 
 	# TODO slide off screen windows into view
 	wm geometry $mytoplevel $geometry
-	if {[tk windowingsystem] eq "aqua"} {
+	if {$::windowingsystem eq "aqua"} {
 		wm minsize $mytoplevel 50 20
 	} else { # leave room for the menubar
 		wm minsize $mytoplevel 310 30
@@ -207,10 +192,11 @@
 	post_tclinfo
 	pdtk_post "Starting pd.tk with main($argc $argv)"
 	init
-	# we are not using Tk scaling, so fix it to 1 on all platforms.  This
-	# guarantees that patches will be pixel-exact on every platform
-	tk scaling 1
 
+	# no english support yet, so I am commenting this out
+	#if {![info exists cmd_ops(lang)]} {set cmd_ops(lang) "en"}
+	#init_locale
+
 	# TODO check args for -stderr and set pdtk_post accordingly
 
 	::pd_menus::create_menubar .menubar

Modified: branches/pd-devel/0.41.4/src/pd_bindings.tcl
===================================================================
--- branches/pd-devel/0.41.4/src/pd_bindings.tcl	2009-01-13 18:14:05 UTC (rev 10538)
+++ branches/pd-devel/0.41.4/src/pd_bindings.tcl	2009-01-13 18:39:26 UTC (rev 10539)
@@ -9,18 +9,19 @@
 	namespace export window_bindings
 	namespace export panel_bindings
 	namespace export canvas_bindings
+}
 
+proc ::pd_bindings::window_bindings {mytoplevel} {
+	variable modifier
+
 	# for key bindings
-	if {[tk windowingsystem] eq "aqua"} {
+	puts "::windowingsystem $::windowingsystem"
+	if {$::windowingsystem eq "aqua"} {
 		set modifier "Mod1"
 	} else {
 		set modifier "Control"
 	}
-}
 
-proc ::pd_bindings::window_bindings {mytoplevel} {
-	variable modifier
-
 	# File menu
 	bind $mytoplevel <$modifier-Key-b>        "menu_helpbrowser"
 	bind $mytoplevel <$modifier-Key-n>        "menu_new"
@@ -74,10 +75,10 @@
 
 proc ::pd_bindings::canvas_bindings {mytoplevel} {
 	variable modifier
+	set mycanvas $mytoplevel.c
 
 	window_bindings $mytoplevel
-	set mycanvas $mytoplevel.c
-	
+
 	# key bindings -------------------------------------------------------------
 	bind $mytoplevel <$modifier-Key-1>        "pdsend \"$mytoplevel obj ;\""
 	bind $mytoplevel <$modifier-Key-2>        "pdsend \"$mytoplevel msg ;\""
@@ -110,7 +111,7 @@
 	bind $mytoplevel <$modifier-Shift-Key-V> "pdsend \"$mytoplevel vslider 1 ;\""
 	bind $mytoplevel <$modifier-Shift-Key-Z> "menu_redo $mytoplevel"
 	
-	if {[tk windowingsystem] eq "aqua"} {
+	if {$::windowingsystem eq "aqua"} {
 		bind $mytoplevel <$modifier-Key-m>   "menu_minimize $mytoplevel"
 		bind $mytoplevel <$modifier-Key-t>   "menu_font $mytoplevel"
         bind $mytoplevel <$modifier-quoteleft> "menu_raisenextwindow"
@@ -127,7 +128,7 @@
     bind $mycanvas <ButtonRelease>        "pdtk_canvas_mouseup %W %x %y %b"
 	bind $mycanvas <$modifier-Button>     "pdtk_canvas_mouse %W %x %y %b 0"
 	# TODO look into "virtual events' for a means for getting Shift-Button, etc.
-	switch {[tk windowingsystem]} { 
+	switch {$::windowingsystem} { 
 		"aqua" {
 			# on Mac OS X, emulate a rightclick with Ctrl-click
 			bind $mycanvas <Ctrl-Button>  "pdtk_canvas_rightclick %W %x %y %b"

Modified: branches/pd-devel/0.41.4/src/pd_menus.tcl
===================================================================
--- branches/pd-devel/0.41.4/src/pd_menus.tcl	2009-01-13 18:14:05 UTC (rev 10538)
+++ branches/pd-devel/0.41.4/src/pd_menus.tcl	2009-01-13 18:39:26 UTC (rev 10539)
@@ -28,12 +28,6 @@
 	namespace export create_menubar
 	namespace export configure_pdwindow
 
-	if {[tk windowingsystem] eq "aqua"} {
-		set accelerator "Cmd"
-	} else {
-		set accelerator "Ctrl"
-	}
-
 	# turn off tearoff menus globally
 	option add *tearOff 0
 }
@@ -41,16 +35,22 @@
 # ------------------------------------------------------------------------------
 # 
 proc ::pd_menus::create_menubar {mymenubar} {
+	variable accelerator
+	if {$::windowingsystem eq "aqua"} {
+		set accelerator "Cmd"
+	} else {
+		set accelerator "Ctrl"
+	}
 	menu $mymenubar
 	set menulist "file edit put find media window help"
-	if { [tk windowingsystem] eq "aqua" } {create_apple_menu $mymenubar}
-	if { [tk windowingsystem] eq "win32" } {create_system_menu $mymenubar}
+	if { $::windowingsystem eq "aqua" } {create_apple_menu $mymenubar}
+	if { $::windowingsystem eq "win32" } {create_system_menu $mymenubar}
 	foreach mymenu $menulist {	
 		menu $mymenubar.$mymenu
 		$mymenubar add cascade -label [string totitle $mymenu] \
 			-menu $mymenubar.$mymenu
 		[format build_%s_menu $mymenu] $mymenubar.$mymenu PLACEHOLDER
-		if {[tk windowingsystem] eq "win32"} {
+		if {$::windowingsystem eq "win32"} {
 			# fix menu font size on Windows with tk scaling = 1
 			$mymenubar.$mymenu configure -font menufont
 		}
@@ -191,7 +191,7 @@
 # ------------------------------------------------------------------------------
 # menu building functions
 proc ::pd_menus::build_file_menu {mymenu mytoplevel} {
-	[format build_file_menu_%s [tk windowingsystem]] $mymenu
+	[format build_file_menu_%s $::windowingsystem] $mymenu
 	$mymenu entryconfigure [say "new_file"]   -command "menu_new"
 	$mymenu entryconfigure [say "Open"]       -command "menu_open"
 	$mymenu entryconfigure [say "Save"]       -command "pdsend \"$mytoplevel menusave ;\""
@@ -220,7 +220,7 @@
 	$mymenu add command -label [say "Select All"] -accelerator "$accelerator+A" \
 		-command "pdsend \"$mytoplevel selectall ;\""
 	$mymenu add  separator
-	if {[tk windowingsystem] eq "aqua"} {
+	if {$::windowingsystem eq "aqua"} {
 		$mymenu add command -label [say "Text Editor"] \
 			-command "menu_texteditor $mytoplevel"
 		$mymenu add command -label [say "Font"]  -accelerator "$accelerator+T" \
@@ -245,7 +245,7 @@
 	#        $mymenu entryconfigure "Edit Mode" -indicatoron false 
 	#    }
 
-	if {[tk windowingsystem] ne "aqua"} {
+	if {$::windowingsystem ne "aqua"} {
 		$mymenu add  separator
 		$mymenu add command -label [say "Preferences"] \
 			-command "menu_preferences"
@@ -313,7 +313,7 @@
 
 proc ::pd_menus::build_window_menu {mymenu mytoplevel} {
 	variable accelerator
-	if {[tk windowingsystem] eq "aqua"} {
+	if {$::windowingsystem eq "aqua"} {
 		$mymenu add command -label [say "Minimize"] -command "menu_minimize ." \
 			-accelerator "$accelerator+M"
 		$mymenu add command -label [say "Zoom"] -command "menu_zoom ."
@@ -326,7 +326,7 @@
 }
 
 proc ::pd_menus::build_help_menu {mymenu mytoplevel} {
-	if {[tk windowingsystem] ne "aqua"} {
+	if {$::windowingsystem ne "aqua"} {
 		$mymenu add command -label {About Pd} \
 			-command "placeholder menu_doc_open doc/1.manual 1.introduction.txt" 
 	}

Modified: branches/pd-devel/0.41.4/src/pdtk_text.tcl
===================================================================
--- branches/pd-devel/0.41.4/src/pdtk_text.tcl	2009-01-13 18:14:05 UTC (rev 10538)
+++ branches/pd-devel/0.41.4/src/pdtk_text.tcl	2009-01-13 18:39:26 UTC (rev 10539)
@@ -13,7 +13,7 @@
 		-anchor nw -font "$::font_family $font_size $::font_weight"
 	$mycanvas bind $canvasitem <Home> "$mycanvas icursor $canvasitem 0"
 	$mycanvas bind $canvasitem <End> "$mycanvas icursor $canvasitem end"
-	if {[tk windowingsystem] eq "aqua"} { # emacs bindings for Mac OS X
+	if {$::windowingsystem eq "aqua"} { # emacs bindings for Mac OS X
 		$mycanvas bind $canvasitem <Control-a> "$mycanvas icursor $canvasitem 0"
 		$mycanvas bind $canvasitem <Control-e> "$mycanvas icursor $canvasitem end"
 	}

Modified: branches/pd-devel/0.41.4/src/wheredoesthisgo.tcl
===================================================================
--- branches/pd-devel/0.41.4/src/wheredoesthisgo.tcl	2009-01-13 18:14:05 UTC (rev 10538)
+++ branches/pd-devel/0.41.4/src/wheredoesthisgo.tcl	2009-01-13 18:39:26 UTC (rev 10539)
@@ -32,6 +32,20 @@
     }
 }
 
+
+#array set cmd_ops {}
+
+# the only arg for pd.tk is the port number to connect to 'pd' on, but this
+# code would be useful for opening files via drag-n-drop, the open panel, etc.
+#for {set i 0} {$i < $argc} {incr i} {
+#	global cmd_ops files_to_open
+#	set o [lindex $argv $i]
+#	switch -regexp -- $o {
+#		^-lang\$ {incr i; set cmd_ops(lang) [lindex $argv $i]}
+#		default {lappend files_to_open [lindex $argv $i]}
+#	}
+#}
+
 # ------------------------------------------------------------------------------
 # lost pdtk functions...
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Pd-cvs mailing list