Beispiel #1
0
    def __init__(self):
        self.__xrandr_gsettings = deepin_gsettings.new(
            "org.gnome.settings-daemon.plugins.xrandr")
        new_brightness = self.__xrandr_gsettings.get_double("brightness")
        if new_brightness > 0.1:
            self.__xrandr_gsettings.set_double("brightness", new_brightness)

        self.gui = Gui()
        self.dbus_user = User(DBUS_USER_STR)
        self.dialog = TrayDialog()

        self.resource_dict = {
            "deepin_shutdown": {
                "info_text": SHUTDOWN_TEXT,
                "ok_text": _("Shut down"),
                "force_ok_text": _("Force shut down"),
                "ok_exec": self.gui.cmd_dbus.new_stop,
            },
            "deepin_restart": {
                "info_text": RESTART_TEXT,
                "ok_text": _("Restart"),
                "force_ok_text": _("Force restart"),
                "ok_exec": self.gui.cmd_dbus.new_restart,
            },
            "deepin_suspend": {
                "info_text": SUSPEND_TEXT,
                "ok_text": _("Suspend"),
                "force_ok_text": _("Force suspend"),
                "ok_exec": self.gui.cmd_dbus.suspend,
            },
            "deepin_hibernate": {
                "info_text": LOGOUT_TEXT,
                "ok_text": _("Log out"),
                "force_ok_text": _("Force log out"),
                "ok_exec": lambda: self.gui.cmd_dbus.logout(1),
            },
        }

        self.gui.stop_btn.connect("clicked", self.check_system_app_running,
                                  'deepin_shutdown')
        self.gui.restart_btn.connect("clicked", self.check_system_app_running,
                                     'deepin_restart')
        self.gui.suspend_btn.connect("clicked", self.check_system_app_running,
                                     'deepin_suspend')
        self.gui.logout_btn.connect("clicked", self.check_system_app_running,
                                    'deepin_hibernate')
        self.gui.switch_btn.connect("clicked", self.switch_btn_clicked)
        self.gui.lock_btn.connect("clicked", self.lock_btn_clicked)
        self.gui.user_label_event.connect("button-press-event",
                                          self.user_label_clicked)
    def __init__(self):
        self.__xrandr_gsettings = deepin_gsettings.new("org.gnome.settings-daemon.plugins.xrandr")
        new_brightness = self.__xrandr_gsettings.get_double("brightness")
        if new_brightness > 0.1:
            self.__xrandr_gsettings.set_double("brightness", new_brightness)
        
        self.gui = Gui()
        self.dbus_user = User(DBUS_USER_STR)
        self.dialog = TrayDialog()

        self.resource_dict = {
                "deepin_shutdown": {
                    "info_text": SHUTDOWN_TEXT,
                    "ok_text": _("Shut down"),
                    "force_ok_text": _("Force shut down"),
                    "ok_exec": self.gui.cmd_dbus.new_stop,
                    },
                "deepin_restart": {
                    "info_text": RESTART_TEXT,
                    "ok_text": _("Restart"),
                    "force_ok_text": _("Force restart"),
                    "ok_exec": self.gui.cmd_dbus.new_restart,
                    },
                "deepin_suspend": {
                    "info_text": SUSPEND_TEXT,
                    "ok_text": _("Suspend"),
                    "force_ok_text": _("Force suspend"),
                    "ok_exec": self.gui.cmd_dbus.suspend,
                    },
                "deepin_hibernate": {
                    "info_text": LOGOUT_TEXT,
                    "ok_text": _("Log out"),
                    "force_ok_text": _("Force log out"),
                    "ok_exec": lambda:self.gui.cmd_dbus.logout(1),
                    },
                }

        self.gui.stop_btn.connect("clicked", self.check_system_app_running, 'deepin_shutdown')
        self.gui.restart_btn.connect("clicked", self.check_system_app_running, 'deepin_restart')
        self.gui.suspend_btn.connect("clicked", self.check_system_app_running, 'deepin_suspend')
        self.gui.logout_btn.connect("clicked", self.check_system_app_running, 'deepin_hibernate')
        self.gui.switch_btn.connect("clicked", self.switch_btn_clicked)
        self.gui.lock_btn.connect("clicked", self.lock_btn_clicked)
        self.gui.user_label_event.connect("button-press-event", self.user_label_clicked)
