Skip to content

Commit

Permalink
added filters on file dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
thanoulis committed Dec 1, 2020
1 parent 14f538f commit 0a75c80
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions tpmg
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,22 @@ example: tpmg --directory --title="Select a Directory" --exist
}
variable FileSelect {
options for Files Select dialog:
--title="string" set window title [default: "Select Files"]
--single single selection [no default]
--title="string" set window title [default: "Select Files"]
--ext="csv" set filetype filter [default: show all files]
--single single selection [no default]
--help this help

returns: file path on 'Open', 1 on 'Cancel', 255 on error
on multiple selection, returns list

example: tpmg --fileselect --title="Select a File" --single
example: tpmg --fileselect --title="Select a File" --ext="*.txt,*" --single
}
variable FileSave {
options for File Save dialog:
--title="string" set window title [default: "Save File"]
--ext="csv" set filetype filter [default: show all files]
--file="filepath" set initial file [no default]
--noconfirm do not confirm on overwrite [no default]
--noconfirm do not confirm on overwrite [default: confirm overwrite]
--help this help

returns: file path on 'Save', 1 on 'Cancel', 255 on error
Expand All @@ -98,10 +100,8 @@ options for Information dialog:
icon to use in dialog [default: "info"]
--button="one of: ok,okcancel,yesno,yesnocancel,retrycancel,abortretryignore"
buttons to use in dialog [default: "ok"]
"first non option string"
main message (bold)
"all" "other" "strings"
message details (every string in a new line)
"first string" main message (bold)
"other" "strings" message details (every string in a new line)
--help this help

returns: the button name (ok, cancel, yes, no, abort, retry, ignore)
Expand Down Expand Up @@ -147,7 +147,7 @@ options for Text dialog:
--title="string" set window title [default: "Show Text"]
--file="filepath" file to show [no default]
--edit can edit text [default: cannot edit]
--font="{font name} size bold/italic/underline/overstrike"
--font="{font name} size bold|italic|underline|overstrike"
font to use [default: "TkFixedFont"]
"other" "non option" "strings"
text body (every string in a new line)
Expand Down Expand Up @@ -283,13 +283,20 @@ proc tPMG::dialog::Directory {args} {
# FILE SELECT DIALOG
#
proc tPMG::dialog::FileSelect {args} {
set title "Select Files"
set single "true"
set title "Select Files"
set filetypes ""
set single "true"
foreach option {*}$args {
switch -glob -- $option {
--title=* {
set title [string range $option 8 end]
}
--ext=* {
set extlist [split [string range $option 6 end] ","]
foreach ext $extlist {
lappend filetypes [list [string toupper $ext] $ext]
}
}
--single {
set single "false"
}
Expand All @@ -305,8 +312,8 @@ proc tPMG::dialog::FileSelect {args} {
}
}
wm withdraw .
set response [file nativename [tk_getOpenFile \
-title $title -multiple $single]]
set response [file nativename [tk_getOpenFile -title $title \
-filetypes $filetypes -multiple $single]]
if {$response eq ""} {return $tPMG::Cancel}
return $response
}
Expand All @@ -315,14 +322,21 @@ proc tPMG::dialog::FileSelect {args} {
# FILE SAVE DIALOG
#
proc tPMG::dialog::FileSave {args} {
set title "Save File"
set confirm "true"
set file ""
set title "Save File"
set filetypes ""
set file ""
set confirm "true"
foreach option {*}$args {
switch -glob -- $option {
--title=* {
set title [string range $option 8 end]
}
--ext=* {
set extlist [split [string range $option 6 end] ","]
foreach ext $extlist {
lappend filetypes [list [string toupper $ext] $ext]
}
}
--file=* {
set file [file nativename [string range $option 7 end]]
}
Expand All @@ -341,8 +355,8 @@ proc tPMG::dialog::FileSave {args} {
}
}
wm withdraw .
set response [file nativename [tk_getSaveFile \
-title $title -confirmoverwrite $confirm -initialfile $file]]
set response [file nativename [tk_getSaveFile -title $title \
-filetypes $filetypes -confirmoverwrite $confirm -initialfile $file]]
if {$response eq ""} {return $tPMG::Cancel}
return $response
}
Expand Down

0 comments on commit 0a75c80

Please sign in to comment.