def _update_ui(self):
     self.auto_cb.set_active(self.is_auto())
     self.desc_lb.set_text(self._desc)
     if self.is_running():
         icon_name = 'flag-green'
         tip = _('Service is running')
     else:
         icon_name = 'flag-black'
         tip = _('Service is not running')
     self.icon.set_from_pixbuf(get_icon(icon_name, 32))
     self.icon.set_tooltip_text(tip)
    def on_item(self, widget, data):
        """listen ServiceItem signals

        Arguments:
        - `widget`: widget
        - `data': {action:(start|stop|restart|auto),
                   name:...
                   item:ServiceItem object
        """
        action = data['action']
        service_name = data['name']
        item = data['item']
        try:
            if action == 'start':
                if not item.is_running():
                    self.iface.start(service_name)
            elif action == 'stop':
                if item.is_running():
                    self.iface.stop(service_name)
            elif action == 'restart':
                if item.is_running():
                    self.iface.restart(service_name)
            elif action == 'auto':
                self.iface.setEnable(service_name,
                                     not widget.get_active())
        except Exception, e:
            if "Comar.PolicyKit" in e._dbus_error_name:
                open_error_dialog(_('Access Denied'))
            else:
                open_error_dialog(unicode(e))
 def __init__(self):
     """init the variables"""
     super(ServiceManagerAddon, self).__init__()
     self._uuid = "513d0f37-51aa-4124-959c-dfad32f63246"
     self._icon_name = "flag"
     self._label = _("Service Manager")
     self._widget = ServiceManager
    def _create_ui(self):
        #create ui
        self.icon = gtk.Image()

        self.name_lb = gtk.Label()
        self.name_lb.set_markup("<b>"+self._name+"</b>")
        self.name_lb.set_alignment(0.0, 0.5)

        self.desc_lb = gtk.Label(self._desc)
        self.desc_lb.set_alignment(0.0, 0.5)

        self.start_btn = gtk.Button()
        self.start_btn.set_image(get_image('media-playback-start', 16))
        self.start_btn.set_tooltip_text(_('Start service'))

        self.restart_btn = gtk.Button()
        self.restart_btn.set_image(get_image('view-refresh', 16))
        self.restart_btn.set_tooltip_text(_('Restart service'))

        self.stop_btn = gtk.Button()
        self.stop_btn.set_image(get_image('media-playback-stop', 16))
        self.stop_btn.set_tooltip_text(_('Stop service'))

        self.auto_cb = gtk.CheckButton(_('Run at start'))

        self.attach(self.icon, 0, 1, 0, 2,
                    gtk.SHRINK, gtk.SHRINK)
        self.attach(self.name_lb, 1, 2, 0, 1,
                    gtk.EXPAND|gtk.FILL, gtk.SHRINK)
        self.attach(self.desc_lb, 1, 2, 1, 2,
                    gtk.EXPAND|gtk.FILL, gtk.SHRINK)
        self.attach(self.start_btn, 2, 3, 0, 2,
                    gtk.SHRINK, gtk.SHRINK)
        self.attach(self.restart_btn, 3, 4, 0, 2,
                    gtk.SHRINK, gtk.SHRINK)
        self.attach(self.stop_btn, 4, 5, 0, 2,
                    gtk.SHRINK, gtk.SHRINK)
        self.attach(self.auto_cb, 5, 6, 0, 2,
                    gtk.SHRINK, gtk.SHRINK)

        self.show_all()
        self._update_ui()
 def _set_style(self):
     self.set_title(_('Service Manager'))
     self.set_default_size(644, 400)
     self.set_icon_name("flag")