class TrayShutdownPlugin(object):
    def __init__(self):
        self.__xrandr_gsettings = deepin_gsettings.new("org.gnome.settings-daemon.plugins.xrandr")
        new_brightness = self.__xrandr_gsettings.get_double("brightness")
        if new_brightness > 0.1:
            self.__xrandr_gsettings.set_double("brightness", new_brightness)
        
        self.gui = Gui()
        self.dbus_user = User(DBUS_USER_STR)
        self.dialog = TrayDialog()

        self.resource_dict = {
                "deepin_shutdown": {
                    "info_text": SHUTDOWN_TEXT,
                    "ok_text": _("Shut down"),
                    "force_ok_text": _("Force shut down"),
                    "ok_exec": self.gui.cmd_dbus.new_stop,
                    },
                "deepin_restart": {
                    "info_text": RESTART_TEXT,
                    "ok_text": _("Restart"),
                    "force_ok_text": _("Force restart"),
                    "ok_exec": self.gui.cmd_dbus.new_restart,
                    },
                "deepin_suspend": {
                    "info_text": SUSPEND_TEXT,
                    "ok_text": _("Suspend"),
                    "force_ok_text": _("Force suspend"),
                    "ok_exec": self.gui.cmd_dbus.suspend,
                    },
                "deepin_hibernate": {
                    "info_text": LOGOUT_TEXT,
                    "ok_text": _("Log out"),
                    "force_ok_text": _("Force log out"),
                    "ok_exec": lambda:self.gui.cmd_dbus.logout(1),
                    },
                }

        self.gui.stop_btn.connect("clicked", self.check_system_app_running, 'deepin_shutdown')
        self.gui.restart_btn.connect("clicked", self.check_system_app_running, 'deepin_restart')
        self.gui.suspend_btn.connect("clicked", self.check_system_app_running, 'deepin_suspend')
        self.gui.logout_btn.connect("clicked", self.check_system_app_running, 'deepin_hibernate')
        self.gui.switch_btn.connect("clicked", self.switch_btn_clicked)
        self.gui.lock_btn.connect("clicked", self.lock_btn_clicked)
        self.gui.user_label_event.connect("button-press-event", self.user_label_clicked)

    def exec_command(self, command):
        subprocess.Popen(command, stderr=subprocess.STDOUT, shell=False)

    def check_system_app_running(self, widget, action_id):
        resource = self.resource_dict[action_id]
        if is_software_center_working():
            self.dialog.show_warning(DSC_WARNING_TEXT + "\n\n" + INHIBIT_TAIL,
                    ok_text=resource["force_ok_text"],
                    )
            self.dialog.run_exec = resource["ok_exec"]
            self.this.hide_menu()
        else:
            running_program = inhibit.get_inhibit_programs()
            if running_program:
                if len(running_program) == 1:
                    self.dialog.show_warning(INHIBIT_HEAD+"\n\n"+INHIBIT_TAIL,
                        ok_text=resource["force_ok_text"])
                else:
                    self.dialog.show_warning(INHIBIT_HEAD_PLURAL % len(running_program) 
                            +"\n\n"+INHIBIT_TAIL,
                        ok_text=resource["force_ok_text"])
                self.dialog.run_exec = resource["ok_exec"]
                self.this.hide_menu()
            else:
                self.dialog.show_dialog(action_id, resource["info_text"], resource["ok_text"])
                self.dialog.run_exec = resource["ok_exec"]
                self.this.hide_menu()

    def user_label_clicked(self, widget, event):
        # run dss command.
        if event.button == 1:
            run_command(RUN_DSS_COMMAND)
            self.this.hide_menu()

    def switch_btn_clicked(self, widget):
        self.this.hide_menu()
        run_command(RUN_SWITCH_TOGREETER)

    def lock_btn_clicked(self, widget):
        self.this.hide_menu()
        run_command(RUN_LOCK_COMMAND)

    def init_values(self, this_list):
        self.this_list = this_list
        self.this = self.this_list[0]
        self.tray_icon = self.this_list[1]
        self.tray_icon.set_icon_theme("user")

    def set_user_icon(self):
        try:
            # set user icon.
            #print self.gui.cmd_dbus.get_user_image_path() 
            #self.gui.user_icon.set_from_file(self.gui.cmd_dbus.get_user_image_path())
            self.gui.user_icon.set_from_file(self.dbus_user.get_icon_file())
            #
            user_pixbuf = self.gui.user_icon.get_pixbuf()
            new_user_pixbuf = user_pixbuf.scale_simple(self.gui.icon_width, 
                                                       self.gui.icon_height, 
                                                       gtk.gdk.INTERP_BILINEAR)
        except Exception, e:
            try:
                user_pixbuf = self.gui.gui_theme.get_pixbuf("account/icon.png").get_pixbuf()
                new_user_pixbuf = user_pixbuf.scale_simple(self.gui.icon_width, 
                                                           self.gui.icon_height, 
                                                           gtk.gdk.INTERP_BILINEAR)
                print "set user icon [error]:", e
            except:
                new_user_pixbuf = self.tray_icon.load_icon("user")

        self.gui.user_icon.set_from_pixbuf(new_user_pixbuf)
