239
240
prefs.add_from_file(ui_file)
240
241
prefs.get_object("notebook").reparent(self.__pref_dialog.vbox)
242
def change_show_value_overlay(show_value_overlay):
243
self.__temp_overlay.props.active = show_value_overlay
243
# = General settings = #
245
self.setup_general_preferences(prefs)
247
# Bind settings to the gtk+ widgets that control them and callbacks
248
# that should be called on setting change.
249
binder = self.applet.settings.get_binder(prefs)
250
binder.bind("unit", "combobox_unit", key_callback=self.change_unit)
251
binder.bind("timeout", "spin_timeout", key_callback=self.change_timeout)
252
binder.bind("theme", "combobox_theme", key_callback=self.change_theme)
253
binder.bind("show_value_overlay", "checkbutton_show_value_overlay",
254
key_callback=self.change_show_value_overlay)
255
binder.bind("font_size", "combobox_font_size",
256
key_callback=self.change_font_size)
257
binder.bind("hand_color", "colorbutton_hand",
258
key_callback=self.change_hand_color)
259
self.applet.settings.load_bindings(binder)
261
# Set the color of the hand color colorbutton
262
cb_hand = prefs.get_object("colorbutton_hand")
263
cb_hand.set_da_color(self.applet.settings["hand_color"])
265
# = Sensor settings = #
267
# Copy to local variable for easy and fast access
245
268
sensors = self.sensors
250
"unit": (units.UNIT_CELSIUS, self.change_unit),
251
"timeout": (2, self.change_timeout,
252
prefs.get_object("spin_timeout")),
253
"theme": (self.__themes[0], self.change_theme),
254
"show_value_overlay": (True, change_show_value_overlay,
255
prefs.get_object("checkbutton_show_value_overlay")),
256
"font_size": (1, self.change_font_size),
257
"hand_color": ("#FFFF88880000FFFF",
258
self.change_hand_color),
270
sensor_default_settings = {
259
271
# Sensor settings
260
272
"ids": [str(sensor.id) for sensor in sensors],
261
273
"labels": [sensor.label for sensor in sensors],
271
283
# Load settings and replace with defaults if not set.
272
for key, value in default_settings.iteritems():
273
if not key in self.applet.settings:
274
self.applet.settings[key] = value
275
settings = self.applet.settings
284
for key, value in sensor_default_settings.iteritems():
285
if key not in self.applet.settings:
286
self.applet.settings[key] = value
288
# Copy to local variable for easy and fast access
289
settings = self.applet.settings
277
291
self.main_sensors = []
278
292
new_sensors = False
299
313
nvidiasensors.interface_name]:
300
314
sensor.updater.set_timeout(settings["timeout"])
302
# If a sensor was lost, a new one found or if order was changed
316
# If a sensor was lost, a new one found or if the order was changed
303
317
if new_sensors or \
304
318
len(sensors) != len(settings["ids"]) or \
305
319
[str(sensor.id) for sensor in sensors] != settings["ids"]:
347
360
awnlib.add_cell_renderer_text(unit_combobox)
348
361
for i in units.UNIT_STR_LONG[:3]:
349
362
unit_combobox.append_text(i)
350
unit_combobox.set_active(self.applet.settings["unit"])
351
unit_combobox.connect('changed', self.unit_changed_cb)
354
365
theme_combobox = prefs.get_object("combobox_theme")
355
366
awnlib.add_cell_renderer_text(theme_combobox)
356
367
for theme in self.__themes:
357
368
# Add filename with '_' replaced width space
358
theme_combobox.append_text(theme.replace('_', ' '))
359
theme_combobox.set_active(self.__themes.index(self.applet.settings["theme"]))
360
theme_combobox.connect('changed', self.theme_changed_cb)
362
# Hand color colorbutton
363
cb_hand = prefs.get_object("colorbutton_hand")
364
# This conversion from desktopagnostic.Color is neccesery because
365
# cb_hand.set_da_color() does not work
366
color = gtk.gdk.Color()
367
self.applet.settings["hand_color"].get_color(color)
368
cb_hand.set_color(color)
369
cb_hand.set_alpha(self.applet.settings["hand_color"].get_alpha())
370
cb_hand.connect('color-set', self.hand_color_changed_cb)
369
theme_combobox.append_text(theme)
370
# If the set theme is not available, revert to default
371
if self.applet.settings["theme"] not in self.__themes:
373
self.applet.settings["theme"] = self.__themes[0]
372
375
# Font size combobox
373
376
font_combobox = prefs.get_object("combobox_font_size")
374
377
awnlib.add_cell_renderer_text(font_combobox)
375
378
for font_size in font_size_names:
376
379
font_combobox.append_text(font_size)
377
font_combobox.set_active(self.applet.settings["font_size"])
378
font_combobox.connect('changed', self.font_size_changed_cb)
380
381
# Font size combobox should be grayed out when value overlay is
602
603
# === Event handlers === #
603
604
def alarm_cb(self, sensor, message):
604
605
"""Show alarm message with awn notify."""
605
self.applet.notify.send(subject=None, body=message, icon="")
606
self.applet.notify.send(subject=None, body=message, icon=applet_logo)
607
608
def height_changed_cb(self):
608
609
"""Update the applet's icon to reflect the new height."""
611
612
self.update_icon(True)
613
614
# === Change setting methods === #
614
def unit_changed_cb(self, widget):
615
"""Save unit setting and update icon."""
616
unit = widget.get_active()
617
self.applet.settings["unit"] = unit
618
self.change_unit(unit)
620
615
def change_unit(self, unit):
621
616
"""Change unit for all sensors and update icon."""
622
617
for sensor in self.sensors:
623
618
sensor.unit = unit
624
619
self.update_icon(True)
626
def font_size_changed_cb(self, widget):
627
"""Save font size setting and update icon."""
628
font_size = widget.get_active()
629
self.applet.settings["font_size"] = font_size
630
self.change_font_size(font_size)
632
621
def change_font_size(self, size_idx):
633
622
"""Change font size for overlay."""
634
623
if len(self.main_sensors) is 1:
640
629
self.__temp_overlay.props.y_override = \
641
630
30 + size_idx if size_idx < 2 else 29
643
def theme_changed_cb(self, widget):
645
self.applet.settings["theme"] = self.__themes[widget.get_active()]
647
632
def change_theme(self, theme):
648
633
"""Save theme setting and update icon."""
649
634
if self.__icon is None:
652
637
# Force icon change
653
638
self.update_icon(True)
640
def change_show_value_overlay(self, show_value_overlay):
641
"""Change whether to show the valu in applet icon"""
642
self.__temp_overlay.props.active = show_value_overlay
655
644
def change_timeout(self, timeout):
656
645
"""Save timeout setting and change timer to new timeout."""
657
646
self.update_icon(True)
696
685
# Force icon update
697
686
self.update_icon(True)
699
def hand_color_changed_cb(self, cb_hand):
700
"""Save hand color"""
701
# This conversion from GdkColor to desktopagnostic.Color is neccesery
702
# because cb_hand.get_da_color() does not work
703
color = self.applet.settings["hand_color"]
704
color.set_color(cb_hand.get_color())
705
color.set_alpha(cb_hand.get_alpha())
706
self.applet.settings["hand_color"] = color
708
688
def change_hand_color(self, color):
709
689
"""Apply hand color setting and update icon."""
710
690
self.__icon.set_hand_color(color)