~ubuntu-branches/ubuntu/lucid/awn-extras-applets/lucid

« back to all changes in this revision

Viewing changes to applets/maintained/hardware-sensors/hardware-sensors.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-03-30 20:26:40 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100330202640-vza3bdnv9gc9bg5z
Tags: 0.4.0~rc1-0ubuntu1
* New upstream release (rc1) (LP: #551309)
 - Stack applet close on click (LP: #261520)
* debian/patches/
 - 03-remove-cairo-menu-pref.patch: From upstream (r1244 + r1245 + r1252),
   remove menu entry for cairo-menu preferences, it's not implemented
   (LP: #511254)
 - 04-tomboy-threading-free.patch: From upstream (r1246), remove threading to
   make the applet working. 
* debian/*.install: Update installation location of comics and digital 
  applets.
* debian/control: 
 - Move digital applet from python to C, and add proper Replaces.
 - Add Replaces for awn-applets-c-core to handle migration from 0.3.2.2.
   (LP: #524559)

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
            return os.path.isdir(os.path.join(theme_dir, path))
100
100
 
101
101
        self.__themes = filter(is_dir, os.listdir(theme_dir))
 
102
        self.__themes = [theme.replace("_", " ") for theme in self.__themes]
102
103
        self.__themes.sort()
103
104
 
104
105
        # == Settings == #
239
240
        prefs.add_from_file(ui_file)
240
241
        prefs.get_object("notebook").reparent(self.__pref_dialog.vbox)
241
242
 
242
 
        def change_show_value_overlay(show_value_overlay):
243
 
            self.__temp_overlay.props.active = show_value_overlay
244
 
 
 
243
        # = General settings = #
 
244
 
 
245
        self.setup_general_preferences(prefs)
 
246
 
 
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)
 
260
 
 
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"])
 
264
 
 
265
        # = Sensor settings = #
 
266
 
 
267
        # Copy to local variable for easy and fast access
245
268
        sensors = self.sensors
246
269
 
247
 
        # Default settings
248
 
        default_settings = {
249
 
            # Global
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],
269
281
        }
270
282
 
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
 
287
 
 
288
        # Copy to local variable for easy and fast access
 
289
        settings = self.applet.settings
276
290
 
277
291
        self.main_sensors = []
278
292
        new_sensors = False
299
313
                                    nvidiasensors.interface_name]:
300
314
                sensor.updater.set_timeout(settings["timeout"])
301
315
 
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"]:
337
351
            self.__icon = None
338
352
            self.applet.settings["theme"] = self.__themes[0]
339
353
 
340
 
        self.setup_general_preferences(prefs)
341
354
        self.setup_sensor_preferences(prefs)
342
355
 
343
356
    def setup_general_preferences(self, prefs):
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)
352
363
 
353
364
        # Theme combobox
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)
361
 
 
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:
 
372
            self.__icon = None
 
373
            self.applet.settings["theme"] = self.__themes[0]
371
374
 
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)
379
380
 
380
381
        # Font size combobox should be grayed out when value overlay is
381
382
        # disabled
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)
606
607
 
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)
612
613
 
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)
619
 
 
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)
625
620
 
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)
631
 
 
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
642
631
 
643
 
    def theme_changed_cb(self, widget):
644
 
        # Save setting
645
 
        self.applet.settings["theme"] = self.__themes[widget.get_active()]
646
 
 
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)
654
639
 
 
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
 
643
 
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)
698
687
 
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
707
 
 
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)