[PD-cvs] SF.net SVN: pure-data:[10460] branches/pd-devel/0.41.4/src/pd.tk
eighthave at users.sourceforge.net
eighthave at users.sourceforge.net
Thu Dec 25 01:06:09 CET 2008
Revision: 10460
http://pure-data.svn.sourceforge.net/pure-data/?rev=10460&view=rev
Author: eighthave
Date: 2008-12-25 00:06:06 +0000 (Thu, 25 Dec 2008)
Log Message:
-----------
- tried making one single menubar that is modified whenever the focus changes,
but I wonder if this makes sense since it might create more work to be done
on every focus shift
- finished File and Put menus
Modified Paths:
--------------
branches/pd-devel/0.41.4/src/pd.tk
Modified: branches/pd-devel/0.41.4/src/pd.tk
===================================================================
--- branches/pd-devel/0.41.4/src/pd.tk 2008-12-24 14:50:28 UTC (rev 10459)
+++ branches/pd-devel/0.41.4/src/pd.tk 2008-12-25 00:06:06 UTC (rev 10460)
@@ -6,89 +6,271 @@
## replace Tk widgets with Ttk widgets on 8.5
#namespace import -force ttk::*
+
+# TODO switch back to creating a menubar for each window
+# TODO figure out Edit Mode Checkbox menu item on Aqua
+# TODO figure out Undo/Redo/Cut/Copy/Paste state changes for menus
+# TODO figure out parent window/window list for Window menu
+
# ------------------------------------------------------------------------------
-# init functions
+# global variables
-proc init_x11 {} {
+# for displaying on menus
+set accelerator "Ctrl"
+# for key bindings
+set modifier "Control"
+
+# ------------------------------------------------------------------------------
+# PLACEHOLDERS
+
+proc pd {} {
}
-proc init_aqua {} {
+proc menu_doc_open {docdir doc} {
+# PLACEHOLDER
}
-proc init_win32 {} {
- font create menufont -family Tahoma -size -11
+proc menu_helpbrowser {dir} {
+# PLACEHOLDER
}
+proc menu_new {} {
+# PLACEHOLDER
+ pdtk_canvas_new [format .flarg%d [expr round(rand()*1000)]] 30 10
+}
+
+proc menu_quit {} {
+# PLACEHOLDER
+ exit
+}
+
+
+# ------------------------------------------------------------------------------
+# init functions
+
proc init {} {
- if { [tk windowingsystem] eq "x11" } {
- } elseif { [tk windowingsystem] eq "aqua" } {
- } elseif { [tk windowingsystem] eq "win32" } {
+ switch -- [tk windowingsystem] {
+ "x11" {
+ }
+ "aqua" {
+ global accelerator modifier
+ set accelerator "Meta"
+ set modifier "Mod1"
+ }
+ "win32" {
+ font create menufont -family Tahoma -size -11
+ }
}
}
# ------------------------------------------------------------------------------
# Mac OS X specific functions
+proc menu_bringalltofront {} {
+ #use [winfo children .] here to get windows that are minimized
+ foreach item [winfo children .] {
+ #get all toplevel windows, exclude menubar windows
+ if { [string equal [winfo toplevel $item] $item] && [catch {$item cget -tearoff}]} {
+ wm deiconify $item
+ }
+ }
+ #be sure to deiconify ., since the above command only gets the child toplevels
+ wm deiconify .
+}
+
+
# ------------------------------------------------------------------------------
# functions called from menu items
-proc accel_munge {thingy} {
+
+proc menu_minimize {} {
+ set windowlist [wm stackorder .]
+ if {$windowlist != {}} {
+ set topwindow [lindex $windowlist end]
+ wm iconify $topwindow
+ }
}
-proc menu_doc_open {docdir doc} {
+proc menu_maximize {window} {
+ wm state $window zoomed
}
-proc menu_doc_browser {dir} {
+# ------------------------------------------------------------------------------
+# menu building functions for Mac OS X/aqua
+
+proc menu_create_file_aqua {rootmenu} {
+ global accelerator
+ $rootmenu add command -label "New" -accelerator "$accelerator+N"
+ $rootmenu add command -label "Open" -accelerator "$accelerator+O"
+ $rootmenu add cascade -label "Open Recent"
+ $rootmenu add separator
+ $rootmenu add command -label "Close" -accelerator "$accelerator+W"
+ $rootmenu add command -label "Save" -accelerator "$accelerator+S"
+ $rootmenu add command -label "Save As..." -accelerator "$accelerator+Shift+S"
+# $rootmenu add command -label "Save All"
+ $rootmenu add command -label "Revert to Saved"
+ $rootmenu add separator
+ $rootmenu add command -label "Message"
+ $rootmenu add separator
+ $rootmenu add command -label "Print..." -accelerator "$accelerator+P"
}
+proc menu_create_edit_aqua {rootmenu} {
+}
+
+# the "Put" and "Find" menus do not have cross-platform differences
+
+proc menu_create_media_aqua {rootmenu} {
+}
+
+proc menu_create_window_aqua {rootmenu} {
+}
+
+proc menu_create_help_aqua {rootmenu} {
+}
+
# ------------------------------------------------------------------------------
-# menu building functions
-proc menu_create_file {rootmenu} {
-# $rootmenu add command -label New -command {menu_new}
- $rootmenu add command -label New -command {pdtk_canvas_new .flarg 30 10} \
- -accelerator [accel_munge "Ctrl+n"]
- $rootmenu add command -label Open -command {menu_open} \
- -accelerator [accel_munge "Ctrl+o"]
+# menu building functions for UNIX/X11
+
+proc menu_create_file_x11 {rootmenu} {
+ global accelerator
+ $rootmenu add command -label "New" -accelerator "$accelerator+N"
+ $rootmenu add command -label "Open" -accelerator "$accelerator+O"
$rootmenu add separator
- $rootmenu add command -label Message -command {menu_send} \
- -accelerator [accel_munge "Ctrl+m"]
- # On MacOS X, these are in the standard HIG locations
- # i.e. the Preferences menu under "Pd"
- if {[tk windowingsystem] ne "aqua"} {
- $rootmenu add command -label Path... \
- -command {pd pd start-path-dialog \;}
- $rootmenu add command -label Startup... \
- -command {pd pd start-startup-dialog \;}
- }
+ $rootmenu add command -label "Save" -accelerator "$accelerator+S"
+ $rootmenu add command -label "Save As..." -accelerator "Shift+$accelerator+S"
+ $rootmenu add command -label "Revert"
$rootmenu add separator
- $rootmenu add command -label Quit -command {menu_quit} \
- -accelerator [accel_munge "Ctrl+q"]
+ $rootmenu add command -label "Message" -accelerator "$accelerator+M"
+ $rootmenu add command -label "Print..." -accelerator "$accelerator+P"
+ $rootmenu add separator
+ $rootmenu add command -label "Close" -accelerator "$accelerator+W"
+ $rootmenu add command -label "Quit" -command {menu_quit} \
+ -accelerator "$accelerator+Q"
}
-proc menu_create_edit {rootmenu} {
+proc menu_create_edit_x11 {rootmenu} {
}
-proc menu_create_put {rootmenu} {
+# the "Put" and "Find" menus do not have cross-platform differences
+
+proc menu_create_media_x11 {rootmenu} {
}
-proc menu_create_media {rootmenu} {
+proc menu_create_window_x11 {rootmenu} {
}
-proc menu_create_window {rootmenu} {
+proc menu_create_help_x11 {rootmenu} {
}
-proc menu_create_help {rootmenu} {
+# ------------------------------------------------------------------------------
+# menu building functions for Windows/Win32
+
+proc menu_create_file_win32 {rootmenu} {
+ global accelerator
+ $rootmenu add command -label "New" -accelerator "$accelerator+N"
+ $rootmenu add command -label "Open" -accelerator "$accelerator+O"
+ $rootmenu add separator
+ $rootmenu add command -label "Save" -accelerator "$accelerator+S"
+ $rootmenu add command -label "Save As..." -accelerator "Shift+$accelerator+S"
+ $rootmenu add command -label "Revert"
+ $rootmenu add separator
+ $rootmenu add command -label "Message" -accelerator "$accelerator+M"
+ $rootmenu add command -label "Print..." -accelerator "$accelerator+P"
+ $rootmenu add separator
+ $rootmenu add command -label "Close" -accelerator "$accelerator+W"
+ $rootmenu add command -label "Quit" -command {menu_quit} \
+ -accelerator "$accelerator+Q"
+}
+
+proc menu_create_edit_win32 {rootmenu} {
+}
+
+# the "Put" and "Find" menus do not have cross-platform differences
+
+proc menu_create_media_win32 {rootmenu} {
+}
+
+proc menu_create_window_win32 {rootmenu} {
+}
+
+proc menu_create_help_win32 {rootmenu} {
+}
+
+
+# ------------------------------------------------------------------------------
+# menu building functions
+proc menu_create_file {rootmenu name} {
+ [format menu_create_file_%s [tk windowingsystem]] $rootmenu
+ $rootmenu entryconfigure "New" -command {menu_new}
+ $rootmenu entryconfigure "Open" -command {menu_open}
+ $rootmenu entryconfigure "Save" -command {menu_save $name}
+ $rootmenu entryconfigure "Save As..." -command {menu_saveas $name}
+ $rootmenu entryconfigure "Revert*" -command {menu_revert $name}
+ $rootmenu entryconfigure "Close" -command {menu_close $name}
+ $rootmenu entryconfigure "Message" -command {menu_send}
+ $rootmenu entryconfigure "Print..." -command {menu_print $name}
+}
+
+proc menu_create_edit {rootmenu name} {
+# [format menu_create_edit_%s [tk windowingsystem]] $rootmenu
+# $rootmenu entryconfigure "New" -command {menu_new}
+}
+
+proc menu_create_put {rootmenu name} {
+ global accelerator
+ $rootmenu add command -label "Object" -accelerator "$accelerator+1" \
+ -command {menu_object $name 0}
+ $rootmenu add command -label "Message" -accelerator "$accelerator+2" \
+ -command {menu_message $name 0}
+ $rootmenu add command -label "Number" -accelerator "$accelerator+3" \
+ -command {menu_floatatom $name 0}
+ $rootmenu add command -label "Symbol" -accelerator "$accelerator+4" \
+ -command {menu_symbolatom $name 0}
+ $rootmenu add command -label "Comment" -accelerator "$accelerator+5" \
+ -command {menu_comment $name 0}
+ $rootmenu add separator
+ $rootmenu add command -label "Bang" -accelerator "Shift+$accelerator+B" \
+ -command {menu_bng $name 0}
+ $rootmenu add command -label "Toggle" -accelerator "Shift+$accelerator+T" \
+ -command {menu_toggle $name 0}
+ $rootmenu add command -label "Number2" -accelerator "Shift+$accelerator+N" \
+ -command {menu_numbox $name 0}
+ $rootmenu add command -label "Vslider" -accelerator "Shift+$accelerator+V" \
+ -command {menu_vslider $name 0}
+ $rootmenu add command -label "Hslider" -accelerator "Shift+$accelerator+H" \
+ -command {menu_hslider $name 0}
+ $rootmenu add command -label "Vradio" -accelerator "Shift+$accelerator+D" \
+ -command {menu_vradio $name 0}
+ $rootmenu add command -label "Hradio" -accelerator "Shift+$accelerator+I" \
+ -command {menu_hradio $name 0}
+ $rootmenu add command -label "VU" -accelerator "Shift+$accelerator+U" \
+ -command {menu_vumeter $name 0}
+ $rootmenu add command -label "Canvas" -accelerator "Shift+$accelerator+C"\
+ -command {menu_mycnv $name 0}
+ $rootmenu add separator
+ $rootmenu add command -label Graph -command {menu_graph $name}
+ $rootmenu add command -label Array -command {menu_array $name}
+}
+
+proc menu_create_media {rootmenu name} {
+}
+
+proc menu_create_window {rootmenu name} {
+}
+
+proc menu_create_help {rootmenu name} {
if {[tk windowingsystem] ne "aqua"} {
$rootmenu add command -label {About Pd} \
-command {menu_doc_open doc/1.manual 1.introduction.txt}
}
- $rootmenu add command -label {Html ...} \
+ $rootmenu add command -label {HTML ...} \
-command {menu_doc_open doc/1.manual index.htm}
$rootmenu add command -label {Browser ...} \
- -command {menu_doc_browser $help_top_directory}
+ -command {menu_helpbrowser $help_top_directory}
}
-proc menu_create_apple {rootmenu} {
+proc menu_create_apple {rootmenu name} {
$rootmenu add command -label "About Pd..." -command \
{menu_doc_open doc/1.manual 1.introduction.txt}
menu $rootmenu.preferences -tearoff 0
@@ -112,35 +294,66 @@
menu $rootmenu.$menuitem -tearoff 0
$rootmenu add cascade -label [string totitle $menuitem] \
-menu $rootmenu.$menuitem
- [concat menu_create_$menuitem] $rootmenu.$menuitem
+ [format menu_create_%s $menuitem] $rootmenu.$menuitem PLACEHOLDER
if {[tk windowingsystem] eq "win32"} {
+ # fix menu font size on Windows with tk scaling = 1
$rootmenu.$menuitem configure -font menufont
}
}
}
+proc menu_entryconfigure {menuname itemname} {
+ set itemindex [$menuname ]
+ $menuname entryconfigure
+}
+proc menu_configure {menubar window} {
+ puts "menu_configure $window"
+ set file_items_to_disable {"Save" "Save As..." "Revert" "Print..." "Close"}
+ if {$window eq "."} {
+ # these are meaningless for the Pd window, so disable them
+ foreach item $file_items_to_disable {
+ $menubar.file entryconfigure $item -state disabled
+ }
+ for {set i 0} {$i <= [$menubar.put index end]} {incr i} {
+ # catch errors by trying to disable separators
+ catch {$menubar.put entryconfigure $i -state disabled }
+ }
+ } else {
+ foreach item $file_items_to_disable {
+ $menubar.file entryconfigure $item -state normal
+ }
+ for {set i 0} {$i <= [$menubar.put index end]} {incr i} {
+ # catch errors by trying to disable separators
+ catch {$menubar.put entryconfigure $i -state normal }
+ }
+ # TODO re-enable menu items
+ # TODO configure "parent on Window menu
+ }
+}
+
# ------------------------------------------------------------------------------
# canvas support functions
proc pdtk_canvas_new {canvas_name width height} {
- if {$width < 200} {set width 200}
- if {$height < 50} {set height 50}
- toplevel $canvas_name -menu $canvas_name.menubar -width $width -height $height
- menu $canvas_name.menubar -tearoff 0
- menu_create $canvas_name.menubar
+ if {$width < 300} {set width 300}
+ if {$height < 150} {set height 150}
+ toplevel $canvas_name -menu .menubar -width $width -height $height
+ bind $canvas_name <FocusIn> {menu_configure .menubar %W}
}
# ------------------------------------------------------------------------------
# main
proc main {} {
+ init
-menu .menubar
-menu_create .menubar
-
-wm title . "Pd-devel"
-#wm protocol . WM_DELETE_WINDOW menu_quit
-. configure -menu .menubar -width 400 -height 250
-
+ menu .menubar
+ menu_create .menubar
+
+ wm title . "Pd-devel"
+ #wm protocol . WM_DELETE_WINDOW menu_quit
+ . configure -menu .menubar -width 400 -height 250
+ menu_configure .menubar .
+ bind . <FocusIn> {menu_configure .menubar %W}
}
main
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