TKE  3.6
Advanced code editor for programmers
themes Namespace Reference

Functions

 update_themes_dir
 
 load
 
 delete_theme name
 
 theme_okay
 
 get_file theme_name
 
 get_all_themes
 
 get_visible_themes
 
 handle_theme_change ?name1? ?name2? ?op?
 
 handle_colorize_change name1 name2 op
 
 handle_hidden_change name1 name2 op
 
 import parent_win fname
 
 export parent_win theme odir creator website license
 
 export_custom ?parent_win?
 
 populate_theme_menu mnu
 
 get_current_theme
 
 get_imported name
 
 get_attributions name
 
 get_user_directory
 
 get_share_items dir
 
 share_changed dir
 

Function Documentation

§ delete_theme()

themes::delete_theme   name  

Definition at line 95 of file themes.tcl.

95  proc delete_theme {name} {
96 
97  variable files
98 
99  # If the theme file exists, delete the file
100  if {[info exists files($name)] && [file exists $files($name)]} {
101  file delete -force $files($name)
102  }
103 
104  # Reload the theme information
105  load
106 
107  }

§ export()

themes::export   parent_win theme odir creator website license  

Definition at line 226 of file themes.tcl.

226  proc export {parent_win theme odir creator website license} {
227 
228  # Create the theme directory
229  file mkdir [set theme_dir [file join $odir $theme]]
230 
231  # Populate the theme directory with the given contents
232  if {![theme::export $theme $theme_dir $creator $website $license]} {
233  tk_messageBox -parent $parent_win -icon error -type ok -default ok \
234  -message "Unable to export theme contents"
235  return
236  }
237 
238  # Get the current working directory
239  set pwd [pwd]
240 
241  # Set the current working directory to the user themes directory
242  cd $theme_dir
243 
244  puts "theme: $theme, odir: $odir, odir contents: [glob *]"
245  puts [glob *]
246 
247  # Perform the archive
248  if {[catch { zipper::list2zip $theme [glob *] [file join .. $theme.tkethemz]} rc]} {
249  puts "list2zip, rc: $rc"
250  if {[catch { exec -ignorestderr zip -r [file join .. $theme.tkethemz] $theme} rc]} {
251  puts "zip, rc: $rc"
252  tk_messageBox -parent $parent_win -icon error -type ok -default ok \
253  -message "Unable to zip theme file"
254  return
255  }
256  }
257 
258  # Restore the current working directory
259  cd $pwd
260 
261  # Delete the theme directory and its contents
262  file delete {*}[glob -nocomplain -directory $theme_dir *]
263  file delete -force $theme_dir
264 
265  }

§ export_custom()

themes::export_custom   ?parent_win?  

Definition at line 269 of file themes.tcl.

269  proc export_custom {{parent_win .}} {
270 
271  variable files
272  variable themes_dir
273 
274  # Create the themes directory
275  set output_dir [file join ~ Desktop UpdatedThemes]
276  set current [theme::get_current_theme]
277 
278  # If the output directory exists, delete it
279  if {[file exists $output_dir]} {
280  file delete -force $output_dir
281  }
282 
283  # Make the output directory
284  file mkdir $output_dir
285 
286  # Load each theme and then export it
287  foreach {name theme_file} [array get files] {
288 
289  # Only consider themes from the themes_dir
290  if {[string compare -length [string length $themes_dir] $theme_file $themes_dir] != 0} {
291  continue
292  }
293 
294  # Initialize some variables
295  set license [file join [file dirname $theme_file] LICENSE]
296 
297  # Load the theme
298  theme::read_tketheme $theme_file
299 
300  # Export the theme to the output directory
301  array set attrs [list creator "" website "" date ""]
302  array set attrs [theme::get_attributions]
303 
304  # Export the loaded theme
305  export $parent_win $name $output_dir $attrs(creator) $attrs(website) $license
306 
307  }
308 
309  # Restore the theme namespace with the current theme contents
310  theme::load_theme $files($current)
311 
312  # Tell the user that the export was successful
313  gui::set_info_message [msgcat::mc "Batch custom theme export completed successfully"]
314 
315  }

§ get_all_themes()

themes::get_all_themes

Definition at line 134 of file themes.tcl.

134  proc get_all_themes {} {
135 
136  variable files
137 
138  return [lsort [array names files]]
139 
140  }

§ get_attributions()

themes::get_attributions   name  

Definition at line 369 of file themes.tcl.

369  proc get_attributions {name} {
370 
371  variable files
372 
373  array set attrs [list creator "" website "" date ""]
374 
375  if {[info exists files($name)]} {
376  array set attrs [theme::get_file_attributions $files($name)]
377  }
378 
379  return [array get attrs]
380 
381  }

§ get_current_theme()

themes::get_current_theme

Definition at line 344 of file themes.tcl.

344  proc get_current_theme {} {
345 
346  variable curr_theme
347 
348  return $curr_theme
349 
350  }

§ get_file()

themes::get_file   theme_name  

Definition at line 120 of file themes.tcl.

120  proc get_file {theme_name} {
121 
122  variable files
123 
124  if {[info exists files($theme_name)]} {
125  return $files($theme_name)
126  }
127 
128  return -code error "Filename for theme $theme_name does not exist"
129 
130  }

§ get_imported()

themes::get_imported   name  

Definition at line 354 of file themes.tcl.

354  proc get_imported {name} {
355 
356  variable files
357  variable themes_dir
358 
359  if {[info exists files($name)]} {
360  return [expr [string compare -length [string length $themes_dir] $themes_dir $files($name)] == 0]
361  }
362 
363  return 0
364 
365  }

§ get_share_items()

themes::get_share_items   dir  

Definition at line 395 of file themes.tcl.

395  proc get_share_items {dir} {
396 
397  return [list themes]
398 
399  }

