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