1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
package provide dialog_startup 0.1
package require scrollboxwindow
package require msgcat
package require pd_guiprefs
namespace eval dialog_startup {
namespace export pdtk_startup_dialog
}
set ::dialog_startup::language ""
set ::dialog_startup::precision_binary ""
########## pdtk_startup_dialog -- dialog window for startup options #########
# Create a simple modal window with an entry widget
# for editing/adding a startup command
# (the next-best-thing to in-place editing)
proc ::dialog_startup::chooseCommand { prompt initialValue } {
global cmd
set cmd $initialValue
toplevel .inputbox -class DialogWindow
wm title .inputbox $prompt
wm group .inputbox .
wm minsize .inputbox 450 30
wm resizable .inputbox 0 0
wm geom .inputbox "450x30"
button .inputbox.button -text [_ "OK"] -command { destroy .inputbox } \
-width [::msgcat::mcmax [_ "OK"]]
entry .inputbox.entry -width 50 -textvariable cmd
pack .inputbox.button -side right
bind .inputbox.entry <KeyPress-Return> { destroy .inputbox }
bind .inputbox.entry <KeyPress-Escape> { destroy .inputbox }
pack .inputbox.entry -side right -expand 1 -fill x -padx 2m
raise .inputbox
focus .inputbox.entry
wm transient .inputbox
grab .inputbox
tkwait window .inputbox
return $cmd
}
proc ::dialog_startup::cancel {mytoplevel} {
::scrollboxwindow::cancel $mytoplevel
}
proc ::dialog_startup::ok {mytoplevel} {
::scrollboxwindow::ok $mytoplevel dialog_startup::commit
}
proc ::dialog_startup::add {} {
return [chooseCommand [_ "Add new library"] ""]
}
proc ::dialog_startup::edit { current_library } {
return [chooseCommand [_ "Edit library"] $current_library]
}
proc ::dialog_startup::commit { new_startup } {
# i18n
if {$::dialog_startup::language eq "default" } {
set ::dialog_startup::language ""
}
set ::pd_i18n::language $::dialog_startup::language
::pd_guiprefs::write "gui_language" $::dialog_startup::language
if {$::platform eq "Darwin"} {
# on macOS, we also want to write the per-application language to the system settings
set key AppleLanguages
catch {
if {$::pd_i18n::language eq "" || $::pd_i18n::language eq "."} {
exec defaults delete $::pd_guiprefs::domain $key
} else {
exec defaults write $::pd_guiprefs::domain $key -array $::pd_i18n::language
}
}
}
# Pd32 vs Pd64
if { $::dialog_startup::precision_binary != "" } {
::pd_guiprefs::write "pdcore_precision_binary" $::dialog_startup::precision_binary
}
# libraries
set ::startup_libraries $new_startup
pdsend "pd startup-dialog $::sys_defeatrt [pdtk_encodedialog $::sys_flags] [pdtk_encode $::startup_libraries]"
}
# set up the panel with the info from pd
proc ::dialog_startup::pdtk_startup_dialog {mytoplevel defeatrt flags} {
set ::sys_defeatrt $defeatrt
if {$flags ne ""} {variable ::sys_flags [subst -nocommands $flags]}
if {[winfo exists $mytoplevel]} {
wm deiconify $mytoplevel
raise $mytoplevel
focus $mytoplevel
} else {
create_dialog $mytoplevel
}
}
proc ::dialog_startup::fill_frame {frame} {
# 'frame' is a frame, rather than a toplevel window
label $frame.restart_required -text [_ "Settings below require a restart of Pd!" ]
pack $frame.restart_required -side top -fill x
# scrollbox
::scrollbox::make ${frame} $::startup_libraries \
{} {} \
[_ "Pd libraries to load on startup"]
## GUI options
labelframe $frame.guiframe -text [_ "GUI Options" ]
set f $frame.guiframe
pack $f -side top -anchor s -fill x -padx 2m -pady 5
# language selection
frame $f.langframe
set w $f.langframe.language
menubutton $w -indicatoron 1 -menu $w.menu \
-text [_ "language" ] \
-relief raised -highlightthickness 1 -anchor c \
-direction flush
menu $w.menu -tearoff 0
set ::dialog_startup::language [::pd_guiprefs::read "gui_language" ]
if { $::dialog_startup::language eq "" } {
set ::dialog_startup::language default
}
foreach lang [::pd_i18n::get_available_languages] {
foreach {langname langcode} $lang {
$w.menu add radiobutton \
-label ${langname} -command "$w configure -text \"${langname}\"" \
-value ${langcode} -variable ::dialog_startup::language
if { ${langcode} == $::dialog_startup::language } {
$w configure -text "${langname}"
}
}
}
pack $w -side right
set w $f.langframe.langlabel
label $w -text [_ "Menu language" ]
pack $w -side left
pack $f.langframe -side top -anchor w -expand 1
# precision selection
set basedir [file normalize [file join [file dirname ${::pdgui::scriptname}] ..]]
set pdexecs {}
foreach {bindir exe} {
bin32 pd32
bin32 pd
bin pd32
bin pd} {
foreach ext {{} .exe .com} {
set x [file join $basedir $bindir ${exe}${ext}]
if {[file executable $x]} {
lappend pdexecs [list [_ "float (32bit)"] 32]
break
}
}
}
foreach {bindir exe} {
bin64 pd64
bin64 pd
bin pd64} {
foreach ext {{} .exe .com} {
set x [file join $basedir $bindir ${exe}${ext}]
if {[file executable $x]} {
lappend pdexecs [list [_ "double (64bit) EXPERIMENTAL"] 64]
# the next line is just for the translations
set x [_ "double (64bit)" ]
break
}
}
}
set precbin [::pd_guiprefs::read "pdcore_precision_binary" ]
if {[info exists ::deken::platform(floatsize)]} {
switch -- ${::deken::platform(floatsize)} {
64 {
set precbin 64
}
32 {
set precbin 32
}
}
}
if { [llength $pdexecs] > 1 } {
if { $precbin == "" } {
set precbin [lindex [lindex $pdexecs 0] 1]
}
frame $f.floatsize
set w $f.floatsize.floatsize
menubutton $w -indicatoron 1 -menu $w.menu \
-text [_ "float size" ] \
-relief raised -highlightthickness 1 -anchor c \
-direction flush
set var ::dialog_startup::precision_binary
if { $::host ne "" } {
$w configure -state disabled
set var ::dialog_startup::precision_binary_dummy
set ::dialog_startup::precision_binary_dummy ${::dialog_startup::precision_binary}
}
set $var $precbin
menu $w.menu -tearoff 0
foreach pdx $pdexecs {
foreach {precision bin} ${pdx} {break}
$w.menu add radiobutton \
-label ${precision} -command "$w configure -text \"${precision}\"" \
-value ${bin} -variable ${var}
if { ${bin} == $precbin } {
$w configure -text "${precision}"
}
}
pack $w -side right
if { $::host ne "" } {
$w configure -state disabled
}
set w $f.floatsize.label
label $w -text [_ "Numeric precision of Pd-core" ]
pack $w -side left
pack $f.floatsize -side top -anchor w -expand 1
}
# Startup options and flags
labelframe $frame.optionframe -text [_ "Startup Options" ]
pack $frame.optionframe -side top -anchor s -fill x -padx 2m -pady 5
checkbutton $frame.optionframe.verbose -anchor w \
-text [_ "Verbose"] \
-variable ::sys_verbose
pack $frame.optionframe.verbose -side top -anchor w -expand 1
if {$::windowingsystem ne "win32"} {
checkbutton $frame.optionframe.defeatrt -anchor w \
-text [_ "Defeat real-time scheduling"] \
-variable ::sys_defeatrt
pack $frame.optionframe.defeatrt -side top -anchor w -expand 1
}
labelframe $frame.flags -text [_ "Startup Flags:" ]
pack $frame.flags -side top -anchor s -fill x -padx 2m
entry $frame.flags.entry -textvariable ::sys_flags
pack $frame.flags.entry -side right -expand 1 -fill x
::preferencewindow::entryfocus $frame.flags.entry
::preferencewindow::simplefocus $frame.listbox.box
}
proc ::dialog_startup::create_dialog {mytoplevel} {
::preferencewindow::create ${mytoplevel} [_ "Pd libraries to load on startup"] {450 300}
wm withdraw $mytoplevel
wm resizable $mytoplevel 0 0
set my [::preferencewindow::add_frame ${mytoplevel} [_ "startup preferences" ]]
# add widgets
fill_frame $my
::preferencewindow::entryfocus $my.flags.entry $mytoplevel.nb.buttonframe.ok "::dialog_startup::ok $mytoplevel" "::dialog_startup::cancel $mytoplevel"
::preferencewindow::simplefocus $my.listbox.box $mytoplevel.nb.buttonframe.ok "::dialog_path::ok $mytoplevel" "::dialog_path::cancel $mytoplevel"
pack $my -side top -fill x -expand 1
# add actions
::preferencewindow::add_cancel ${mytoplevel} "::scrollboxwindow::cancel ${mytoplevel}"
::preferencewindow::add_apply ${mytoplevel} "::scrollboxwindow::apply ${my} ::dialog_startup::commit"
::pd_bindings::dialog_bindings $mytoplevel "startup"
# set min size based on widget sizing
update
wm minsize $mytoplevel [winfo width $mytoplevel] [winfo reqheight $mytoplevel]
position_over_window $mytoplevel .pdwindow
raise $mytoplevel
}
# for focus handling on OSX
proc ::dialog_startup::rebind_return {mytoplevel} {
bind $mytoplevel <KeyPress-Escape> "::dialog_startup::cancel $mytoplevel"
bind $mytoplevel <KeyPress-Return> "::dialog_startup::ok $mytoplevel"
focus $mytoplevel.nb.buttonframe.ok
return 0
}
# for focus handling on OSX
proc ::dialog_startup::unbind_return {mytoplevel} {
bind $mytoplevel <KeyPress-Escape> break
bind $mytoplevel <KeyPress-Return> break
return 1
}
# procs for setting variables from the Pd-core
proc ::dialog_startup::set_flags {flags} {
set ::sys_flags [subst -nocommands -novariables ${flags}]
}
proc ::dialog_startup::set_libraries {libraries} {
set ::startup_libraries $libraries
}
|