Beispiel #4
0
class TrayShutdownPlugin(object):
    def __init__(self):
        self.__xrandr_gsettings = deepin_gsettings.new(
            "org.gnome.settings-daemon.plugins.xrandr")
        new_brightness = self.__xrandr_gsettings.get_double("brightness")
        if new_brightness > 0.1:
            self.__xrandr_gsettings.set_double("brightness", new_brightness)

        self.gui = Gui()
        self.dbus_user = User(DBUS_USER_STR)
        self.dialog = TrayDialog()

        self.resource_dict = {
            "deepin_shutdown": {
                "info_text": SHUTDOWN_TEXT,
                "ok_text": _("Shut down"),
                "force_ok_text": _("Force shut down"),
                "ok_exec": self.gui.cmd_dbus.new_stop,
            },
            "deepin_restart": {
                "info_text": RESTART_TEXT,
                "ok_text": _("Restart"),
                "force_ok_text": _("Force restart"),
                "ok_exec": self.gui.cmd_dbus.new_restart,
            },
            "deepin_suspend": {
                "info_text": SUSPEND_TEXT,
                "ok_text": _("Suspend"),
                "force_ok_text": _("Force suspend"),
                "ok_exec": self.gui.cmd_dbus.suspend,
            },
            "deepin_hibernate": {
                "info_text": LOGOUT_TEXT,
                "ok_text": _("Log out"),
                "force_ok_text": _("Force log out"),
                "ok_exec": lambda: self.gui.cmd_dbus.logout(1),
            },
        }

        self.gui.stop_btn.connect("clicked", self.check_system_app_running,
                                  'deepin_shutdown')
        self.gui.restart_btn.connect("clicked", self.check_system_app_running,
                                     'deepin_restart')
        self.gui.suspend_btn.connect("clicked", self.check_system_app_running,
                                     'deepin_suspend')
        self.gui.logout_btn.connect("clicked", self.check_system_app_running,
                                    'deepin_hibernate')
        self.gui.switch_btn.connect("clicked", self.switch_btn_clicked)
        self.gui.lock_btn.connect("clicked", self.lock_btn_clicked)
        self.gui.user_label_event.connect("button-press-event",
                                          self.user_label_clicked)

    def exec_command(self, command):
        subprocess.Popen(command, stderr=subprocess.STDOUT, shell=False)

    def check_system_app_running(self, widget, action_id):
        resource = self.resource_dict[action_id]
        if is_software_center_working():
            self.dialog.show_warning(
                DSC_WARNING_TEXT + "\n\n" + INHIBIT_TAIL,
                ok_text=resource["force_ok_text"],
            )
            self.dialog.run_exec = resource["ok_exec"]
            self.this.hide_menu()
        else:
            running_program = inhibit.get_inhibit_programs()
            if running_program:
                if len(running_program) == 1:
                    self.dialog.show_warning(INHIBIT_HEAD + "\n\n" +
                                             INHIBIT_TAIL,
                                             ok_text=resource["force_ok_text"])
                else:
                    self.dialog.show_warning(
                        INHIBIT_HEAD_PLURAL % len(running_program) + "\n\n" +
                        INHIBIT_TAIL,
                        ok_text=resource["force_ok_text"])
                self.dialog.run_exec = resource["ok_exec"]
                self.this.hide_menu()
            else:
                self.dialog.show_dialog(action_id, resource["info_text"],
                                        resource["ok_text"])
                self.dialog.run_exec = resource["ok_exec"]
                self.this.hide_menu()

    def user_label_clicked(self, widget, event):
        # run dss command.
        if event.button == 1:
            run_command(RUN_DSS_COMMAND)
            self.this.hide_menu()

    def switch_btn_clicked(self, widget):
        self.this.hide_menu()
        run_command(RUN_SWITCH_TOGREETER)

    def lock_btn_clicked(self, widget):
        self.this.hide_menu()
        run_command(RUN_LOCK_COMMAND)

    def init_values(self, this_list):
        self.this_list = this_list
        self.this = self.this_list[0]
        self.tray_icon = self.this_list[1]
        self.tray_icon.set_icon_theme("user")

    def set_user_icon(self):
        try:
            # set user icon.
            #print self.gui.cmd_dbus.get_user_image_path()
            #self.gui.user_icon.set_from_file(self.gui.cmd_dbus.get_user_image_path())
            self.gui.user_icon.set_from_file(self.dbus_user.get_icon_file())
            #
            user_pixbuf = self.gui.user_icon.get_pixbuf()
            new_user_pixbuf = user_pixbuf.scale_simple(self.gui.icon_width,
                                                       self.gui.icon_height,
                                                       gtk.gdk.INTERP_BILINEAR)
        except Exception, e:
            try:
                user_pixbuf = self.gui.gui_theme.get_pixbuf(
                    "account/icon.png").get_pixbuf()
                new_user_pixbuf = user_pixbuf.scale_simple(
                    self.gui.icon_width, self.gui.icon_height,
                    gtk.gdk.INTERP_BILINEAR)
                print "set user icon [error]:", e
            except:
                new_user_pixbuf = self.tray_icon.load_icon("user")

        self.gui.user_icon.set_from_pixbuf(new_user_pixbuf)