§ get_user_directory()

themes::get_user_directory

Definition at line 385 of file themes.tcl.

385  proc get_user_directory {} {
386 
387  variable themes_dir
388 
389  return $themes_dir
390 
391  }

§ get_visible_themes()

themes::get_visible_themes

Definition at line 144 of file themes.tcl.

144  proc get_visible_themes {} {
145 
146  variable files
147 
148  # Create list of files to
149  return [lsort [::struct::set difference [array names files] [preferences::get Appearance/HiddenThemes]]]
150 
151  }

§ handle_colorize_change()

themes::handle_colorize_change   name1 name2 op  

Definition at line 171 of file themes.tcl.

171  proc handle_colorize_change {name1 name2 op} {
172 
174 
175  }

§ handle_hidden_change()

themes::handle_hidden_change   name1 name2 op  

Definition at line 179 of file themes.tcl.

179  proc handle_hidden_change {name1 name2 op} {
180 
181  # Reload the themes
182  load
183 
184  }

§ handle_theme_change()

themes::handle_theme_change   ?name1? ?name2? ?op?  

Definition at line 155 of file themes.tcl.

155  proc handle_theme_change {{name1 ""} {name2 ""} {op ""}} {
156 
157  variable files
158 
159  set user_theme [preferences::get Appearance/Theme]
160 
161  if {[info exists files($user_theme)]} {
162  theme::load_theme $files($user_theme)
163  } else {
164  theme::load_theme $files(Default)
165  }
166 
167  }

§ import()

themes::import   parent_win fname  

Definition at line 191 of file themes.tcl.

191  proc import {parent_win fname} {
192 
193  variable files
194  variable themes_dir
195 
196  # If the directory exists, move it out of the way
197  set odir [file join $themes_dir [file rootname [file tail $fname]]]
198  if {[file exists $odir]} {
199  file rename $odir $odir.old
200  }
201 
202  # Unzip the file contents
203  if {[catch { zipper::unzip $fname $themes_dir} rc]} {
204  if {[catch { exec -ignorestderr unzip -u $fname -d $themes_dir} rc]} {
205  catch { file rename $odir.old $odir}
206  tk_messageBox -parent $parent_win -icon error -type ok -default ok \
207  -message "Unable to unzip theme file" -detail $rc
208  return ""
209  }
210  }
211 
212  # Remove the old file if it exists
213  catch { file delete [file exists $odir.old]}
214 
215  # Reload the available themes
216  load
217 
218  # Return the pathname of the installed .tketheme file
219  return $files([file rootname [file tail $fname]])
220 
221  }

§ load()

themes::load

Definition at line 48 of file themes.tcl.

48  proc load {} {
49 
50  variable files
51  variable themes_dir
52 
53  # Update the user's themes directory
55 
56  # Trace changes to syntax preference values
57  if {[array size files] == 0} {
58  trace variable preferences::prefs(Appearance/Theme) w themes::handle_theme_change
59  trace variable preferences::prefs(Appearance/Colorize) w themes::handle_colorize_change
60  trace variable preferences::prefs(Appearance/HiddenThemes) w themes::handle_hidden_change
61  }
62 
63  # Reset the files/themes arrays and unregister launcher items
64  array unset files
65  launcher::unregister [msgcat::mc "Theme:*"]
66 
67  # Load the tke_dir theme files
68  set tfiles [utils::glob_install [file join $::tke_dir data themes] *.tketheme]
69 
70  # Load the theme files
71  foreach item [glob -nocomplain -directory $themes_dir -types d *] {
72  if {[file exists [file join $item [file tail $item].tketheme]]} {
73  lappend tfiles [file join $item [file tail $item].tketheme]
74  }
75  }
76 
77  # Get the theme information
78  foreach tfile $tfiles {
79  set name [file rootname [file tail $tfile]]
80  set files($name) $tfile
81  }
82 
83  # Create the launcher items (only display the visible themes)
84  foreach name [get_visible_themes] {
85  launcher::register [format "%s: %s" [msgcat::mc "Theme"] $name] [list theme::load_theme $files($name)] "" [list themes::theme_okay]
86  }
87 
88  # Allow the preferences UI to be updated, if it exists
90 
91  }

§ populate_theme_menu()

themes::populate_theme_menu   mnu  

Definition at line 319 of file themes.tcl.

319  proc populate_theme_menu {mnu} {
320 
321  variable files
322  variable curr_theme
323 
324  # Get the current theme
325  set curr_theme [theme::get_current_theme]
326 
327  # Figure out the state for the items
328  set state [expr {[themer::window_exists] ? "disabled" : "normal"}]
329 
330  # Clear the menu
331  $mnu delete 0 end
332 
333  # Populate the menu with the available themes
334  foreach name [get_visible_themes] {
335  $mnu add radiobutton -label $name -variable themes::curr_theme -value $name -command [list theme::load_theme $files($name)] -state $state
336  }
337 
338  return $mnu
339 
340  }

§ share_changed()

themes::share_changed   dir  

Definition at line 403 of file themes.tcl.

403  proc share_changed {dir} {
404 
405  variable themes_dir
406 
407  set themes_dir [file join $dir themes]
408 
409  }

§ theme_okay()

themes::theme_okay

Definition at line 111 of file themes.tcl.

111  proc theme_okay {} {
112 
113  return [expr [themer::window_exists] ^ 1]
114 
115  }

§ update_themes_dir()

themes::update_themes_dir

Definition at line 35 of file themes.tcl.

35  proc update_themes_dir {} {
36 
37  variable themes_dir
38 
39  foreach fname [glob -nocomplain -directory $themes_dir *.tketheme] {
40  file mkdir [file rootname $fname]
41  file rename $fname [file rootname $fname]
42  }
43 
44  }