]> Dogcows Code - chaz/tint2/blob - src/tint2conf/tintwizard.py
added customised tintwizard
[chaz/tint2] / src / tint2conf / tintwizard.py
1 #!/usr/bin/env python
2
3 #**************************************************************************
4 # Tintwizard
5 #
6 # Copyright (C) 2009 Euan Freeman <euan04@gmail.com>
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License version 3
10 # as published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #*************************************************************************/
20 # Last modified: 27th September 2009
21
22 import pygtk
23 pygtk.require('2.0')
24 import gtk
25 import os
26 import sys
27 import signal
28 import webbrowser
29 import math
30 import shutil
31
32 # Project information
33 NAME = "tintwizard"
34 AUTHORS = ["Euan Freeman <euan04@gmail.com>"]
35 VERSION = "0.2.9"
36 COMMENTS = "tintwizard generates config files for the lightweight panel replacement tint2"
37 WEBSITE = "http://code.google.com/p/tintwizard/"
38
39 # Default values for text entry fields
40 BG_ROUNDING = "0"
41 BG_BORDER = "0"
42 PANEL_SIZE_X = "0"
43 PANEL_SIZE_Y = "40"
44 PANEL_MARGIN_X = "0"
45 PANEL_MARGIN_Y = "0"
46 PANEL_PADDING_X = "0"
47 PANEL_PADDING_Y = "0"
48 PANEL_MONITOR = "all"
49 TASKBAR_PADDING_X = "0"
50 TASKBAR_PADDING_Y = "0"
51 TASK_BLINKS = "7"
52 TASK_MAXIMUM_SIZE_X = "200"
53 TASK_MAXIMUM_SIZE_Y = "32"
54 TASK_PADDING_X = "0"
55 TASK_PADDING_Y = "0"
56 TASK_SPACING = "0"
57 TRAY_PADDING_X = "0"
58 TRAY_PADDING_Y = "0"
59 TRAY_SPACING = "0"
60 ICON_ALPHA = "0"
61 ICON_SAT = "0"
62 ICON_BRI = "0"
63 ACTIVE_ICON_ALPHA = "0"
64 ACTIVE_ICON_SAT = "0"
65 ACTIVE_ICON_BRI = "0"
66 CLOCK_FMT_1 = "%H:%M"
67 CLOCK_FMT_2 = "%a %d %b"
68 CLOCK_PADDING_X = "0"
69 CLOCK_PADDING_Y = "0"
70 CLOCK_LCLICK = ""
71 CLOCK_RCLICK = ""
72 TOOLTIP_PADDING_X = "0"
73 TOOLTIP_PADDING_Y = "0"
74 TOOLTIP_SHOW_TIMEOUT = "0"
75 TOOLTIP_HIDE_TIMEOUT = "0"
76 BATTERY_LOW = "20"
77 BATTERY_ACTION = 'notify-send "battery low"'
78 BATTERY_PADDING_X = "0"
79 BATTERY_PADDING_Y = "0"
80
81 class TintWizardPrefGUI(gtk.Window):
82 """The dialog window which lets the user change the default preferences."""
83 def __init__(self, tw):
84 """Create and shows the window."""
85 self.tw = tw
86
87 # Create top-level window
88 gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
89
90 self.set_title("Preferences")
91 self.connect("delete_event", self.quit)
92
93 self.layout = gtk.Table(2, 2, False)
94
95 self.table = gtk.Table(5, 2, False)
96 self.table.set_row_spacings(5)
97 self.table.set_col_spacings(5)
98
99 temp = gtk.Label("Default Font")
100 temp.set_alignment(0, 0.5)
101 self.table.attach(temp, 0, 1, 0, 1)
102 self.font = gtk.FontButton(self.tw.defaults["font"])
103 self.font.set_alignment(0, 0.5)
104 self.table.attach(self.font, 1, 2, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
105
106 temp = gtk.Label("Default Background Color")
107 temp.set_alignment(0, 0.5)
108 self.table.attach(temp, 0, 1, 1, 2)
109 self.bgColor = gtk.ColorButton(gtk.gdk.color_parse(self.tw.defaults["bgColor"]))
110 self.bgColor.set_alignment(0, 0.5)
111 self.table.attach(self.bgColor, 1, 2, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
112
113 temp = gtk.Label("Default Foreground Color")
114 temp.set_alignment(0, 0.5)
115 self.table.attach(temp, 0, 1, 2, 3)
116 self.fgColor = gtk.ColorButton(gtk.gdk.color_parse(self.tw.defaults["fgColor"]))
117 self.fgColor.set_alignment(0, 0.5)
118 self.table.attach(self.fgColor, 1, 2, 2, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
119
120 temp = gtk.Label("Default Border Color")
121 temp.set_alignment(0, 0.5)
122 self.table.attach(temp, 0, 1, 3, 4)
123 self.borderColor = gtk.ColorButton(gtk.gdk.color_parse(self.tw.defaults["borderColor"]))
124 self.borderColor.set_alignment(0, 0.5)
125 self.table.attach(self.borderColor, 1, 2, 3, 4, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
126
127 temp = gtk.Label("Number of Background Styles")
128 temp.set_alignment(0, 0.5)
129 self.table.attach(temp, 0, 1, 4, 5)
130 self.bgCount = gtk.Entry(6)
131 self.bgCount.set_width_chars(8)
132 self.bgCount.set_text(str(self.tw.defaults["bgCount"]))
133 self.table.attach(self.bgCount, 1, 2, 4, 5, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
134
135 temp = gtk.Label("Default directory")
136 temp.set_alignment(0, 0.5)
137 self.table.attach(temp, 0, 1, 5, 6)
138 self.dir = gtk.Button(self.tw.defaults["dir"])
139 self.dir.connect("clicked", self.chooseFolder)
140 self.table.attach(self.dir, 1, 2, 5, 6, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
141
142 self.layout.attach(self.table, 0, 2, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, xpadding=20, ypadding=5)
143
144 temp = gtk.Button("Save", gtk.STOCK_SAVE)
145 temp.set_name("save")
146 temp.connect("clicked", self.save)
147 self.layout.attach(temp, 0, 1, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, ypadding=20)
148 temp = gtk.Button("Cancel", gtk.STOCK_CANCEL)
149 temp.set_name("cancel")
150 temp.connect("clicked", self.quit)
151 self.layout.attach(temp, 1, 2, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, ypadding=20)
152
153 self.add(self.layout)
154
155 self.show_all()
156
157 def chooseFolder(self, widget=None, direction=None):
158 """Called every time the folder button is clicked. Shows a file chooser."""
159 chooser = gtk.FileChooserDialog("Choose Default Folder", self, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
160 chooser.set_default_response(gtk.RESPONSE_OK)
161
162 if self.tw.curDir != None:
163 chooser.set_current_folder(self.tw.curDir)
164
165 chooser.show()
166
167 response = chooser.run()
168
169 if response == gtk.RESPONSE_OK:
170 self.dir.set_label(chooser.get_filename())
171 else:
172 chooser.destroy()
173 return
174
175 chooser.destroy()
176
177 def quit(self, widget=None, event=None):
178 """Destroys the window."""
179 self.destroy()
180
181 def save(self, action=None):
182 """Called when the Save button is clicked."""
183 if confirmDialog(self, "Overwrite configuration file?") == gtk.RESPONSE_YES:
184 self.tw.defaults["font"] = self.font.get_font_name()
185 self.tw.defaults["bgColor"] = rgbToHex(self.bgColor.get_color().red, self.bgColor.get_color().green, self.bgColor.get_color().blue)
186 self.tw.defaults["fgColor"] = rgbToHex(self.fgColor.get_color().red, self.fgColor.get_color().green, self.fgColor.get_color().blue)
187 self.tw.defaults["borderColor"] = rgbToHex(self.borderColor.get_color().red, self.borderColor.get_color().green, self.borderColor.get_color().blue)
188
189 try:
190 self.tw.defaults["bgCount"] = int(self.bgCount.get_text())
191 except:
192 errorDialog(self, "Invalid value for background count")
193 return
194
195 self.tw.defaults["dir"] = self.dir.get_label()
196 self.curDir = self.tw.defaults["dir"]
197
198 self.tw.writeConf()
199
200 self.quit()
201
202 class TintWizardGUI(gtk.Window):
203 """The main window for the application."""
204 def __init__(self):
205 """Create and show the window."""
206 self.filename = None
207 self.curDir = None
208 self.toSave = False
209
210 if len(sys.argv) > 1:
211 self.filename = sys.argv[1]
212 self.oneConfigFile = True
213 else:
214 self.oneConfigFile = False
215
216 # Read conf file and set default values
217 self.readConf()
218
219 if self.defaults["bgColor"] in [None, "None"]:
220 self.defaults["bgColor"] = "#000000"
221
222 if self.defaults["fgColor"] in [None, "None"]:
223 self.defaults["fgColor"] = "#ffffff"
224
225 if self.defaults["borderColor"] in [None, "None"]:
226 self.defaults["borderColor"] = "#ffffff"
227
228 if self.defaults["dir"] in [None, "None"]:
229 if os.path.exists(os.path.expandvars("${HOME}") + "/.config/tint2"):
230 self.curDir = os.path.expandvars("${HOME}") + "/.config/tint2"
231 else:
232 self.curDir = None
233 else:
234 self.curDir = os.path.expandvars(self.defaults["dir"])
235
236 if not os.path.exists(os.path.expandvars(self.curDir)):
237 if os.path.exists(os.path.expandvars("${HOME}") + "/.config/tint2"):
238 self.curDir = os.path.expandvars("${HOME}") + "/.config/tint2"
239 else:
240 self.curDir = None
241
242 try:
243 self.defaults["bgCount"] = int(self.defaults["bgCount"])
244 except:
245 self.defaults["bgCount"] = 2
246
247 # Get the full location of the tint2 binary
248 which = os.popen('which tint2')
249
250 self.tint2Bin = which.readline().strip()
251
252 which.close()
253
254 if len(self.tint2Bin) == 0:
255 errorDialog(self, "tint2 could not be found. Are you sure it is installed?")
256 sys.exit(1)
257
258 # Create top-level window
259 gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
260
261 self.set_title("tintwizard")
262
263 self.connect("delete_event", self.quit)
264
265 # self.table is our main layout manager
266 self.table = gtk.Table(4, 1, False)
267
268 # Create menus and toolbar items
269 ui = """
270 <ui>
271 <menubar name="MenuBar">
272 <menu action="File">
273 <menuitem action="New" />
274 <menuitem action="Open" />
275 <separator />
276 <menuitem action="Save" />
277 <menuitem action="Save As..." />
278 <separator />
279 <menuitem action="Quit" />
280 </menu>
281 <menu action="Tint2">
282 <menuitem action="OpenDefault" />
283 <menuitem action="SaveDefault" />
284 <separator />
285 <menuitem action="Apply" />
286 </menu>
287 <menu action="Tools">
288 <menuitem action="FontChange" />
289 <separator />
290 <menuitem action="Defaults" />
291 </menu>
292 <menu action="HelpMenu">
293 <menuitem action="Help" />
294 <menuitem action="Report Bug" />
295 <separator />
296 <menuitem action="About" />
297 </menu>
298 </menubar>
299 <toolbar name="ToolBar">
300 <toolitem action="New" />
301 <toolitem action="Open" />
302 <toolitem action="Save" />
303 <separator />
304 <toolitem action="Apply" />
305 </toolbar>
306 </ui>
307 """
308
309 # Set up UI manager
310 self.uiManager = gtk.UIManager()
311
312 accelGroup = self.uiManager.get_accel_group()
313 self.add_accel_group(accelGroup)
314
315 self.ag = gtk.ActionGroup("File")
316 self.ag.add_actions([("File", None, "_File"),
317 ("New",gtk.STOCK_NEW, "_New", None, "Create a new config", self.new),
318 ("Open", gtk.STOCK_OPEN, "_Open", None, "Open an existing config", self.openFile),
319 ("Save", gtk.STOCK_SAVE, "_Save", None, "Save the current config", self.save),
320 ("Save As...", gtk.STOCK_SAVE_AS, "Save As", None, "Save the current config as...", self.saveAs),
321 ("SaveDefault", None, "Save As tint2 Default", None, "Save the current config as the tint2 default", self.saveAsDef),
322 ("OpenDefault", None, "Open tint2 Default", None, "Open the current tint2 default config", self.openDef),
323 ("Apply", gtk.STOCK_APPLY, "Apply Config", None, "Apply the current config to tint2", self.apply),
324 ("Quit", gtk.STOCK_QUIT, "_Quit", None, "Quit the program", self.quit),
325 ("Tools", None, "_Tools"),
326 ("Tint2", None, "Tint_2"),
327 ("HelpMenu", None, "_Help"),
328 ("FontChange",gtk.STOCK_SELECT_FONT, "Change All Fonts", None, "Change all fonts at once.", self.changeAllFonts),
329 ("Defaults",gtk.STOCK_PREFERENCES, "Change Defaults", None, "Change tintwizard defaults.", self.changeDefaults),
330 ("Help",gtk.STOCK_HELP, "_Help", None, "Get help with tintwizard", self.help),
331 ("Report Bug",None, "Report Bug", None, "Report a problem with tintwizard", self.reportBug),
332 ("About",gtk.STOCK_ABOUT, "_About Tint Wizard", None, "Find out more about Tint Wizard", self.about)])
333
334
335 # Add main UI
336 self.uiManager.insert_action_group(self.ag)
337 self.uiManager.add_ui_from_string(ui)
338
339 if not self.oneConfigFile:
340 # Attach menubar and toolbar to main window
341 self.table.attach(self.uiManager.get_widget("/MenuBar"), 0, 4, 0, 1)
342 self.table.attach(self.uiManager.get_widget("/ToolBar"), 0, 4, 1, 2)
343
344 # Create notebook
345 self.notebook = gtk.Notebook()
346 self.notebook.set_tab_pos(gtk.POS_TOP)
347
348 # Create notebook pages
349 # Background Options
350 self.tableBgs = gtk.Table(rows=1, columns=1, homogeneous=False)
351 self.tableBgs.set_row_spacings(5)
352 self.tableBgs.set_col_spacings(5)
353
354 self.bgNotebook = gtk.Notebook()
355 self.bgNotebook.set_scrollable(True)
356
357 self.tableBgs.attach(self.bgNotebook, 0, 2, 0, 1)
358
359 self.bgs = []
360
361 # Add buttons for adding/deleting background styles
362 temp = gtk.Button("New Background", gtk.STOCK_NEW)
363 temp.set_name("addBg")
364 temp.connect("clicked", self.addBgClick)
365 self.tableBgs.attach(temp, 0, 1, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
366 temp = gtk.Button("Delete Background", gtk.STOCK_DELETE)
367 temp.set_name("delBg")
368 temp.connect("clicked", self.delBgClick)
369 self.tableBgs.attach(temp, 1, 2, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
370
371 # Panel Options
372 self.tablePanel = gtk.Table(rows=9, columns=3, homogeneous=False)
373 self.tablePanel.set_row_spacings(5)
374 self.tablePanel.set_col_spacings(5)
375
376 temp = gtk.Label("Position")
377 temp.set_alignment(0, 0.5)
378 self.tablePanel.attach(temp, 0, 1, 0, 1, xpadding=10)
379 self.panelPosY = gtk.combo_box_new_text()
380 self.panelPosY.append_text("bottom")
381 self.panelPosY.append_text("top")
382 self.panelPosY.append_text("center")
383 self.panelPosY.set_active(0)
384 self.panelPosY.connect("changed", self.changeOccurred)
385 self.tablePanel.attach(self.panelPosY, 2, 3, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
386 self.panelPosX = gtk.combo_box_new_text()
387 self.panelPosX.append_text("left")
388 self.panelPosX.append_text("right")
389 self.panelPosX.append_text("center")
390 self.panelPosX.set_active(0)
391 self.panelPosX.connect("changed", self.changeOccurred)
392 self.tablePanel.attach(self.panelPosX, 1, 2, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
393
394 temp = gtk.Label("Panel Orientation")
395 temp.set_alignment(0, 0.5)
396 self.tablePanel.attach(temp, 0, 1, 1, 2, xpadding=10)
397 self.panelOrientation = gtk.combo_box_new_text()
398 self.panelOrientation.append_text("horizontal")
399 self.panelOrientation.append_text("vertical")
400 self.panelOrientation.set_active(0)
401 self.panelOrientation.connect("changed", self.changeOccurred)
402 self.tablePanel.attach(self.panelOrientation, 1, 2, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
403
404 self.panelSizeLabel = gtk.Label("Size (width, height)")
405 self.panelSizeLabel.set_alignment(0, 0.5)
406 self.tablePanel.attach(self.panelSizeLabel, 0, 1, 2, 3, xpadding=10)
407 self.panelSizeX = gtk.Entry(6)
408 self.panelSizeX.set_width_chars(8)
409 self.panelSizeX.set_text(PANEL_SIZE_X)
410 self.panelSizeX.connect("changed", self.changeOccurred)
411 self.tablePanel.attach(self.panelSizeX, 1, 2, 2, 3, xoptions=gtk.EXPAND)
412 self.panelSizeY = gtk.Entry(6)
413 self.panelSizeY.set_width_chars(8)
414 self.panelSizeY.set_text(PANEL_SIZE_Y)
415 self.panelSizeY.connect("changed", self.changeOccurred)
416 self.tablePanel.attach(self.panelSizeY, 2, 3, 2, 3, xoptions=gtk.EXPAND)
417
418 temp = gtk.Label("Margin (x, y)")
419 temp.set_alignment(0, 0.5)
420 self.tablePanel.attach(temp, 0, 1, 3, 4, xpadding=10)
421 self.panelMarginX = gtk.Entry(6)
422 self.panelMarginX.set_width_chars(8)
423 self.panelMarginX.set_text(PANEL_MARGIN_X)
424 self.panelMarginX.connect("changed", self.changeOccurred)
425 self.tablePanel.attach(self.panelMarginX, 1, 2, 3, 4, xoptions=gtk.EXPAND)
426 self.panelMarginY = gtk.Entry(6)
427 self.panelMarginY.set_width_chars(8)
428 self.panelMarginY.set_text(PANEL_MARGIN_Y)
429 self.panelMarginY.connect("changed", self.changeOccurred)
430 self.tablePanel.attach(self.panelMarginY, 2, 3, 3, 4, xoptions=gtk.EXPAND)
431
432 temp = gtk.Label("Padding (x, y)")
433 temp.set_alignment(0, 0.5)
434 self.tablePanel.attach(temp, 0, 1, 4, 5, xpadding=10)
435 self.panelPadX = gtk.Entry(6)
436 self.panelPadX.set_width_chars(8)
437 self.panelPadX.set_text(PANEL_PADDING_Y)
438 self.panelPadX.connect("changed", self.changeOccurred)
439 self.tablePanel.attach(self.panelPadX, 1, 2, 4, 5, xoptions=gtk.EXPAND)
440 self.panelPadY = gtk.Entry(6)
441 self.panelPadY.set_width_chars(8)
442 self.panelPadY.set_text(PANEL_PADDING_Y)
443 self.panelPadY.connect("changed", self.changeOccurred)
444 self.tablePanel.attach(self.panelPadY, 2, 3, 4, 5, xoptions=gtk.EXPAND)
445
446 temp = gtk.Label("Panel Background ID")
447 temp.set_alignment(0, 0.5)
448 self.tablePanel.attach(temp, 0, 1, 5, 6, xpadding=10)
449 self.panelBg = gtk.combo_box_new_text()
450 self.panelBg.append_text("0 (fully transparent)")
451 for i in range(len(self.bgs)):
452 self.panelBg.append_text(str(i+1))
453 self.panelBg.set_active(0)
454 self.panelBg.connect("changed", self.changeOccurred)
455 self.tablePanel.attach(self.panelBg, 1, 2, 5, 6, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
456
457 temp = gtk.Label("Window Manager Menu")
458 temp.set_alignment(0, 0.5)
459 self.tablePanel.attach(temp, 0, 1, 6, 7, xpadding=10)
460 self.panelMenu = gtk.CheckButton()
461 self.panelMenu.set_active(False)
462 self.panelMenu.connect("toggled", self.changeOccurred)
463 self.tablePanel.attach(self.panelMenu, 1, 2, 6, 7, xoptions=gtk.EXPAND)
464
465 temp = gtk.Label("Place In Window Manager Dock")
466 temp.set_alignment(0, 0.5)
467 self.tablePanel.attach(temp, 0, 1, 7, 8, xpadding=10)
468 self.panelDock = gtk.CheckButton()
469 self.panelDock.set_active(False)
470 self.panelDock.connect("toggled", self.changeOccurred)
471 self.tablePanel.attach(self.panelDock, 1, 2, 7, 8, xoptions=gtk.EXPAND)
472
473 temp = gtk.Label("Panel Monitor (all, 1, 2...)")
474 temp.set_alignment(0, 0.5)
475 self.tablePanel.attach(temp, 0, 1, 8, 9, xpadding=10)
476 self.panelMonitor = gtk.Entry(6)
477 self.panelMonitor.set_width_chars(8)
478 self.panelMonitor.set_text(PANEL_MONITOR)
479 self.panelMonitor.connect("changed", self.changeOccurred)
480 self.tablePanel.attach(self.panelMonitor, 1, 2, 8, 9, xoptions=gtk.EXPAND)
481
482 # Taskbar
483 self.tableTaskbar = gtk.Table(rows=4, columns=3, homogeneous=False)
484 self.tableTaskbar.set_row_spacings(5)
485 self.tableTaskbar.set_col_spacings(5)
486
487 temp = gtk.Label("Taskbar Mode")
488 temp.set_alignment(0, 0.5)
489 self.tableTaskbar.attach(temp, 0, 1, 0, 1, xpadding=10)
490 self.taskbarMode = gtk.combo_box_new_text()
491 self.taskbarMode.append_text("single_desktop")
492 self.taskbarMode.append_text("multi_desktop")
493 self.taskbarMode.set_active(0)
494 self.taskbarMode.connect("changed", self.changeOccurred)
495 self.tableTaskbar.attach(self.taskbarMode, 1, 2, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
496
497 temp = gtk.Label("Padding (x, y)")
498 temp.set_alignment(0, 0.5)
499 self.tableTaskbar.attach(temp, 0, 1, 1, 2, xpadding=10)
500 self.taskbarPadX = gtk.Entry(6)
501 self.taskbarPadX.set_width_chars(8)
502 self.taskbarPadX.set_text(TASKBAR_PADDING_X)
503 self.taskbarPadX.connect("changed", self.changeOccurred)
504 self.tableTaskbar.attach(self.taskbarPadX, 1, 2, 1, 2, xoptions=gtk.EXPAND)
505 self.taskbarPadY = gtk.Entry(6)
506 self.taskbarPadY.set_width_chars(8)
507 self.taskbarPadY.set_text(TASKBAR_PADDING_Y)
508 self.taskbarPadY.connect("changed", self.changeOccurred)
509 self.tableTaskbar.attach(self.taskbarPadY, 2, 3, 1, 2, xoptions=gtk.EXPAND)
510
511 temp = gtk.Label("Taskbar Background ID")
512 temp.set_alignment(0, 0.5)
513 self.tableTaskbar.attach(temp, 0, 1, 3, 4, xpadding=10)
514 self.taskbarBg = gtk.combo_box_new_text()
515 self.taskbarBg.append_text("0 (fully transparent)")
516 for i in range(len(self.bgs)):
517 self.taskbarBg.append_text(str(i+1))
518 self.taskbarBg.set_active(0)
519 self.taskbarBg.connect("changed", self.changeOccurred)
520 self.tableTaskbar.attach(self.taskbarBg, 1, 2, 3, 4, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
521
522 temp = gtk.Label("Active Taskbar Background ID")
523 temp.set_alignment(0, 0.5)
524 self.tableTaskbar.attach(temp, 0, 1, 4, 5, xpadding=10)
525 self.taskbarActiveBg = gtk.combo_box_new_text()
526 self.taskbarActiveBg.append_text("0 (fully transparent)")
527 for i in range(len(self.bgs)):
528 self.taskbarActiveBg.append_text(str(i+1))
529 self.taskbarActiveBg.set_active(0)
530 self.taskbarActiveBg.connect("changed", self.changeOccurred)
531 self.tableTaskbar.attach(self.taskbarActiveBg, 1, 2, 4, 5, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
532 self.taskbarActiveBgEnable = gtk.CheckButton("Enable")
533 self.taskbarActiveBgEnable.set_active(False)
534 self.taskbarActiveBgEnable.connect("toggled", self.changeOccurred)
535 self.tableTaskbar.attach(self.taskbarActiveBgEnable, 2, 3, 4, 5, xoptions=gtk.EXPAND)
536
537 # Task Options
538 self.tableTask = gtk.Table(rows=12, columns=3, homogeneous=False)
539 self.tableTask.set_row_spacings(5)
540 self.tableTask.set_col_spacings(5)
541
542 temp = gtk.Label("Number of 'Blinks' on Urgent Event")
543 temp.set_alignment(0, 0.5)
544 self.tableTask.attach(temp, 0, 1, 0, 1, xpadding=10)
545 self.taskBlinks = gtk.Entry(6)
546 self.taskBlinks.set_width_chars(8)
547 self.taskBlinks.set_text(TASK_BLINKS)
548 self.taskBlinks.connect("changed", self.changeOccurred)
549 self.tableTask.attach(self.taskBlinks, 1, 2, 0, 1, xoptions=gtk.EXPAND)
550
551 temp = gtk.Label("Show Text")
552 temp.set_alignment(0, 0.5)
553 self.tableTask.attach(temp, 0, 1, 1, 2, xpadding=10)
554 self.taskTextCheckButton = gtk.CheckButton()
555 self.taskTextCheckButton.set_active(True)
556 self.taskTextCheckButton.connect("toggled", self.changeOccurred)
557 self.tableTask.attach(self.taskTextCheckButton, 1, 2, 1, 2, xoptions=gtk.EXPAND)
558
559 temp = gtk.Label("Centre Text")
560 temp.set_alignment(0, 0.5)
561 self.tableTask.attach(temp, 0, 1, 2, 3, xpadding=10)
562 self.taskCentreCheckButton = gtk.CheckButton()
563 self.taskCentreCheckButton.set_active(True)
564 self.taskCentreCheckButton.connect("toggled", self.changeOccurred)
565 self.tableTask.attach(self.taskCentreCheckButton, 1, 2, 2, 3, xoptions=gtk.EXPAND)
566
567 temp = gtk.Label("Maximum Size (x, y)")
568 temp.set_alignment(0, 0.5)
569 self.tableTask.attach(temp, 0, 1, 3, 4, xpadding=10)
570 self.taskMaxSizeX = gtk.Entry(6)
571 self.taskMaxSizeX.set_width_chars(8)
572 self.taskMaxSizeX.set_text(TASK_MAXIMUM_SIZE_X)
573 self.taskMaxSizeX.connect("changed", self.changeOccurred)
574 self.tableTask.attach(self.taskMaxSizeX, 1, 2, 3, 4, xoptions=gtk.EXPAND)
575 self.taskMaxSizeY = gtk.Entry(6)
576 self.taskMaxSizeY.set_width_chars(8)
577 self.taskMaxSizeY.set_text(TASK_MAXIMUM_SIZE_Y)
578 self.taskMaxSizeY.connect("changed", self.changeOccurred)
579 self.tableTask.attach(self.taskMaxSizeY, 2, 3, 3, 4, xoptions=gtk.EXPAND)
580
581 temp = gtk.Label("Padding (x, y)")
582 temp.set_alignment(0, 0.5)
583 self.tableTask.attach(temp, 0, 1, 4, 5, xpadding=10)
584 self.taskPadX = gtk.Entry(6)
585 self.taskPadX.set_width_chars(8)
586 self.taskPadX.set_text(TASK_PADDING_X)
587 self.taskPadX.connect("changed", self.changeOccurred)
588 self.tableTask.attach(self.taskPadX, 1, 2, 4, 5, xoptions=gtk.EXPAND)
589 self.taskPadY = gtk.Entry(6)
590 self.taskPadY.set_width_chars(8)
591 self.taskPadY.set_text(TASK_PADDING_Y)
592 self.taskPadY.connect("changed", self.changeOccurred)
593 self.tableTask.attach(self.taskPadY, 2, 3, 4, 5, xoptions=gtk.EXPAND)
594
595 temp = gtk.Label("Horizontal Spacing")
596 temp.set_alignment(0, 0.5)
597 self.tableTask.attach(temp, 0, 1, 5, 6, xpadding=10)
598 self.taskbarSpacing = gtk.Entry(6)
599 self.taskbarSpacing.set_width_chars(8)
600 self.taskbarSpacing.set_text(TASK_SPACING)
601 self.taskbarSpacing.connect("changed", self.changeOccurred)
602 self.tableTask.attach(self.taskbarSpacing, 1, 2, 5, 6, xoptions=gtk.EXPAND)
603
604 temp = gtk.Label("Task Background ID")
605 temp.set_alignment(0, 0.5)
606 self.tableTask.attach(temp, 0, 1, 6, 7, xpadding=10)
607 self.taskBg = gtk.combo_box_new_text()
608 self.taskBg.append_text("0 (fully transparent)")
609 for i in range(len(self.bgs)):
610 self.taskBg.append_text(str(i+1))
611 self.taskBg.set_active(0)
612 self.taskBg.connect("changed", self.changeOccurred)
613 self.tableTask.attach(self.taskBg, 1, 2, 6, 7, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
614
615 temp = gtk.Label("Task Active Background ID")
616 temp.set_alignment(0, 0.5)
617 self.tableTask.attach(temp, 0, 1, 7, 8, xpadding=10)
618 self.taskActiveBg = gtk.combo_box_new_text()
619 self.taskActiveBg.append_text("0 (fully transparent)")
620 for i in range(len(self.bgs)):
621 self.taskActiveBg.append_text(str(i+1))
622 self.taskActiveBg.set_active(0)
623 self.taskActiveBg.connect("changed", self.changeOccurred)
624 self.tableTask.attach(self.taskActiveBg, 1, 2, 7, 8, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
625
626 # Icon Options
627 self.tableIcon = gtk.Table(rows=7, columns=3, homogeneous=False)
628 self.tableIcon.set_row_spacings(5)
629 self.tableIcon.set_col_spacings(5)
630
631 temp = gtk.Label("Show Icons")
632 temp.set_alignment(0, 0.5)
633 self.tableIcon.attach(temp, 0, 1, 0, 1, xpadding=10)
634 self.taskIconCheckButton = gtk.CheckButton()
635 self.taskIconCheckButton.set_active(True)
636 self.taskIconCheckButton.connect("toggled", self.changeOccurred)
637 self.tableIcon.attach(self.taskIconCheckButton, 1, 2, 0, 1, xoptions=gtk.EXPAND)
638
639 temp = gtk.Label("Note: Default values of 0 for each of these settings leaves icons unchanged!")
640 temp.set_alignment(0, 0.5)
641 self.tableIcon.attach(temp, 0, 1, 1, 2, xpadding=10)
642
643 temp = gtk.Label("Icon Alpha (0 to 100)")
644 temp.set_alignment(0, 0.5)
645 self.tableIcon.attach(temp, 0, 1, 2, 3, xpadding=10)
646 self.iconHue = gtk.Entry(6)
647 self.iconHue.set_width_chars(8)
648 self.iconHue.set_text(ICON_ALPHA)
649 self.iconHue.connect("changed", self.changeOccurred)
650 self.tableIcon.attach(self.iconHue, 1, 2, 2, 3, xoptions=gtk.EXPAND)
651
652 temp = gtk.Label("Icon Saturation (-100 to 100)")
653 temp.set_alignment(0, 0.5)
654 self.tableIcon.attach(temp, 0, 1, 3, 4, xpadding=10)
655 self.iconSat = gtk.Entry(6)
656 self.iconSat.set_width_chars(8)
657 self.iconSat.set_text(ICON_SAT)
658 self.iconSat.connect("changed", self.changeOccurred)
659 self.tableIcon.attach(self.iconSat, 1, 2, 3, 4, xoptions=gtk.EXPAND)
660
661 temp = gtk.Label("Icon Brightness (-100 to 100)")
662 temp.set_alignment(0, 0.5)
663 self.tableIcon.attach(temp, 0, 1, 4, 5, xpadding=10)
664 self.iconBri = gtk.Entry(6)
665 self.iconBri.set_width_chars(8)
666 self.iconBri.set_text(ICON_BRI)
667 self.iconBri.connect("changed", self.changeOccurred)
668 self.tableIcon.attach(self.iconBri, 1, 2, 4, 5, xoptions=gtk.EXPAND)
669
670 temp = gtk.Label("Active Icon Alpha (0 to 100)")
671 temp.set_alignment(0, 0.5)
672 self.tableIcon.attach(temp, 0, 1, 5, 6, xpadding=10)
673 self.activeIconHue = gtk.Entry(6)
674 self.activeIconHue.set_width_chars(8)
675 self.activeIconHue.set_text(ACTIVE_ICON_ALPHA)
676 self.activeIconHue.connect("changed", self.changeOccurred)
677 self.tableIcon.attach(self.activeIconHue, 1, 2, 5, 6, xoptions=gtk.EXPAND)
678
679 temp = gtk.Label("Active Icon Saturation (-100 to 100)")
680 temp.set_alignment(0, 0.5)
681 self.tableIcon.attach(temp, 0, 1, 6, 7, xpadding=10)
682 self.activeIconSat = gtk.Entry(6)
683 self.activeIconSat.set_width_chars(8)
684 self.activeIconSat.set_text(ACTIVE_ICON_SAT)
685 self.activeIconSat.connect("changed", self.changeOccurred)
686 self.tableIcon.attach(self.activeIconSat, 1, 2, 6, 7, xoptions=gtk.EXPAND)
687
688 temp = gtk.Label("Active Icon Brightness (-100 to 100)")
689 temp.set_alignment(0, 0.5)
690 self.tableIcon.attach(temp, 0, 1, 7, 8, xpadding=10)
691 self.activeIconBri = gtk.Entry(6)
692 self.activeIconBri.set_width_chars(8)
693 self.activeIconBri.set_text(ACTIVE_ICON_BRI)
694 self.activeIconBri.connect("changed", self.changeOccurred)
695 self.tableIcon.attach(self.activeIconBri, 1, 2, 7, 8, xoptions=gtk.EXPAND)
696
697 # Font Options
698 self.tableFont = gtk.Table(rows=3, columns=3, homogeneous=False)
699 self.tableFont.set_row_spacings(5)
700 self.tableFont.set_col_spacings(5)
701
702 temp = gtk.Label("Font")
703 temp.set_alignment(0, 0.5)
704 self.tableFont.attach(temp, 0, 1, 0, 1, xpadding=10)
705 self.fontButton = gtk.FontButton()
706
707 if self.defaults["font"] in [None, "None"]: # If there was no font specified in the config file
708 self.defaults["font"] = self.fontButton.get_font_name() # Use the gtk default
709
710 self.fontButton.set_font_name(self.defaults["font"])
711 self.fontButton.connect("font-set", self.changeOccurred)
712 self.tableFont.attach(self.fontButton, 1, 2, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
713
714 temp = gtk.Label("Font Color")
715 temp.set_alignment(0, 0.5)
716 self.tableFont.attach(temp, 0, 1, 1, 2, xpadding=10)
717 self.fontCol = gtk.Entry(7)
718 self.fontCol.set_width_chars(9)
719 self.fontCol.set_name("fontCol")
720 self.fontCol.connect("activate", self.colorTyped)
721 self.tableFont.attach(self.fontCol, 1, 2, 1, 2, xoptions=gtk.EXPAND)
722 self.fontColButton = gtk.ColorButton(gtk.gdk.color_parse(self.defaults["fgColor"]))
723 self.fontColButton.set_use_alpha(True)
724 self.fontColButton.set_name("fontCol")
725 self.fontColButton.connect("color-set", self.colorChange)
726 self.tableFont.attach(self.fontColButton, 2, 3, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
727 self.fontCol.set_text(self.defaults["fgColor"])
728 # Add this AFTER we set color to avoid "changed" event
729 self.fontCol.connect("changed", self.changeOccurred)
730
731 temp = gtk.Label("Active Font Color")
732 temp.set_alignment(0, 0.5)
733 self.tableFont.attach(temp, 0, 1, 2, 3, xpadding=10)
734 self.fontActiveCol = gtk.Entry(7)
735 self.fontActiveCol.set_width_chars(9)
736 self.fontActiveCol.set_name("fontActiveCol")
737 self.fontActiveCol.connect("activate", self.colorTyped)
738 self.tableFont.attach(self.fontActiveCol, 1, 2, 2, 3, xoptions=gtk.EXPAND)
739 self.fontActiveColButton = gtk.ColorButton(gtk.gdk.color_parse(self.defaults["fgColor"]))
740 self.fontActiveColButton.set_use_alpha(True)
741 self.fontActiveColButton.set_name("fontActiveCol")
742 self.fontActiveColButton.connect("color-set", self.colorChange)
743 self.tableFont.attach(self.fontActiveColButton, 2, 3, 2, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
744 self.fontActiveCol.set_text(self.defaults["fgColor"])
745 # Add this AFTER we set color to avoid "changed" event
746 self.fontActiveCol.connect("changed", self.changeOccurred)
747
748 temp = gtk.Label("Font Shadow")
749 temp.set_alignment(0, 0.5)
750 self.tableFont.attach(temp, 0, 1, 3, 4, xpadding=10)
751 self.fontShadowCheckButton = gtk.CheckButton()
752 self.fontShadowCheckButton.set_active(False)
753 self.fontShadowCheckButton.connect("toggled", self.changeOccurred)
754 self.tableFont.attach(self.fontShadowCheckButton, 1, 2, 3, 4, xoptions=gtk.EXPAND)
755
756 # Systray Options
757 self.tableTray = gtk.Table(rows=3, columns=3, homogeneous=False)
758 self.tableTray.set_row_spacings(5)
759 self.tableTray.set_col_spacings(5)
760
761 temp = gtk.Label("Show Systray")
762 temp.set_alignment(0, 0.5)
763 self.tableTray.attach(temp, 0, 1, 0, 1, xpadding=10)
764 self.trayCheckButton = gtk.CheckButton()
765 self.trayCheckButton.set_active(True)
766 self.trayCheckButton.connect("toggled", self.changeOccurred)
767 self.tableTray.attach(self.trayCheckButton, 1, 2, 0, 1, xoptions=gtk.EXPAND)
768
769 temp = gtk.Label("Padding (x, y)")
770 temp.set_alignment(0, 0.5)
771 self.tableTray.attach(temp, 0, 1, 1, 2, xpadding=10)
772 self.trayPadX = gtk.Entry(6)
773 self.trayPadX.set_width_chars(8)
774 self.trayPadX.set_text(TRAY_PADDING_X)
775 self.trayPadX.connect("changed", self.changeOccurred)
776 self.tableTray.attach(self.trayPadX, 1, 2, 1, 2, xoptions=gtk.EXPAND)
777 self.trayPadY = gtk.Entry(6)
778 self.trayPadY.set_width_chars(8)
779 self.trayPadY.set_text(TRAY_PADDING_Y)
780 self.trayPadY.connect("changed", self.changeOccurred)
781 self.tableTray.attach(self.trayPadY, 2, 3, 1, 2, xoptions=gtk.EXPAND)
782
783 temp = gtk.Label("Horizontal Spacing")
784 temp.set_alignment(0, 0.5)
785 self.tableTray.attach(temp, 0, 1, 2, 3, xpadding=10)
786 self.traySpacing = gtk.Entry(6)
787 self.traySpacing.set_width_chars(8)
788 self.traySpacing.set_text(TRAY_SPACING)
789 self.traySpacing.connect("changed", self.changeOccurred)
790 self.tableTray.attach(self.traySpacing, 1, 2, 2, 3, xoptions=gtk.EXPAND)
791
792 temp = gtk.Label("Icon Ordering")
793 temp.set_alignment(0, 0.5)
794 self.tableTray.attach(temp, 0, 1, 3, 4, xpadding=10)
795 self.trayOrder = gtk.combo_box_new_text()
796 self.trayOrder.append_text("ascending")
797 self.trayOrder.append_text("descending")
798 self.trayOrder.append_text("left2right")
799 self.trayOrder.append_text("right2left")
800 self.trayOrder.set_active(0)
801 self.trayOrder.connect("changed", self.changeOccurred)
802 self.tableTray.attach(self.trayOrder, 1, 2, 3, 4, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
803
804 temp = gtk.Label("Systray Background ID")
805 temp.set_alignment(0, 0.5)
806 self.tableTray.attach(temp, 0, 1, 4, 5, xpadding=10)
807 self.trayBg = gtk.combo_box_new_text()
808 self.trayBg.append_text("0 (fully transparent)")
809 for i in range(len(self.bgs)):
810 self.trayBg.append_text(str(i+1))
811 self.trayBg.set_active(0)
812 self.trayBg.connect("changed", self.changeOccurred)
813 self.tableTray.attach(self.trayBg, 1, 2, 4, 5, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
814
815 # Clock Options
816 self.tableClockDisplays = gtk.Table(rows=3, columns=3, homogeneous=False)
817 self.tableClockDisplays.set_row_spacings(5)
818 self.tableClockDisplays.set_col_spacings(5)
819
820 temp = gtk.Label("Show Clock")
821 temp.set_alignment(0, 0.5)
822 self.tableClockDisplays.attach(temp, 0, 1, 0, 1, xpadding=10)
823 self.clockCheckButton = gtk.CheckButton()
824 self.clockCheckButton.set_active(True)
825 self.clockCheckButton.connect("toggled", self.changeOccurred)
826 self.tableClockDisplays.attach(self.clockCheckButton, 1, 2, 0, 1, xoptions=gtk.EXPAND)
827
828 temp = gtk.Label("Time 1 Format")
829 temp.set_alignment(0, 0.5)
830 self.tableClockDisplays.attach(temp, 0, 1, 1, 2, xpadding=10)
831 self.clock1Format = gtk.Entry(50)
832 self.clock1Format.set_width_chars(20)
833 self.clock1Format.set_text(CLOCK_FMT_1)
834 self.clock1Format.connect("changed", self.changeOccurred)
835 self.tableClockDisplays.attach(self.clock1Format, 1, 2, 1, 2, xoptions=gtk.EXPAND)
836 self.clock1CheckButton = gtk.CheckButton("Show")
837 self.clock1CheckButton.set_active(True)
838 self.clock1CheckButton.connect("toggled", self.changeOccurred)
839 self.tableClockDisplays.attach(self.clock1CheckButton, 2, 3, 1, 2, xoptions=gtk.EXPAND)
840
841 temp = gtk.Label("Time 1 Font")
842 temp.set_alignment(0, 0.5)
843 self.tableClockDisplays.attach(temp, 0, 1, 2, 3, xpadding=10)
844 self.clock1FontButton = gtk.FontButton()
845 self.clock1FontButton.set_font_name(self.defaults["font"])
846 self.clock1FontButton.connect("font-set", self.changeOccurred)
847 self.tableClockDisplays.attach(self.clock1FontButton, 1, 2, 2, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
848
849 temp = gtk.Label("Time 2 Format")
850 temp.set_alignment(0, 0.5)
851 self.tableClockDisplays.attach(temp, 0, 1, 3, 4, xpadding=10)
852 self.clock2Format = gtk.Entry(50)
853 self.clock2Format.set_width_chars(20)
854 self.clock2Format.set_text(CLOCK_FMT_2)
855 self.clock2Format.connect("changed", self.changeOccurred)
856 self.tableClockDisplays.attach(self.clock2Format, 1, 2, 3, 4, xoptions=gtk.EXPAND)
857 self.clock2CheckButton = gtk.CheckButton("Show")
858 self.clock2CheckButton.set_active(True)
859 self.clock2CheckButton.connect("toggled", self.changeOccurred)
860 self.tableClockDisplays.attach(self.clock2CheckButton, 2, 3, 3, 4, xoptions=gtk.EXPAND)
861
862 temp = gtk.Label("Time 2 Font")
863 temp.set_alignment(0, 0.5)
864 self.tableClockDisplays.attach(temp, 0, 1, 4, 5, xpadding=10)
865 self.clock2FontButton = gtk.FontButton()
866 self.clock2FontButton.set_font_name(self.defaults["font"])
867 self.clock2FontButton.connect("font-set", self.changeOccurred)
868 self.tableClockDisplays.attach(self.clock2FontButton, 1, 2, 4, 5, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
869
870 self.clockArea = gtk.ScrolledWindow()
871 self.clockBuf = gtk.TextBuffer()
872 self.clockTextView = gtk.TextView(self.clockBuf)
873 self.clockBuf.insert_at_cursor("%H 00-23 (24-hour) %I 01-12 (12-hour) %l 1-12 (12-hour) %M 00-59 (minutes)\n%S 00-59 (seconds) %P am/pm %b Jan-Dec %B January-December\n%a Sun-Sat %A Sunday-Saturday %d 01-31 (day) %e 1-31 (day)\n%y 2 digit year, e.g. 09 %Y 4 digit year, e.g. 2009")
874 self.clockTextView.set_editable(False)
875 self.clockArea.add_with_viewport(self.clockTextView)
876 self.tableClockDisplays.attach(self.clockArea, 0, 3, 5, 6, xpadding=10)
877
878 self.tableClockSettings = gtk.Table(rows=3, columns=3, homogeneous=False)
879 self.tableClockSettings.set_row_spacings(5)
880 self.tableClockSettings.set_col_spacings(5)
881
882 temp = gtk.Label("Clock Font Color")
883 temp.set_alignment(0, 0.5)
884 self.tableClockSettings.attach(temp, 0, 1, 0, 1, xpadding=10)
885 self.clockFontCol = gtk.Entry(7)
886 self.clockFontCol.set_width_chars(9)
887 self.clockFontCol.set_name("clockFontCol")
888 self.clockFontCol.connect("activate", self.colorTyped)
889 self.tableClockSettings.attach(self.clockFontCol, 1, 2, 0, 1, xoptions=gtk.EXPAND)
890 self.clockFontColButton = gtk.ColorButton(gtk.gdk.color_parse(self.defaults["fgColor"]))
891 self.clockFontColButton.set_use_alpha(True)
892 self.clockFontColButton.set_name("clockFontCol")
893 self.clockFontColButton.connect("color-set", self.colorChange)
894 self.tableClockSettings.attach(self.clockFontColButton, 2, 3, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
895 self.clockFontCol.set_text(self.defaults["fgColor"])
896 # Add this AFTER we set color to avoid "changed" event
897 self.clockFontCol.connect("changed", self.changeOccurred)
898
899 temp = gtk.Label("Padding (x, y)")
900 temp.set_alignment(0, 0.5)
901 self.tableClockSettings.attach(temp, 0, 1, 1, 2, xpadding=10)
902 self.clockPadX = gtk.Entry(6)
903 self.clockPadX.set_width_chars(8)
904 self.clockPadX.set_text(CLOCK_PADDING_X)
905 self.clockPadX.connect("changed", self.changeOccurred)
906 self.tableClockSettings.attach(self.clockPadX, 1, 2, 1, 2, xoptions=gtk.EXPAND)
907 self.clockPadY = gtk.Entry(6)
908 self.clockPadY.set_width_chars(8)
909 self.clockPadY.set_text(CLOCK_PADDING_Y)
910 self.clockPadY.connect("changed", self.changeOccurred)
911 self.tableClockSettings.attach(self.clockPadY, 2, 3, 1, 2, xoptions=gtk.EXPAND)
912
913 temp = gtk.Label("Clock Background ID")
914 temp.set_alignment(0, 0.5)
915 self.tableClockSettings.attach(temp, 0, 1, 2, 3, xpadding=10)
916 self.clockBg = gtk.combo_box_new_text()
917 self.clockBg.append_text("0 (fully transparent)")
918 for i in range(len(self.bgs)):
919 self.clockBg.append_text(str(i+1))
920 self.clockBg.set_active(0)
921 self.clockBg.connect("changed", self.changeOccurred)
922 self.tableClockSettings.attach(self.clockBg, 1, 2, 2, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
923
924 temp = gtk.Label("Left Click Command")
925 temp.set_alignment(0, 0.5)
926 self.tableClockSettings.attach(temp, 0, 1, 3, 4, xpadding=10)
927 self.clockLClick = gtk.Entry(50)
928 self.clockLClick.set_width_chars(20)
929 self.clockLClick.set_text(CLOCK_LCLICK)
930 self.clockLClick.connect("changed", self.changeOccurred)
931 self.tableClockSettings.attach(self.clockLClick, 1, 2, 3, 4, xoptions=gtk.EXPAND)
932
933 temp = gtk.Label("Right Click Command")
934 temp.set_alignment(0, 0.5)
935 self.tableClockSettings.attach(temp, 0, 1, 4, 5, xpadding=10)
936 self.clockRClick = gtk.Entry(50)
937 self.clockRClick.set_width_chars(20)
938 self.clockRClick.set_text(CLOCK_RCLICK)
939 self.clockRClick.connect("changed", self.changeOccurred)
940 self.tableClockSettings.attach(self.clockRClick, 1, 2, 4, 5, xoptions=gtk.EXPAND)
941
942 # Tooltip Options
943 self.tableTooltip = gtk.Table(rows=7, columns=3, homogeneous=False)
944 self.tableTooltip.set_row_spacings(5)
945 self.tableTooltip.set_col_spacings(5)
946
947 temp = gtk.Label("Show Tooltips")
948 temp.set_alignment(0, 0.5)
949 self.tableTooltip.attach(temp, 0, 1, 0, 1, xpadding=10)
950 self.tooltipShow = gtk.CheckButton()
951 self.tooltipShow.set_active(False)
952 self.tooltipShow.connect("toggled", self.changeOccurred)
953 self.tableTooltip.attach(self.tooltipShow, 1, 2, 0, 1, xoptions=gtk.EXPAND)
954
955 temp = gtk.Label("Padding (x, y)")
956 temp.set_alignment(0, 0.5)
957 self.tableTooltip.attach(temp, 0, 1, 1, 2, xpadding=10)
958 self.tooltipPadX = gtk.Entry(6)
959 self.tooltipPadX.set_width_chars(8)
960 self.tooltipPadX.set_text(TOOLTIP_PADDING_X)
961 self.tooltipPadX.connect("changed", self.changeOccurred)
962 self.tableTooltip.attach(self.tooltipPadX, 1, 2, 1, 2, xoptions=gtk.EXPAND)
963 self.tooltipPadY = gtk.Entry(6)
964 self.tooltipPadY.set_width_chars(8)
965 self.tooltipPadY.set_text(TOOLTIP_PADDING_Y)
966 self.tooltipPadY.connect("changed", self.changeOccurred)
967 self.tableTooltip.attach(self.tooltipPadY, 2, 3, 1, 2, xoptions=gtk.EXPAND)
968
969 temp = gtk.Label("Tooltip Show Timeout (seconds)")
970 temp.set_alignment(0, 0.5)
971 self.tableTooltip.attach(temp, 0, 1, 2, 3, xpadding=10)
972 self.tooltipShowTime = gtk.Entry(6)
973 self.tooltipShowTime.set_width_chars(8)
974 self.tooltipShowTime.set_text(TOOLTIP_SHOW_TIMEOUT)
975 self.tooltipShowTime.connect("changed", self.changeOccurred)
976 self.tableTooltip.attach(self.tooltipShowTime, 1, 2, 2, 3, xoptions=gtk.EXPAND)
977
978 temp = gtk.Label("Tooltip Hide Timeout (seconds)")
979 temp.set_alignment(0, 0.5)
980 self.tableTooltip.attach(temp, 0, 1, 3, 4, xpadding=10)
981 self.tooltipHideTime = gtk.Entry(6)
982 self.tooltipHideTime.set_width_chars(8)
983 self.tooltipHideTime.set_text(TOOLTIP_HIDE_TIMEOUT)
984 self.tooltipHideTime.connect("changed", self.changeOccurred)
985 self.tableTooltip.attach(self.tooltipHideTime, 1, 2, 3, 4, xoptions=gtk.EXPAND)
986
987 temp = gtk.Label("Tooltip Background ID")
988 temp.set_alignment(0, 0.5)
989 self.tableTooltip.attach(temp, 0, 1, 4, 5, xpadding=10)
990 self.tooltipBg = gtk.combo_box_new_text()
991 self.tooltipBg.append_text("0 (fully transparent)")
992 for i in range(len(self.bgs)):
993 self.tooltipBg.append_text(str(i+1))
994 self.tooltipBg.set_active(0)
995 self.tooltipBg.connect("changed", self.changeOccurred)
996 self.tableTooltip.attach(self.tooltipBg, 1, 2, 4, 5, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
997
998 temp = gtk.Label("Tooltip Font")
999 temp.set_alignment(0, 0.5)
1000 self.tableTooltip.attach(temp, 0, 1, 5, 6, xpadding=10)
1001 self.tooltipFont = gtk.FontButton()
1002 self.tooltipFont.set_font_name(self.defaults["font"])
1003 self.tooltipFont.connect("font-set", self.changeOccurred)
1004 self.tableTooltip.attach(self.tooltipFont, 1, 2, 5, 6, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1005
1006 temp = gtk.Label("Tooltip Font Color")
1007 temp.set_alignment(0, 0.5)
1008 self.tableTooltip.attach(temp, 0, 1, 6, 7, xpadding=10)
1009 self.tooltipFontCol = gtk.Entry(7)
1010 self.tooltipFontCol.set_width_chars(9)
1011 self.tooltipFontCol.set_name("tooltipFontCol")
1012 self.tooltipFontCol.connect("activate", self.colorTyped)
1013 self.tableTooltip.attach(self.tooltipFontCol, 1, 2, 6, 7, xoptions=gtk.EXPAND)
1014 self.tooltipFontColButton = gtk.ColorButton(gtk.gdk.color_parse(self.defaults["fgColor"]))
1015 self.tooltipFontColButton.set_use_alpha(True)
1016 self.tooltipFontColButton.set_name("tooltipFontCol")
1017 self.tooltipFontColButton.connect("color-set", self.colorChange)
1018 self.tableTooltip.attach(self.tooltipFontColButton, 2, 3, 6, 7, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1019 self.tooltipFontCol.set_text(self.defaults["fgColor"])
1020 # Add this AFTER we set color to avoid "changed" event
1021 self.clockFontCol.connect("changed", self.changeOccurred)
1022
1023 # Mouse Options
1024 self.tableMouse = gtk.Table(rows=4, columns=3, homogeneous=False)
1025 self.tableMouse.set_row_spacings(5)
1026 self.tableMouse.set_col_spacings(5)
1027
1028 temp = gtk.Label("Middle Mouse Click Action")
1029 temp.set_alignment(0, 0.5)
1030 self.tableMouse.attach(temp, 0, 1, 0, 1, xpadding=10)
1031 self.mouseMiddle = gtk.combo_box_new_text()
1032 self.mouseMiddle.append_text("none")
1033 self.mouseMiddle.append_text("close")
1034 self.mouseMiddle.append_text("toggle")
1035 self.mouseMiddle.append_text("iconify")
1036 self.mouseMiddle.append_text("shade")
1037 self.mouseMiddle.append_text("toggle_iconify")
1038 self.mouseMiddle.append_text("maximize_restore")
1039 self.mouseMiddle.append_text("desktop_left")
1040 self.mouseMiddle.append_text("desktop_right")
1041 self.mouseMiddle.set_active(0)
1042 self.mouseMiddle.connect("changed", self.changeOccurred)
1043 self.tableMouse.attach(self.mouseMiddle, 1, 2, 0, 1, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1044
1045 temp = gtk.Label("Right Mouse Click Action")
1046 temp.set_alignment(0, 0.5)
1047 self.tableMouse.attach(temp, 0, 1, 1, 2, xpadding=10)
1048 self.mouseRight = gtk.combo_box_new_text()
1049 self.mouseRight.append_text("none")
1050 self.mouseRight.append_text("close")
1051 self.mouseRight.append_text("toggle")
1052 self.mouseRight.append_text("iconify")
1053 self.mouseRight.append_text("shade")
1054 self.mouseRight.append_text("toggle_iconify")
1055 self.mouseRight.append_text("maximize_restore")
1056 self.mouseRight.append_text("desktop_left")
1057 self.mouseRight.append_text("desktop_right")
1058 self.mouseRight.set_active(0)
1059 self.mouseRight.connect("changed", self.changeOccurred)
1060 self.tableMouse.attach(self.mouseRight, 1, 2, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1061
1062 temp = gtk.Label("Mouse Wheel Scroll Up Action")
1063 temp.set_alignment(0, 0.5)
1064 self.tableMouse.attach(temp, 0, 1, 2, 3, xpadding=10)
1065 self.mouseUp = gtk.combo_box_new_text()
1066 self.mouseUp.append_text("none")
1067 self.mouseUp.append_text("close")
1068 self.mouseUp.append_text("toggle")
1069 self.mouseUp.append_text("iconify")
1070 self.mouseUp.append_text("shade")
1071 self.mouseUp.append_text("toggle_iconify")
1072 self.mouseUp.append_text("maximize_restore")
1073 self.mouseUp.append_text("desktop_left")
1074 self.mouseUp.append_text("desktop_right")
1075 self.mouseUp.set_active(0)
1076 self.mouseUp.connect("changed", self.changeOccurred)
1077 self.tableMouse.attach(self.mouseUp, 1, 2, 2, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1078
1079 temp = gtk.Label("Mouse Wheel Scroll Down Action")
1080 temp.set_alignment(0, 0.5)
1081 self.tableMouse.attach(temp, 0, 1, 3, 4, xpadding=10)
1082 self.mouseDown = gtk.combo_box_new_text()
1083 self.mouseDown.append_text("none")
1084 self.mouseDown.append_text("close")
1085 self.mouseDown.append_text("toggle")
1086 self.mouseDown.append_text("iconify")
1087 self.mouseDown.append_text("shade")
1088 self.mouseDown.append_text("toggle_iconify")
1089 self.mouseDown.append_text("maximize_restore")
1090 self.mouseDown.append_text("desktop_left")
1091 self.mouseDown.append_text("desktop_right")
1092 self.mouseDown.set_active(0)
1093 self.mouseDown.connect("changed", self.changeOccurred)
1094 self.tableMouse.attach(self.mouseDown, 1, 2, 3, 4, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1095
1096 # Battery Options
1097 self.tableBattery = gtk.Table(rows=8, columns=3, homogeneous=False)
1098 self.tableBattery.set_row_spacings(5)
1099 self.tableBattery.set_col_spacings(5)
1100
1101 temp = gtk.Label("Show Battery Applet")
1102 temp.set_alignment(0, 0.5)
1103 self.tableBattery.attach(temp, 0, 1, 0, 1, xpadding=10)
1104 self.batteryCheckButton = gtk.CheckButton()
1105 self.batteryCheckButton.set_active(False)
1106 self.batteryCheckButton.connect("toggled", self.changeOccurred)
1107 self.tableBattery.attach(self.batteryCheckButton, 1, 2, 0, 1, xoptions=gtk.EXPAND)
1108
1109 temp = gtk.Label("Battery Low Status (%)")
1110 temp.set_alignment(0, 0.5)
1111 self.tableBattery.attach(temp, 0, 1, 1, 2, xpadding=10)
1112 self.batteryLow = gtk.Entry(6)
1113 self.batteryLow.set_width_chars(8)
1114 self.batteryLow.set_text(BATTERY_LOW)
1115 self.batteryLow.connect("changed", self.changeOccurred)
1116 self.tableBattery.attach(self.batteryLow, 1, 2, 1, 2, xoptions=gtk.EXPAND)
1117
1118 temp = gtk.Label("Battery Low Action")
1119 temp.set_alignment(0, 0.5)
1120 self.tableBattery.attach(temp, 0, 1, 2, 3, xpadding=10)
1121 self.batteryLowAction = gtk.Entry(150)
1122 self.batteryLowAction.set_width_chars(32)
1123 self.batteryLowAction.set_text(BATTERY_ACTION)
1124 self.batteryLowAction.connect("changed", self.changeOccurred)
1125 self.tableBattery.attach(self.batteryLowAction, 1, 3, 2, 3, xoptions=gtk.EXPAND)
1126
1127 temp = gtk.Label("Battery 1 Font")
1128 temp.set_alignment(0, 0.5)
1129 self.tableBattery.attach(temp, 0, 1, 3, 4, xpadding=10)
1130 self.bat1FontButton = gtk.FontButton()
1131 self.bat1FontButton.set_font_name(self.defaults["font"])
1132 self.bat1FontButton.connect("font-set", self.changeOccurred)
1133 self.tableBattery.attach(self.bat1FontButton, 1, 2, 3, 4, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1134
1135 temp = gtk.Label("Battery 2 Font")
1136 temp.set_alignment(0, 0.5)
1137 self.tableBattery.attach(temp, 0, 1, 4, 5, xpadding=10)
1138 self.bat2FontButton = gtk.FontButton()
1139 self.bat2FontButton.set_font_name(self.defaults["font"])
1140 self.bat2FontButton.connect("font-set", self.changeOccurred)
1141 self.tableBattery.attach(self.bat2FontButton, 1, 2, 4, 5, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1142
1143 temp = gtk.Label("Battery Font Color")
1144 temp.set_alignment(0, 0.5)
1145 self.tableBattery.attach(temp, 0, 1, 5, 6, xpadding=10)
1146 self.batteryFontCol = gtk.Entry(7)
1147 self.batteryFontCol.set_width_chars(9)
1148 self.batteryFontCol.set_name("batteryFontCol")
1149 self.batteryFontCol.connect("activate", self.colorTyped)
1150 self.tableBattery.attach(self.batteryFontCol, 1, 2, 5, 6, xoptions=gtk.EXPAND)
1151 self.batteryFontColButton = gtk.ColorButton(gtk.gdk.color_parse(self.defaults["fgColor"]))
1152 self.batteryFontColButton.set_use_alpha(True)
1153 self.batteryFontColButton.set_name("batteryFontCol")
1154 self.batteryFontColButton.connect("color-set", self.colorChange)
1155 self.tableBattery.attach(self.batteryFontColButton, 2, 3, 5, 6, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1156 self.batteryFontCol.set_text(self.defaults["fgColor"])
1157 # Add this AFTER we set color to avoid "changed" event
1158 self.batteryFontCol.connect("changed", self.changeOccurred)
1159
1160 temp = gtk.Label("Padding (x, y)")
1161 temp.set_alignment(0, 0.5)
1162 self.tableBattery.attach(temp, 0, 1, 6, 7, xpadding=10)
1163 self.batteryPadX = gtk.Entry(6)
1164 self.batteryPadX.set_width_chars(8)
1165 self.batteryPadX.set_text(BATTERY_PADDING_X)
1166 self.batteryPadX.connect("changed", self.changeOccurred)
1167 self.tableBattery.attach(self.batteryPadX, 1, 2, 6, 7, xoptions=gtk.EXPAND)
1168 self.batteryPadY = gtk.Entry(6)
1169 self.batteryPadY.set_width_chars(8)
1170 self.batteryPadY.set_text(BATTERY_PADDING_Y)
1171 self.batteryPadY.connect("changed", self.changeOccurred)
1172 self.tableBattery.attach(self.batteryPadY, 2, 3, 6, 7, xoptions=gtk.EXPAND)
1173
1174 temp = gtk.Label("Battery Background ID")
1175 temp.set_alignment(0, 0.5)
1176 self.tableBattery.attach(temp, 0, 1, 7, 8, xpadding=10)
1177 self.batteryBg = gtk.combo_box_new_text()
1178 self.batteryBg.append_text("0 (fully transparent)")
1179 for i in range(len(self.bgs)):
1180 self.batteryBg.append_text(str(i+1))
1181 self.batteryBg.set_active(0)
1182 self.batteryBg.connect("changed", self.changeOccurred)
1183 self.tableBattery.attach(self.batteryBg, 1, 2, 7, 8, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1184
1185 # View Config
1186 self.configArea = gtk.ScrolledWindow()
1187 self.configBuf = gtk.TextBuffer()
1188 self.configTextView = gtk.TextView(self.configBuf)
1189 self.configArea.add_with_viewport(self.configTextView)
1190
1191 # Add backgrounds to notebooks
1192 for i in range(self.defaults["bgCount"]):
1193 self.addBgClick(None, init=True)
1194
1195 self.bgNotebook.set_current_page(0)
1196
1197 # Create sub-notebooks
1198 self.taskNotebook = gtk.Notebook()
1199 self.taskNotebook.set_tab_pos(gtk.POS_TOP)
1200 self.taskNotebook.set_current_page(0)
1201
1202 self.taskNotebook.append_page(self.tableTask, gtk.Label("Task Settings"))
1203 self.taskNotebook.append_page(self.tableIcon, gtk.Label("Task Icons"))
1204 self.taskNotebook.append_page(self.tableFont, gtk.Label("Task Fonts"))
1205
1206 self.clockNotebook = gtk.Notebook()
1207 self.clockNotebook.set_tab_pos(gtk.POS_TOP)
1208 self.clockNotebook.set_current_page(0)
1209
1210 self.clockNotebook.append_page(self.tableClockDisplays, gtk.Label("Clock Display"))
1211 self.clockNotebook.append_page(self.tableClockSettings, gtk.Label("Clock Settings"))
1212
1213 # Add pages to notebook
1214 self.notebook.append_page(self.tableBgs, gtk.Label("Backgrounds"))
1215 self.notebook.append_page(self.tablePanel, gtk.Label("Panel"))
1216 self.notebook.append_page(self.tableTaskbar, gtk.Label("Taskbar"))
1217 self.notebook.append_page(self.taskNotebook, gtk.Label("Tasks"))
1218 self.notebook.append_page(self.tableTray, gtk.Label("Systray"))
1219 self.notebook.append_page(self.clockNotebook, gtk.Label("Clock"))
1220 self.notebook.append_page(self.tableMouse, gtk.Label("Mouse"))
1221 self.notebook.append_page(self.tableTooltip, gtk.Label("Tooltips"))
1222 self.notebook.append_page(self.tableBattery, gtk.Label("Battery"))
1223 self.notebook.append_page(self.configArea, gtk.Label("View Config"))
1224
1225 self.notebook.connect("switch-page", self.switchPage)
1226
1227 # Add notebook to window and show
1228 self.table.attach(self.notebook, 0, 4, 2, 3, xpadding=5, ypadding=5)
1229
1230 # Create and add the status bar to the bottom of the main window
1231 self.statusBar = gtk.Statusbar()
1232 self.statusBar.set_has_resize_grip(True)
1233 self.updateStatusBar("New Config File [*]")
1234 self.table.attach(self.statusBar, 0, 4, 3, 4)
1235
1236 self.add(self.table)
1237
1238 self.show_all()
1239
1240 # Create our property dictionary. This holds the widgets which correspond to each property
1241 self.propUI = {
1242 "panel_monitor": self.panelMonitor,
1243 "panel_position": (self.panelPosY, self.panelPosX, self.panelOrientation),
1244 "panel_size": (self.panelSizeX, self.panelSizeY),
1245 "panel_margin": (self.panelMarginX, self.panelMarginY),
1246 "panel_padding": (self.panelPadX, self.panelPadY),
1247 "wm_menu": self.panelMenu,
1248 "panel_dock": self.panelDock,
1249 "panel_background_id": self.panelBg,
1250 "taskbar_mode": self.taskbarMode,
1251 "taskbar_padding": (self.taskbarPadX, self.taskbarPadY, self.taskbarSpacing),
1252 "taskbar_background_id": self.taskbarBg,
1253 "taskbar_active_background_id": self.taskbarActiveBg,
1254 "task_icon": self.taskIconCheckButton,
1255 "task_text": self.taskTextCheckButton,
1256 "task_centered": self.taskCentreCheckButton,
1257 "task_maximum_size": (self.taskMaxSizeX, self.taskMaxSizeY),
1258 "task_padding": (self.taskPadX, self.taskPadY),
1259 "task_background_id": self.taskBg,
1260 "task_active_background_id": self.taskActiveBg,
1261 "task_font": self.fontButton,
1262 "task_font_color": (self.fontCol, self.fontColButton),
1263 "task_active_font_color": (self.fontActiveCol, self.fontActiveColButton),
1264 "task_icon_asb": (self.iconHue, self.iconSat, self.iconBri),
1265 "task_active_icon_asb": (self.activeIconHue, self.activeIconSat, self.activeIconBri),
1266 "font_shadow": self.fontShadowCheckButton,
1267 "systray_padding": (self.trayPadX, self.trayPadY, self.traySpacing),
1268 "systray_background_id": self.trayBg,
1269 "systray_sort": self.trayOrder,
1270 "time1_format": self.clock1Format,
1271 "time2_format": self.clock2Format,
1272 "time1_font": self.clock1FontButton,
1273 "time2_font": self.clock2FontButton,
1274 "clock_font_color": (self.clockFontCol, self.clockFontColButton),
1275 "clock_padding": (self.clockPadX, self.clockPadY),
1276 "clock_background_id": self.clockBg,
1277 "clock_lclick_command": self.clockLClick,
1278 "clock_rclick_command": self.clockRClick,
1279 "mouse_middle": self.mouseMiddle,
1280 "mouse_right": self.mouseRight,
1281 "mouse_scroll_up": self.mouseUp,
1282 "mouse_scroll_down": self.mouseDown,
1283 "tooltip": self.tooltipShow,
1284 "tooltip_padding": (self.tooltipPadX, self.tooltipPadY),
1285 "tooltip_show_timeout": self.tooltipShowTime,
1286 "tooltip_hide_timeout": self.tooltipHideTime,
1287 "tooltip_background_id": self.tooltipBg,
1288 "tooltip_font": self.tooltipFont,
1289 "tooltip_font_color": (self.tooltipFontCol, self.tooltipFontColButton),
1290 "battery": self.batteryCheckButton,
1291 "battery_low_status": self.batteryLow,
1292 "battery_low_cmd": self.batteryLowAction,
1293 "bat1_font": self.bat1FontButton,
1294 "bat2_font": self.bat2FontButton,
1295 "battery_font_color": (self.batteryFontCol, self.batteryFontColButton),
1296 "battery_padding": (self.batteryPadX, self.batteryPadY),
1297 "battery_background_id": self.batteryBg
1298 }
1299
1300 if self.oneConfigFile:
1301 self.readTint2Config()
1302
1303 self.generateConfig()
1304
1305 def about(self, action=None):
1306 """Displays the About dialog."""
1307 about = gtk.AboutDialog()
1308 about.set_program_name(NAME)
1309 about.set_version(VERSION)
1310 about.set_authors(AUTHORS)
1311 about.set_comments(COMMENTS)
1312 about.set_website(WEBSITE)
1313 gtk.about_dialog_set_url_hook(self.aboutLinkCallback)
1314 about.run()
1315 about.destroy()
1316
1317 def aboutLinkCallback(dialog, link, data=None):
1318 """Callback for when a URL is clicked in an About dialog."""
1319 try:
1320 webbrowser.open(link)
1321 except:
1322 errorDialog(self, "Your default web-browser could not be opened.\nPlease visit %s" % link)
1323
1324 def addBg(self):
1325 """Adds a new background to the list of backgrounds."""
1326 self.bgs += [gtk.Table(4, 3, False)]
1327
1328 temp = gtk.Label("Corner Rounding (px)")
1329 temp.set_alignment(0, 0.5)
1330 self.bgs[-1].attach(temp, 0, 1, 0, 1, xpadding=10)
1331 temp = gtk.Entry(7)
1332 temp.set_width_chars(9)
1333 temp.set_name("rounded")
1334 temp.set_text(BG_ROUNDING)
1335 temp.connect("changed", self.changeOccurred)
1336 self.bgs[-1].attach(temp, 1, 2, 0, 1, xoptions=gtk.EXPAND)
1337
1338 temp = gtk.Label("Background Color")
1339 temp.set_alignment(0, 0.5)
1340 self.bgs[-1].attach(temp, 0, 1, 1, 2, xpadding=10)
1341 temp = gtk.Entry(7)
1342 temp.set_width_chars(9)
1343 temp.set_name("bgColEntry")
1344 temp.set_text(self.defaults["bgColor"])
1345 temp.connect("changed", self.changeOccurred)
1346 temp.connect("activate", self.colorTyped)
1347 self.bgs[-1].attach(temp, 1, 2, 1, 2, xoptions=gtk.EXPAND)
1348 temp = gtk.ColorButton(gtk.gdk.color_parse(self.defaults["bgColor"]))
1349 temp.set_use_alpha(True)
1350 temp.set_name("bgCol")
1351 temp.connect("color-set", self.colorChange)
1352 self.bgs[-1].attach(temp, 2, 3, 1, 2, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1353
1354 temp = gtk.Label("Border Width (px)")
1355 temp.set_alignment(0, 0.5)
1356 self.bgs[-1].attach(temp, 0, 1, 2, 3, xpadding=10)
1357 temp = gtk.Entry(7)
1358 temp.set_width_chars(9)
1359 temp.set_name("border")
1360 temp.set_text(BG_BORDER)
1361 temp.connect("changed", self.changeOccurred)
1362 self.bgs[-1].attach(temp, 1, 2, 2, 3, xoptions=gtk.EXPAND)
1363
1364 temp = gtk.Label("Border Color")
1365 temp.set_alignment(0, 0.5)
1366 self.bgs[-1].attach(temp, 0, 1, 3, 4, xpadding=10)
1367 temp = gtk.Entry(7)
1368 temp.set_width_chars(9)
1369 temp.set_name("borderColEntry")
1370 temp.connect("activate", self.colorTyped)
1371 temp.set_text(self.defaults["borderColor"])
1372 temp.connect("changed", self.changeOccurred)
1373 self.bgs[-1].attach(temp, 1, 2, 3, 4, xoptions=gtk.EXPAND)
1374 temp = gtk.ColorButton(gtk.gdk.color_parse(self.defaults["borderColor"]))
1375 temp.set_use_alpha(True)
1376 temp.set_name("borderCol")
1377 temp.connect("color-set", self.colorChange)
1378 self.bgs[-1].attach(temp, 2, 3, 3, 4, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND)
1379
1380 # Note: Only set init to True when initialising background styles.
1381 # This prevents unwanted calls to changeOccurred()
1382 def addBgClick(self, widget=None, init=False):
1383 """Creates a new background and adds a new tab to the notebook."""
1384 n = self.bgNotebook.get_n_pages()
1385
1386 if n > (self.defaults["bgCount"] + 2):
1387 if confirmDialog(self, "You already have %d background styles. Are you sure you would like another?" % n) == gtk.RESPONSE_NO:
1388 return
1389
1390 self.addBg()
1391
1392 newId = len(self.bgs)
1393
1394 self.bgNotebook.append_page(self.bgs[newId-1], gtk.Label("Background ID %d" % (newId)))
1395
1396 self.bgNotebook.show_all()
1397
1398 self.updateComboBoxes(n, "add")
1399
1400 self.bgNotebook.set_current_page(n)
1401
1402 if not init:
1403 self.changeOccurred()
1404
1405 def apply(self, widget, event=None, confirmChange=True):
1406 """Applies the current config to tint2."""
1407 if confirmDialog(self, "This will terminate all currently running instances of tint2 before applying config. Continue?") == gtk.RESPONSE_YES:
1408 if not self.save():
1409 return
1410
1411 #shutil.copyfile(self.filename, self.filename+".backup") # Create backup
1412
1413 # Check if tint2 is running
1414 procs = os.popen('pidof "tint2"') # Check list of active processes for tint2
1415 pids = [] # List of process ids for tint2
1416
1417 for proc in procs.readlines():
1418 pids += [int(proc.strip().split(" ")[0])]
1419
1420 procs.close()
1421
1422 # If it is - kill it
1423 for pid in pids:
1424 os.kill(pid, signal.SIGTERM)
1425
1426 # Lastly, start it
1427 os.spawnv(os.P_NOWAIT, self.tint2Bin, [self.tint2Bin, "-c" + self.filename])
1428
1429 if confirmChange and self.filename != (os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc") and confirmDialog(self, "Use this as default tint2 config?") == gtk.RESPONSE_YES:
1430 tmp = self.filename
1431 self.filename = os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc"
1432 try:
1433 shutil.copyfile(tmp, self.filename)
1434 except shutil.Error:
1435 pass
1436
1437 #if confirmChange and confirmDialog(self, "Keep this config?") == gtk.RESPONSE_NO:
1438 # shutil.copyfile(self.filename+".backup", self.filename) # Create backup
1439 # self.apply(widget, event, False)
1440
1441 def changeAllFonts(self, widget):
1442 """Changes all fonts at once."""
1443 dialog = gtk.FontSelectionDialog("Select Font")
1444
1445 dialog.set_font_name(self.defaults["font"])
1446
1447 if dialog.run() == gtk.RESPONSE_OK:
1448 newFont = dialog.get_font_name()
1449
1450 self.clock1FontButton.set_font_name(newFont)
1451 self.clock2FontButton.set_font_name(newFont)
1452 self.bat1FontButton.set_font_name(newFont)
1453 self.bat2FontButton.set_font_name(newFont)
1454 self.fontButton.set_font_name(newFont)
1455
1456 dialog.destroy()
1457
1458 self.generateConfig()
1459 self.changeOccurred()
1460
1461 def changeDefaults(self, widget=None):
1462 """Shows the style preferences widget."""
1463 TintWizardPrefGUI(self)
1464
1465 def changeOccurred(self, widget=None):
1466 """Called when the user changes something, i.e. entry value"""
1467 self.toSave = True
1468
1469 self.updateStatusBar(change=True)
1470
1471 if widget == self.panelOrientation:
1472 if self.panelOrientation.get_active_text() == "horizontal":
1473 self.panelSizeLabel.set_text("Size (width, height)")
1474 else:
1475 self.panelSizeLabel.set_text("Size (height, width)")
1476
1477 def colorChange(self, widget):
1478 """Update the text entry when a color button is updated."""
1479 r = widget.get_color().red
1480 g = widget.get_color().green
1481 b = widget.get_color().blue
1482
1483 label = self.getColorLabel(widget)
1484
1485 # No label found
1486 if not label:
1487 return
1488
1489 label.set_text(rgbToHex(r, g, b))
1490
1491 self.changeOccurred()
1492
1493 def colorTyped(self, widget):
1494 """Update the color button when a valid value is typed into the entry."""
1495 s = widget.get_text()
1496
1497 # The color button associated with this widget.
1498 colorButton = self.getColorButton(widget)
1499
1500 # Just a precautionary check - this situation should never arise.
1501 if not colorButton:
1502 #print "Error in colorTyped() -- unrecognised entry widget."
1503 return
1504
1505 # If the entered value is invalid, set textbox to the current
1506 # hex value of the associated color button.
1507 buttonHex = self.getHexFromWidget(colorButton)
1508
1509 if len(s) != 7:
1510 errorDialog(self, "Invalid color specification!")
1511 #self.colorChange(widget) TODO - remove this when issue 29 is verified
1512 widget.set_text(buttonHex)
1513 return
1514
1515 if not self.oneConfigFile:
1516 try:
1517 col = gtk.gdk.Color(s)
1518 except:
1519 errorDialog(self, "Invalid color specification!")
1520 #self.colorChange(widget) TODO - remove this when issue 29 is verified
1521 widget.set_text(buttonHex)
1522 return
1523
1524 colorButton.set_color(col)
1525
1526 # Note: only set init to True when removing backgrounds for a new config
1527 # This prevents unwanted calls to changeOccurred()
1528 def delBgClick(self, widget=None, prompt=True, init=False):
1529 """Deletes the selected background after confirming with the user."""
1530 selected = self.bgNotebook.get_current_page()
1531
1532 if selected == -1: # Nothing to remove
1533 return
1534
1535 if prompt:
1536 if confirmDialog(self, "Remove this background?") != gtk.RESPONSE_YES:
1537 return
1538
1539 self.bgNotebook.remove_page(selected)
1540 self.bgs.pop(selected)
1541
1542 for i in range(self.bgNotebook.get_n_pages()):
1543 self.bgNotebook.set_tab_label_text(self.bgNotebook.get_nth_page(i), "Background ID %d" % (i+1))
1544
1545 self.bgNotebook.show_all()
1546
1547 self.updateComboBoxes(len(self.bgs) + 1, "remove")
1548
1549 if not init:
1550 self.changeOccurred()
1551
1552 def generateConfig(self):
1553 """Reads values from each widget and generates a config."""
1554 self.configBuf.delete(self.configBuf.get_start_iter(), self.configBuf.get_end_iter())
1555 self.configBuf.insert(self.configBuf.get_end_iter(), "# Tint2 config file\n")
1556 self.configBuf.insert(self.configBuf.get_end_iter(), "# Generated by tintwizard (http://code.google.com/p/tintwizard/)\n")
1557 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# For information on manually configuring tint2 see http://code.google.com/p/tint2/wiki/Configure\n")
1558 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# To use this as default tint2 config: save as $HOME/.config/tint2/tint2rc\n\n")
1559
1560 self.configBuf.insert(self.configBuf.get_end_iter(), "# Background definitions\n")
1561 for i in range(len(self.bgs)):
1562 self.configBuf.insert(self.configBuf.get_end_iter(), "# ID %d\n" % (i + 1))
1563
1564 for child in self.bgs[i].get_children():
1565 if child.get_name() == "rounded":
1566 rounded = child.get_text() if child.get_text() else BG_ROUNDING
1567 elif child.get_name() == "border":
1568 borderW = child.get_text() if child.get_text() else BG_BORDER
1569 elif child.get_name() == "bgCol":
1570 bgCol = self.getHexFromWidget(child)
1571 bgAlpha = int(child.get_alpha() / 65535.0 * 100)
1572 elif child.get_name() == "borderCol":
1573 borderCol = self.getHexFromWidget(child)
1574 borderAlpha = int(child.get_alpha() / 65535.0 * 100)
1575
1576 self.configBuf.insert(self.configBuf.get_end_iter(), "rounded = %s\n" % (rounded))
1577 self.configBuf.insert(self.configBuf.get_end_iter(), "border_width = %s\n" % (borderW))
1578 self.configBuf.insert(self.configBuf.get_end_iter(), "background_color = %s %d\n" % (bgCol, bgAlpha))
1579 self.configBuf.insert(self.configBuf.get_end_iter(), "border_color = %s %d\n\n" % (borderCol, borderAlpha))
1580
1581 self.configBuf.insert(self.configBuf.get_end_iter(), "# Panel\n")
1582 self.configBuf.insert(self.configBuf.get_end_iter(), "panel_monitor = %s\n" % (self.panelMonitor.get_text() if self.panelMonitor.get_text() else PANEL_MONITOR))
1583 self.configBuf.insert(self.configBuf.get_end_iter(), "panel_position = %s %s %s\n" % (self.panelPosY.get_active_text(), self.panelPosX.get_active_text(), self.panelOrientation.get_active_text()))
1584 self.configBuf.insert(self.configBuf.get_end_iter(), "panel_size = %s %s\n" % (self.panelSizeX.get_text() if self.panelSizeX.get_text() else PANEL_SIZE_X,
1585 self.panelSizeY.get_text() if self.panelSizeY.get_text() else PANEL_SIZE_Y))
1586 self.configBuf.insert(self.configBuf.get_end_iter(), "panel_margin = %s %s\n" % (self.panelMarginX.get_text() if self.panelMarginX.get_text() else PANEL_MARGIN_X,
1587 self.panelMarginY.get_text() if self.panelMarginY.get_text() else PANEL_MARGIN_Y))
1588 self.configBuf.insert(self.configBuf.get_end_iter(), "panel_padding = %s %s\n" % (self.panelPadX.get_text() if self.panelPadX.get_text() else PANEL_PADDING_X,
1589 self.panelPadY.get_text() if self.panelPadY.get_text() else PANEL_PADDING_Y))
1590 self.configBuf.insert(self.configBuf.get_end_iter(), "panel_dock = %s\n" % int(self.panelDock.get_active()))
1591 self.configBuf.insert(self.configBuf.get_end_iter(), "wm_menu = %s\n" % int(self.panelMenu.get_active()))
1592 self.configBuf.insert(self.configBuf.get_end_iter(), "panel_background_id = %s\n" % (self.panelBg.get_active()))
1593
1594 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# Taskbar\n")
1595 self.configBuf.insert(self.configBuf.get_end_iter(), "taskbar_mode = %s\n" % (self.taskbarMode.get_active_text()))
1596 self.configBuf.insert(self.configBuf.get_end_iter(), "taskbar_padding = %s %s %s\n" % (self.taskbarPadX.get_text() if self.taskbarPadX.get_text() else TASKBAR_PADDING_X,
1597 self.taskbarPadY.get_text() if self.taskbarPadY.get_text() else TASKBAR_PADDING_X,
1598 self.taskbarSpacing.get_text() if self.taskbarSpacing.get_text() else TASK_SPACING))
1599 self.configBuf.insert(self.configBuf.get_end_iter(), "taskbar_background_id = %s\n" % (self.taskbarBg.get_active()))
1600 # Comment out the taskbar_active_background_id if user has "disabled" it
1601 if self.taskbarActiveBgEnable.get_active() == 0:
1602 self.configBuf.insert(self.configBuf.get_end_iter(), "#")
1603 self.configBuf.insert(self.configBuf.get_end_iter(), "taskbar_active_background_id = %s\n" % (self.taskbarActiveBg.get_active()))
1604
1605 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# Tasks\n")
1606 self.configBuf.insert(self.configBuf.get_end_iter(), "urgent_nb_of_blink = %s\n" % (self.taskBlinks.get_text() if self.taskBlinks.get_text() else TASK_BLINKS))
1607 self.configBuf.insert(self.configBuf.get_end_iter(), "task_icon = %s\n" % int(self.taskIconCheckButton.get_active()))
1608 self.configBuf.insert(self.configBuf.get_end_iter(), "task_text = %s\n" % int(self.taskTextCheckButton.get_active()))
1609 self.configBuf.insert(self.configBuf.get_end_iter(), "task_centered = %s\n" % int(self.taskCentreCheckButton.get_active()))
1610 self.configBuf.insert(self.configBuf.get_end_iter(), "task_maximum_size = %s %s\n" % (self.taskMaxSizeX.get_text() if self.taskMaxSizeX.get_text() else TASK_MAXIMUM_SIZE_X, self.taskMaxSizeY.get_text() if self.taskMaxSizeY.get_text() else TASK_MAXIMUM_SIZE_Y))
1611 self.configBuf.insert(self.configBuf.get_end_iter(), "task_padding = %s %s\n" % (self.taskPadX.get_text() if self.taskPadX.get_text() else TASK_PADDING_X,
1612 self.taskPadY.get_text() if self.taskPadY.get_text() else TASK_PADDING_Y))
1613 self.configBuf.insert(self.configBuf.get_end_iter(), "task_background_id = %s\n" % (self.taskBg.get_active()))
1614 self.configBuf.insert(self.configBuf.get_end_iter(), "task_active_background_id = %s\n" % (self.taskActiveBg.get_active()))
1615 self.configBuf.insert(self.configBuf.get_end_iter(), "task_icon_asb = %s %s %s\n" % (self.iconHue.get_text() if self.iconHue.get_text() else ICON_ALPHA,
1616 self.iconSat.get_text() if self.iconSat.get_text() else ICON_SAT,
1617 self.iconBri.get_text() if self.iconBri.get_text() else ICON_BRI))
1618 self.configBuf.insert(self.configBuf.get_end_iter(), "task_active_icon_asb = %s %s %s\n" % (self.activeIconHue.get_text() if self.activeIconHue.get_text() else ACTIVE_ICON_ALPHA,
1619 self.activeIconSat.get_text() if self.activeIconSat.get_text() else ACTIVE_ICON_SAT,
1620 self.activeIconBri.get_text() if self.activeIconBri.get_text() else ACTIVE_ICON_BRI))
1621
1622 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# Fonts\n")
1623 self.configBuf.insert(self.configBuf.get_end_iter(), "task_font = %s\n" % (self.fontButton.get_font_name()))
1624 self.configBuf.insert(self.configBuf.get_end_iter(), "task_font_color = %s %s\n" % (self.getHexFromWidget(self.fontColButton),
1625 int(self.fontColButton.get_alpha() / 65535.0 * 100)))
1626 self.configBuf.insert(self.configBuf.get_end_iter(), "task_active_font_color = %s %s\n" % (self.getHexFromWidget(self.fontActiveColButton),
1627 int(self.fontActiveColButton.get_alpha() / 65535.0 * 100)))
1628 self.configBuf.insert(self.configBuf.get_end_iter(), "font_shadow = %s\n" % int(self.fontShadowCheckButton.get_active()))
1629
1630 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# Systray")
1631 if not self.trayCheckButton.get_active():
1632 self.configBuf.insert(self.configBuf.get_end_iter(), " - DISABLED\n#")
1633 else:
1634 self.configBuf.insert(self.configBuf.get_end_iter(), "\n")
1635 self.configBuf.insert(self.configBuf.get_end_iter(), "systray_padding = %s %s %s\n" % (self.trayPadX.get_text() if self.trayPadX.get_text() else TRAY_PADDING_X,
1636 self.trayPadY.get_text() if self.trayPadY.get_text() else TRAY_PADDING_Y,
1637 self.traySpacing.get_text() if self.traySpacing.get_text() else TRAY_SPACING))
1638 self.configBuf.insert(self.configBuf.get_end_iter(), "systray_sort = %s\n" % (self.trayOrder.get_active_text()))
1639 self.configBuf.insert(self.configBuf.get_end_iter(), "systray_background_id = %s\n" % (self.trayBg.get_active()))
1640
1641 if self.clockCheckButton.get_active():
1642 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# Clock\n")
1643 if self.clock1CheckButton.get_active():
1644 self.configBuf.insert(self.configBuf.get_end_iter(), "time1_format = %s\n" % (self.clock1Format.get_text() if self.clock1Format.get_text() else CLOCK_FMT_1))
1645 self.configBuf.insert(self.configBuf.get_end_iter(), "time1_font = %s\n" % (self.clock1FontButton.get_font_name()))
1646 if self.clock2CheckButton.get_active():
1647 self.configBuf.insert(self.configBuf.get_end_iter(), "time2_format = %s\n" % (self.clock2Format.get_text() if self.clock2Format.get_text() else CLOCK_FMT_2))
1648 self.configBuf.insert(self.configBuf.get_end_iter(), "time2_font = %s\n" % (self.clock2FontButton.get_font_name()))
1649 self.configBuf.insert(self.configBuf.get_end_iter(), "clock_font_color = %s %s\n" % (self.getHexFromWidget(self.clockFontColButton),
1650 int(self.clockFontColButton.get_alpha() / 65535.0 * 100)))
1651 self.configBuf.insert(self.configBuf.get_end_iter(), "clock_padding = %s %s\n" % (self.clockPadX.get_text() if self.clockPadX.get_text() else CLOCK_PADDING_X,
1652 self.clockPadY.get_text() if self.clockPadY.get_text() else CLOCK_PADDING_Y))
1653 self.configBuf.insert(self.configBuf.get_end_iter(), "clock_background_id = %s\n" % (self.clockBg.get_active()))
1654 if self.clockLClick.get_text():
1655 self.configBuf.insert(self.configBuf.get_end_iter(), "clock_lclick_command = %s\n" % (self.clockLClick.get_text()))
1656 if self.clockRClick.get_text():
1657 self.configBuf.insert(self.configBuf.get_end_iter(), "clock_rclick_command = %s\n" % (self.clockRClick.get_text()))
1658
1659 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# Tooltips\n")
1660 self.configBuf.insert(self.configBuf.get_end_iter(), "tooltip = %s\n" % int(self.tooltipShow.get_active()))
1661 self.configBuf.insert(self.configBuf.get_end_iter(), "tooltip_padding = %s %s\n" % (self.tooltipPadX.get_text() if self.tooltipPadX.get_text() else TOOLTIP_PADDING_Y,
1662 self.tooltipPadY.get_text() if self.tooltipPadY.get_text() else TOOLTIP_PADDING_Y))
1663 self.configBuf.insert(self.configBuf.get_end_iter(), "tooltip_show_timeout = %s\n" % (self.tooltipShowTime.get_text() if self.tooltipShowTime.get_text() else TOOLTIP_SHOW_TIMEOUT))
1664 self.configBuf.insert(self.configBuf.get_end_iter(), "tooltip_hide_timeout = %s\n" % (self.tooltipHideTime.get_text() if self.tooltipHideTime.get_text() else TOOLTIP_HIDE_TIMEOUT))
1665 self.configBuf.insert(self.configBuf.get_end_iter(), "tooltip_background_id = %s\n" % (self.tooltipBg.get_active()))
1666 self.configBuf.insert(self.configBuf.get_end_iter(), "tooltip_font = %s\n" % (self.tooltipFont.get_font_name()))
1667 self.configBuf.insert(self.configBuf.get_end_iter(), "tooltip_font_color = %s %s\n" % (self.getHexFromWidget(self.tooltipFontColButton),
1668 int(self.tooltipFontColButton.get_alpha() / 65535.0 * 100)))
1669
1670 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# Mouse\n")
1671 self.configBuf.insert(self.configBuf.get_end_iter(), "mouse_middle = %s\n" % (self.mouseMiddle.get_active_text()))
1672 self.configBuf.insert(self.configBuf.get_end_iter(), "mouse_right = %s\n" % (self.mouseRight.get_active_text()))
1673 self.configBuf.insert(self.configBuf.get_end_iter(), "mouse_scroll_up = %s\n" % (self.mouseUp.get_active_text()))
1674 self.configBuf.insert(self.configBuf.get_end_iter(), "mouse_scroll_down = %s\n" % (self.mouseDown.get_active_text()))
1675
1676 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# Battery\n")
1677 self.configBuf.insert(self.configBuf.get_end_iter(), "battery = %s\n" % int(self.batteryCheckButton.get_active()))
1678 self.configBuf.insert(self.configBuf.get_end_iter(), "battery_low_status = %s\n" % (self.batteryLow.get_text() if self.batteryLow.get_text() else BATTERY_LOW))
1679 self.configBuf.insert(self.configBuf.get_end_iter(), "battery_low_cmd = %s\n" % (self.batteryLowAction.get_text() if self.batteryLowAction.get_text() else BATTERY_ACTION))
1680 self.configBuf.insert(self.configBuf.get_end_iter(), "bat1_font = %s\n" % (self.bat1FontButton.get_font_name()))
1681 self.configBuf.insert(self.configBuf.get_end_iter(), "bat2_font = %s\n" % (self.bat2FontButton.get_font_name()))
1682 self.configBuf.insert(self.configBuf.get_end_iter(), "battery_font_color = %s %s\n" % (self.getHexFromWidget(self.batteryFontColButton),
1683 int(self.batteryFontColButton.get_alpha() / 65535.0 * 100)))
1684 self.configBuf.insert(self.configBuf.get_end_iter(), "battery_padding = %s %s\n" % (self.batteryPadX.get_text() if self.batteryPadX.get_text() else BATTERY_PADDING_Y,
1685 self.batteryPadY.get_text() if self.batteryPadY.get_text() else BATTERY_PADDING_Y))
1686 self.configBuf.insert(self.configBuf.get_end_iter(), "battery_background_id = %s\n" % (self.batteryBg.get_active()))
1687
1688 self.configBuf.insert(self.configBuf.get_end_iter(), "\n# End of config")
1689
1690 def getColorButton(self, widget):
1691 """Returns the color button associated with widget."""
1692 if widget.get_name() == "fontCol":
1693 return self.fontColButton
1694 elif widget.get_name() == "fontActiveCol":
1695 return self.fontActiveColButton
1696 elif widget.get_name() == "clockFontCol":
1697 return self.clockFontColButton
1698 elif widget.get_name() == "batteryFontCol":
1699 return self.batteryFontColButton
1700 elif widget.get_name() == "tooltipFontCol":
1701 return self.tooltipFontColButton
1702 elif widget.get_name() == "bgColEntry":
1703 bgID = self.bgNotebook.get_current_page()
1704
1705 for child in self.bgs[bgID].get_children():
1706 if child.get_name() == "bgCol":
1707
1708 return child
1709 elif widget.get_name() == "borderColEntry":
1710 bgID = self.bgNotebook.get_current_page()
1711
1712 for child in self.bgs[bgID].get_children():
1713 if child.get_name() == "borderCol":
1714
1715 return child
1716
1717 # No button found which matches label
1718 return None
1719
1720 def getColorLabel(self, widget):
1721 """Gets the color label associated with a color button."""
1722 if widget.get_name() == "fontCol":
1723 return self.fontCol
1724 elif widget.get_name() == "fontActiveCol":
1725 return self.fontActiveCol
1726 elif widget.get_name() == "clockFontCol":
1727 return self.clockFontCol
1728 elif widget.get_name() == "batteryFontCol":
1729 return self.batteryFontCol
1730 elif widget.get_name() == "tooltipFontCol":
1731 return self.tooltipFontCol
1732 elif widget.get_name() == "bgCol":
1733 bgID = self.bgNotebook.get_current_page()
1734
1735 for child in self.bgs[bgID].get_children():
1736 if child.get_name() == "bgColEntry":
1737
1738 return child
1739 elif widget.get_name() == "borderCol":
1740 bgID = self.bgNotebook.get_current_page()
1741
1742 for child in self.bgs[bgID].get_children():
1743 if child.get_name() == "borderColEntry":
1744
1745 return child
1746
1747 # No label found which matches color button
1748 return None
1749
1750 def getHexFromWidget(self, widget):
1751 """Returns the #RRGGBB value of a widget."""
1752 r = widget.get_color().red
1753 g = widget.get_color().green
1754 b = widget.get_color().blue
1755
1756 return rgbToHex(r, g, b)
1757
1758 def help(self, action=None):
1759 """Opens the Help wiki page in the default web browser."""
1760 try:
1761 webbrowser.open("http://code.google.com/p/tintwizard/wiki/Help")
1762 except:
1763 errorDialog(self, "Your default web-browser could not be opened.\nPlease visit http://code.google.com/p/tintwizard/wiki/Help")
1764
1765 def reportBug(self, action=None):
1766 """Opens the bug report page in the default web browser."""
1767 try:
1768 webbrowser.open("http://code.google.com/p/tintwizard/issues/entry")
1769 except:
1770 errorDialog(self, "Your default web-browser could not be opened.\nPlease visit http://code.google.com/p/tintwizard/issues/entry")
1771
1772 def main(self):
1773 """Enters the main loop."""
1774 gtk.main()
1775
1776 def resetConfig(self):
1777 """Resets all the widgets to their default values."""
1778 # Backgrounds
1779 for i in range(len(self.bgs)):
1780 self.delBgClick(prompt=False, init=True)
1781
1782 for i in range(self.defaults["bgCount"]):
1783 self.addBgClick(init=True)
1784
1785 self.bgNotebook.set_current_page(0)
1786
1787 # Panel
1788 self.panelPosY.set_active(0)
1789 self.panelPosX.set_active(0)
1790 self.panelOrientation.set_active(0)
1791 self.panelSizeX.set_text(PANEL_SIZE_X)
1792 self.panelSizeY.set_text(PANEL_SIZE_Y)
1793 self.panelMarginX.set_text(PANEL_MARGIN_X)
1794 self.panelMarginY.set_text(PANEL_MARGIN_Y)
1795 self.panelPadX.set_text(PANEL_PADDING_Y)
1796 self.panelPadY.set_text(PANEL_PADDING_Y)
1797 self.panelBg.set_active(0)
1798 self.panelMenu.set_active(0)
1799 self.panelDock.set_active(0)
1800 self.panelMonitor.set_text(PANEL_MONITOR)
1801 # Taskbar
1802 self.taskbarMode.set_active(0)
1803 self.taskbarPadX.set_text(TASKBAR_PADDING_X)
1804 self.taskbarPadY.set_text(TASKBAR_PADDING_Y)
1805 self.taskbarSpacing.set_text(TASK_SPACING)
1806 self.taskbarBg.set_active(0)
1807 self.taskbarActiveBg.set_active(0)
1808 self.taskbarActiveBgEnable.set_active(0)
1809 # Tasks
1810 self.taskBlinks.set_text(TASK_BLINKS)
1811 self.taskCentreCheckButton.set_active(True)
1812 self.taskTextCheckButton.set_active(True)
1813 self.taskIconCheckButton.set_active(True)
1814 self.taskMaxSizeX.set_text(TASK_MAXIMUM_SIZE_X)
1815 self.taskMaxSizeY.set_text(TASK_MAXIMUM_SIZE_Y)
1816 self.taskPadX.set_text(TASK_PADDING_X)
1817 self.taskPadY.set_text(TASK_PADDING_Y)
1818 self.taskBg.set_active(0)
1819 self.taskActiveBg.set_active(0)
1820 # Icons
1821 self.iconHue.set_text(ICON_ALPHA)
1822 self.iconSat.set_text(ICON_SAT)
1823 self.iconBri.set_text(ICON_BRI)
1824 self.activeIconHue.set_text(ACTIVE_ICON_ALPHA)
1825 self.activeIconSat.set_text(ACTIVE_ICON_SAT)
1826 self.activeIconBri.set_text(ACTIVE_ICON_BRI)
1827 # Fonts
1828 self.fontButton.set_font_name(self.defaults["font"])
1829 self.fontColButton.set_alpha(65535)
1830 self.fontColButton.set_color(gtk.gdk.color_parse(self.defaults["fgColor"]))
1831 self.fontCol.set_text(self.defaults["fgColor"])
1832 self.fontActiveColButton.set_alpha(65535)
1833 self.fontActiveColButton.set_color(gtk.gdk.color_parse(self.defaults["fgColor"]))
1834 self.fontActiveCol.set_text(self.defaults["fgColor"])
1835 self.fontShadowCheckButton.set_active(False)
1836 # Systray
1837 self.trayCheckButton.set_active(True)
1838 self.trayPadX.set_text(TRAY_PADDING_X)
1839 self.trayPadY.set_text(TRAY_PADDING_X)
1840 self.traySpacing.set_text(TRAY_SPACING)
1841 self.trayOrder.set_active(0)
1842 self.trayBg.set_active(0)
1843 # Clock
1844 self.clockCheckButton.set_active(True)
1845 self.clock1Format.set_text(CLOCK_FMT_1)
1846 self.clock1CheckButton.set_active(True)
1847 self.clock1FontButton.set_font_name(self.defaults["font"])
1848 self.clock2Format.set_text(CLOCK_FMT_2)
1849 self.clock2CheckButton.set_active(True)
1850 self.clock2FontButton.set_font_name(self.defaults["font"])
1851 self.clockFontColButton.set_alpha(65535)
1852 self.clockFontColButton.set_color(gtk.gdk.color_parse(self.defaults["fgColor"]))
1853 self.clockFontCol.set_text(self.defaults["fgColor"])
1854 self.clockPadX.set_text(CLOCK_PADDING_X)
1855 self.clockPadY.set_text(CLOCK_PADDING_Y)
1856 self.clockBg.set_active(0)
1857 self.clockLClick.set_text(CLOCK_LCLICK)
1858 self.clockRClick.set_text(CLOCK_RCLICK)
1859 # Tooltips
1860 self.tooltipShow.set_active(False)
1861 self.tooltipPadX.set_text(TOOLTIP_PADDING_X)
1862 self.tooltipPadY.set_text(TOOLTIP_PADDING_Y)
1863 self.tooltipShowTime.set_text(TOOLTIP_SHOW_TIMEOUT)
1864 self.tooltipHideTime.set_text(TOOLTIP_HIDE_TIMEOUT)
1865 self.tooltipBg.set_active(0)
1866 self.tooltipFont.set_font_name(self.defaults["font"])
1867 self.tooltipFontColButton.set_alpha(65535)
1868 self.tooltipFontColButton.set_color(gtk.gdk.color_parse(self.defaults["fgColor"]))
1869 self.tooltipFontCol.set_text(self.defaults["fgColor"])
1870 # Mouse
1871 self.mouseMiddle.set_active(0)
1872 self.mouseRight.set_active(0)
1873 self.mouseUp.set_active(0)
1874 self.mouseDown.set_active(0)
1875 # Battery
1876 self.batteryCheckButton.set_active(False)
1877 self.batteryLow.set_text(BATTERY_LOW)
1878 self.batteryLowAction.set_text(BATTERY_ACTION)
1879 self.bat1FontButton.set_font_name(self.defaults["font"])
1880 self.bat2FontButton.set_font_name(self.defaults["font"])
1881 self.batteryFontColButton.set_alpha(65535)
1882 self.batteryFontColButton.set_color(gtk.gdk.color_parse(self.defaults["fgColor"]))
1883 self.batteryFontCol.set_text(self.defaults["fgColor"])
1884 self.batteryPadX.set_text(BATTERY_PADDING_Y)
1885 self.batteryPadY.set_text(BATTERY_PADDING_Y)
1886 self.batteryBg.set_active(0)
1887
1888 def new(self, action=None):
1889 """Prepares a new config."""
1890 if self.toSave:
1891 self.savePrompt()
1892
1893 self.toSave = True
1894 self.filename = None
1895
1896 self.resetConfig()
1897
1898 self.generateConfig()
1899 self.updateStatusBar("New Config File [*]")
1900
1901 def openDef(self, widget=None):
1902 """Opens the default tint2 config."""
1903 self.openFile(default=True)
1904
1905 def openFile(self, widget=None, default=False):
1906 """Reads from a config file. If default=True, open the tint2 default config."""
1907 self.new()
1908
1909 if not default:
1910 chooser = gtk.FileChooserDialog("Open Config File", self, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
1911 chooser.set_default_response(gtk.RESPONSE_OK)
1912
1913 if self.curDir != None:
1914 chooser.set_current_folder(self.curDir)
1915
1916 chooserFilter = gtk.FileFilter()
1917 chooserFilter.set_name("All files")
1918 chooserFilter.add_pattern("*")
1919 chooser.add_filter(chooserFilter)
1920 chooser.show()
1921
1922 response = chooser.run()
1923
1924 if response == gtk.RESPONSE_OK:
1925 self.filename = chooser.get_filename()
1926 self.curDir = os.path.dirname(self.filename)
1927 else:
1928 chooser.destroy()
1929 return
1930
1931 chooser.destroy()
1932 else:
1933 self.filename = os.path.expandvars("$HOME/.config/tint2/tint2rc")
1934 self.curDir = os.path.expandvars("$HOME/.config/tint2")
1935
1936 self.readTint2Config()
1937 self.generateConfig()
1938 self.updateStatusBar()
1939
1940 def addBgDefs(self, bgDefs):
1941 """Add interface elements for a list of background style definitions. bgDefs
1942 should be a list containing dictionaries with the following keys: rounded,
1943 border_width, background_color, border_color"""
1944 for d in bgDefs:
1945 self.addBg()
1946
1947 for child in self.bgs[-1].get_children():
1948 if child.get_name() == "rounded":
1949 child.set_text(d["rounded"])
1950 elif child.get_name() == "border":
1951 child.set_text(d["border_width"])
1952 elif child.get_name() == "bgColEntry":
1953 child.set_text(d["background_color"].split(" ")[0].strip())
1954 child.activate()
1955 elif child.get_name() == "borderColEntry":
1956 child.set_text(d["border_color"].split(" ")[0].strip())
1957 child.activate()
1958 elif child.get_name() == "bgCol":
1959 list = d["background_color"].split(" ")
1960 if len(list) > 1:
1961 child.set_alpha(int(int(list[1].strip()) * 65535 / 100.0))
1962 else:
1963 child.set_alpha(65535)
1964 elif child.get_name() == "borderCol":
1965 list = d["border_color"].split(" ")
1966 if len(list) > 1:
1967 child.set_alpha(int(int(list[1].strip()) * 65535 / 100.0))
1968 else:
1969 child.set_alpha(65535)
1970
1971 newId = len(self.bgs)
1972
1973 self.bgNotebook.append_page(self.bgs[newId-1], gtk.Label("Background ID %d" % (newId)))
1974
1975 self.bgNotebook.show_all()
1976
1977 self.updateComboBoxes(newId-1, "add")
1978
1979 self.bgNotebook.set_current_page(newId)
1980
1981 def parseBgs(self, string):
1982 """Parses the background definitions from a string."""
1983 s = string.split("\n")
1984
1985 bgDefs = []
1986 cur = -1
1987 bgKeys = ["border_width", "background_color", "border_color"]
1988 newString = ""
1989
1990 for line in s:
1991 data = [token.strip() for token in line.split("=")]
1992
1993 if data[0] == "rounded": # It may be considered bad practice to
1994 bgDefs += [{"rounded": data[1]}] # find each style definition with an
1995 elif data[0] in bgKeys: # arbitrary value, but tint2 does the same.
1996 bgDefs[cur][data[0]] = data[1] # This means that any existing configs must
1997 else: # start with 'rounded'.
1998 newString += "%s\n" % line
1999
2000 self.addBgDefs(bgDefs)
2001
2002 return newString
2003
2004 def parseConfig(self, string):
2005 """Parses the contents of a config file."""
2006 for line in string.split("\n"):
2007 s = line.split("=") # Create a list with KEY and VALUE
2008
2009 e = s[0].strip() # Strip whitespace from KEY
2010
2011 if e == "time1_format": # Set the VALUE of KEY
2012 self.parseProp(self.propUI[e], s[1], True, "time1")
2013 elif e == "time2_format":
2014 self.parseProp(self.propUI[e], s[1], True, "time2")
2015 elif e == "systray_padding":
2016 self.parseProp(self.propUI[e], s[1], True, "tray")
2017 elif e == "taskbar_active_background_id":
2018 self.parseProp(self.propUI[e], s[1], True, "activeBg")
2019 else:
2020 if self.propUI.has_key(e):
2021 self.parseProp(self.propUI[e], s[1])
2022
2023 def parseProp(self, prop, string, special=False, propType=""):
2024 """Parses a variable definition from the conf file and updates the correct UI widget."""
2025 string = string.strip() # Remove whitespace from the VALUE
2026 eType = type(prop) # Get widget type
2027
2028 if special: # 'Special' properties are those which are optional
2029 if propType == "time1":
2030 self.clockCheckButton.set_active(True)
2031 self.clock1CheckButton.set_active(True)
2032 elif propType == "time2":
2033 self.clockCheckButton.set_active(True)
2034 self.clock2CheckButton.set_active(True)
2035 elif propType == "tray":
2036 self.trayCheckButton.set_active(True)
2037 elif propType == "activeBg":
2038 self.taskbarActiveBgEnable.set_active(True)
2039
2040 if eType == gtk.Entry:
2041 prop.set_text(string)
2042 prop.activate()
2043 elif eType == gtk.ComboBox:
2044 if string in ["bottom", "top", "left", "right", "center", "single_desktop", "multi_desktop", "single_monitor",
2045 "none", "close", "shade", "iconify", "toggle", "toggle_iconify", "maximize_restore",
2046 "desktop_left", "desktop_right", "horizontal", "vertical", "ascending", "descending",
2047 "left2right", "right2left"]:
2048 if string in ["bottom", "left", "single_desktop", "none", "horizontal", "ascending"]:
2049 i = 0
2050 elif string in ["top", "right", "multi_desktop", "close", "vertical", "descending"]:
2051 i = 1
2052 elif string in ["center", "single_monitor", "toggle", "left2right"]:
2053 i = 2
2054 elif string in ["right2left"]:
2055 i = 3
2056 else:
2057 i = ["none", "close", "toggle", "iconify", "shade", "toggle_iconify", "maximize_restore",
2058 "desktop_left", "desktop_right"].index(string)
2059
2060 prop.set_active(i)
2061 else:
2062 prop.set_active(int(string))
2063 elif eType == gtk.CheckButton:
2064 prop.set_active(bool(int(string)))
2065 elif eType == gtk.FontButton:
2066 prop.set_font_name(string)
2067 elif eType == gtk.ColorButton:
2068 prop.set_alpha(int(int(string) * 65535 / 100.0))
2069 elif eType == tuple: # If a property has more than 1 value, for example the x and y co-ords
2070 s = string.split(" ") # of the padding properties, then just we use recursion to set the
2071 for i in range(len(prop)): # value of each associated widget.
2072 if i >= len(s):
2073 self.parseProp(prop[i], "0")
2074 else:
2075 self.parseProp(prop[i], s[i])
2076
2077 def quit(self, widget, event=None):
2078 """Asks if user would like to save file before quitting, then quits the program."""
2079 if self.toSave:
2080 if self.oneConfigFile:
2081 response = gtk.RESPONSE_YES
2082 else:
2083 dialog = gtk.Dialog("Save config?", self, gtk.DIALOG_MODAL, (gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
2084 dialog.get_content_area().add(gtk.Label("Save config before quitting?"))
2085 dialog.get_content_area().set_size_request(300, 100)
2086 dialog.show_all()
2087 response = dialog.run()
2088 dialog.destroy()
2089
2090 if response == gtk.RESPONSE_CANCEL:
2091 return True # Return True to stop it quitting when we hit "Cancel"
2092 elif response == gtk.RESPONSE_NO:
2093 gtk.main_quit()
2094 elif response == gtk.RESPONSE_YES:
2095 self.save()
2096 gtk.main_quit()
2097 else:
2098 gtk.main_quit()
2099
2100 def readConf(self):
2101 """Reads the tintwizard configuration file - NOT tint2 config files."""
2102 self.defaults = {"font": None, "bgColor": None, "fgColor": None, "borderColor": None, "bgCount": None, "dir": None}
2103
2104 if self.oneConfigFile:
2105 # don't need tintwizard.conf
2106 return
2107
2108 pathName = os.path.dirname(sys.argv[0])
2109
2110 if pathName != "":
2111 pathName += "/"
2112
2113 if not os.path.exists(pathName + "tintwizard.conf"):
2114 self.writeConf()
2115 return
2116
2117 f = open(pathName + "tintwizard.conf", "r")
2118
2119 for line in f:
2120 if "=" in line:
2121 l = line.split("=")
2122
2123 if self.defaults.has_key(l[0].strip()):
2124 self.defaults[l[0].strip()] = l[1].strip()
2125
2126 def readTint2Config(self):
2127 """Reads in from a config file."""
2128 f = open(self.filename, "r")
2129
2130 string = ""
2131
2132 for line in f:
2133 if (line[0] != "#") and (len(line) > 2):
2134 string += line
2135
2136 f.close()
2137
2138 # Deselect the optional stuff, and we'll re-check them if the config has them enabled
2139 self.clockCheckButton.set_active(False)
2140 self.clock1CheckButton.set_active(False)
2141 self.clock2CheckButton.set_active(False)
2142 self.trayCheckButton.set_active(False)
2143 self.taskbarActiveBgEnable.set_active(False)
2144
2145 # Remove all background styles so we can create new ones as we read them
2146 for i in range(len(self.bgs)):
2147 self.delBgClick(None, False)
2148
2149 # As we parse background definitions, we build a new string
2150 # without the background related stuff. This means we don't
2151 # have to read through background defs AGAIN when parsing
2152 # the other stuff.
2153 noBgDefs = self.parseBgs(string)
2154
2155 self.parseConfig(noBgDefs)
2156
2157 def save(self, widget=None, event=None):
2158 """Saves the generated config file."""
2159
2160 # This function returns the boolean status of whether or not the
2161 # file saved, so that the apply() function knows if it should
2162 # kill the tint2 process and apply the new config.
2163
2164 # If no file has been selected, force the user to "Save As..."
2165 if self.filename == None:
2166 return self.saveAs()
2167 else:
2168 self.generateConfig()
2169 self.writeFile()
2170
2171 return True
2172
2173 def saveAs(self, widget=None, event=None):
2174 """Prompts the user to select a file and then saves the generated config file."""
2175 self.generateConfig()
2176
2177 chooser = gtk.FileChooserDialog("Save Config File As...", self, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK))
2178 chooser.set_default_response(gtk.RESPONSE_OK)
2179
2180 if self.curDir != None:
2181 chooser.set_current_folder(self.curDir)
2182
2183 chooserFilter = gtk.FileFilter()
2184 chooserFilter.set_name("All files")
2185 chooserFilter.add_pattern("*")
2186 chooser.add_filter(chooserFilter)
2187 chooser.show()
2188
2189 response = chooser.run()
2190
2191 if response == gtk.RESPONSE_OK:
2192 self.filename = chooser.get_filename()
2193
2194 if os.path.exists(self.filename):
2195 overwrite = confirmDialog(self, "This file already exists. Overwrite this file?")
2196
2197 if overwrite == gtk.RESPONSE_YES:
2198 self.writeFile()
2199 chooser.destroy()
2200 return True
2201 else:
2202 self.filename = None
2203 chooser.destroy()
2204 return False
2205 else:
2206 self.writeFile()
2207 chooser.destroy()
2208 return True
2209 else:
2210 self.filename = None
2211 chooser.destroy()
2212 return False
2213
2214 def saveAsDef(self, widget=None, event=None):
2215 """Saves the config as the default tint2 config."""
2216 if confirmDialog(self, "Overwrite current tint2 default config?") == gtk.RESPONSE_YES:
2217 self.filename = os.path.expandvars("${HOME}") + "/.config/tint2/tint2rc"
2218 self.curDir = os.path.expandvars("${HOME}") + "/.config/tint2"
2219
2220 # If, for whatever reason, tint2 has no default config - create one.
2221 if not os.path.isfile(self.filename):
2222 f = open(self.filename, "w")
2223 f.write("# tint2rc")
2224 f.close()
2225
2226 self.generateConfig()
2227 self.writeFile()
2228
2229 return True
2230
2231 def savePrompt(self):
2232 """Prompt the user to save before creating a new file."""
2233 if confirmDialog(self, "Save current config?") == gtk.RESPONSE_YES:
2234 self.save(None)
2235
2236 def switchPage(self, notebook, page, page_num):
2237 """Handles notebook page switch events."""
2238
2239 # If user selects the 'View Config' tab, update the textarea within this tab.
2240 if notebook.get_tab_label_text(notebook.get_nth_page(page_num)) == "View Config":
2241 self.generateConfig()
2242
2243 def updateComboBoxes(self, i, action="add"):
2244 """Updates the contents of a combo box when a background style has been added/removed."""
2245 cbs = [self.batteryBg, self.clockBg, self.taskbarBg, self.taskbarActiveBg, self.trayBg, self.taskActiveBg, self.taskBg, self.panelBg, self.tooltipBg]
2246
2247 if action == "add":
2248 for cb in cbs:
2249 cb.append_text(str(i+1))
2250 else:
2251 for cb in cbs:
2252 if cb.get_active() == i: # If background is selected, set to a different value
2253 cb.set_active(0)
2254
2255 cb.remove_text(i)
2256
2257 def updateStatusBar(self, message="", change=False):
2258 """Updates the message on the statusbar. A message can be provided,
2259 and if change is set to True (i.e. something has been modified) then
2260 an appropriate symbol [*] is shown beside filename."""
2261 contextID = self.statusBar.get_context_id("")
2262
2263 self.statusBar.pop(contextID)
2264
2265 if not message:
2266 message = "%s %s" % (self.filename or "New Config File", "[*]" if change else "")
2267
2268 self.statusBar.push(contextID, message)
2269
2270 def writeConf(self):
2271 """Writes the tintwizard configuration file."""
2272 confStr = "#Start\n[defaults]\n"
2273
2274 for key in self.defaults:
2275 confStr += "%s = %s\n" % (key, str(self.defaults[key]))
2276
2277 confStr += "#End\n"
2278
2279 pathName = os.path.dirname(sys.argv[0])
2280
2281 if pathName == "":
2282 f = open("tintwizard.conf", "w")
2283 else:
2284 f = open(pathName+"/tintwizard.conf", "w")
2285
2286 f.write(confStr)
2287
2288 f.close()
2289
2290 def writeFile(self):
2291 """Writes the contents of the config text buffer to file."""
2292 try:
2293 f = open(self.filename, "w")
2294
2295 f.write(self.configBuf.get_text(self.configBuf.get_start_iter(), self.configBuf.get_end_iter()))
2296
2297 f.close()
2298
2299 self.toSave = False
2300
2301 self.curDir = os.path.dirname(self.filename)
2302
2303 self.updateStatusBar()
2304 except IOError:
2305 errorDialog(self, "Could not save file")
2306
2307 # General use functions
2308 def confirmDialog(parent, message):
2309 """Creates a confirmation dialog and returns the response."""
2310 dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, message)
2311 dialog.show()
2312 response = dialog.run()
2313 dialog.destroy()
2314 return response
2315
2316 def errorDialog(parent=None, message="An error has occured!"):
2317 """Creates an error dialog."""
2318 dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message)
2319 dialog.show()
2320 dialog.run()
2321 dialog.destroy()
2322
2323 def numToHex(n):
2324 """Convert integer n in range [0, 15] to hex."""
2325 try:
2326 return ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"][n]
2327 except:
2328 return -1
2329
2330 def rgbToHex(r, g, b):
2331 """Constructs a 6 digit hex representation of color (r, g, b)."""
2332 r2 = trunc(r / 65535.0 * 255)
2333 g2 = trunc(g / 65535.0 * 255)
2334 b2 = trunc(b / 65535.0 * 255)
2335
2336 return "#%s%s%s%s%s%s" % (numToHex(r2 / 16), numToHex(r2 % 16), numToHex(g2 / 16), numToHex(g2 % 16), numToHex(b2 / 16), numToHex(b2 % 16))
2337
2338 def trunc(n):
2339 """Truncate a floating point number, rounding up or down appropriately."""
2340 c = math.fabs(math.ceil(n) - n)
2341 f = math.fabs(math.floor(n) - n)
2342
2343 if c < f:
2344 return int(math.ceil(n))
2345 else:
2346 return int(math.floor(n))
2347
2348 # Direct execution of application
2349 if __name__ == "__main__":
2350 tw = TintWizardGUI()
2351 tw.main()
This page took 0.187846 seconds and 4 git commands to generate.