Ejemplo n.º 1
0
class GtkMain(object):
    def __init__(self, *args, **kwargs):
        self.is_login = False
        self.login_dlg = None
        self._create_tray()
        self._create_widgets()
        self.set_login_status(False)

    def _create_tray(self):

        self.tray_menu_logged_in = gtk.Menu()
        self.tray_menu_logged_out = gtk.Menu()

        if appindicator is not None:
            g_logger.info("APP INDICATOR!")
            # This means we're running on unity and we need a different tray
            self.tray_indicator = appindicator.Indicator(
                "open-monitor",  # APP ID
                "internet-feed-reader",  # ICON NAME
                appindicator.CATEGORY_APPLICATION_STATUS)  # APP CATEGORY
            self.tray_indicator.set_status(appindicator.STATUS_ACTIVE)
            self.tray_indicator.set_attention_icon("indicator-messages-new")
            self.tray_indicator.set_menu(self.tray_menu_logged_out)

        else:
            self.tray_icon = gtk.StatusIcon()
            self.tray_icon.connect('popup-menu', self.show_menu)
            self.tray_icon.set_tooltip("Open Monitor")
            self.tray_icon.set_from_file(
                os.path.join(ICONS_DIR, "tray_icon_gray_32.ico"))

    def _create_widgets(self):
        menu_item = gtk.MenuItem(_("ICM Webpage"))
        menu_item.connect("activate", lambda w: self.show_web_map())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.ImageMenuItem(_("Dashboard"))
        menu_item.connect("activate", lambda w: self.show_dashboard())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.ImageMenuItem(_("Event List"))
        menu_item.connect("activate", lambda w: self.show_event_list())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.ImageMenuItem(_("Logs"))
        menu_item.connect("activate", lambda w: self.show_logs())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        self.tray_menu_logged_in.append(gtk.SeparatorMenuItem())

        menu_item = gtk.MenuItem(_("Preferences..."))
        menu_item.connect("activate", lambda w: self.show_preference())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.MenuItem(_("Software Update"))
        menu_item.connect("activate", lambda w: self.show_software_update())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.MenuItem(_("About"))
        menu_item.connect("activate", lambda w: self.show_about())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        self.tray_menu_logged_in.append(gtk.SeparatorMenuItem())

        menu_item = gtk.MenuItem(_("Logout"))
        menu_item.connect("activate", lambda w: theApp.logout())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.ImageMenuItem(_("Exit"))
        menu_item.connect("activate", lambda w: reactor.stop())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)
        self.tray_menu_logged_in.show_all()
        ###

        menu_item = gtk.MenuItem(_("Login"))
        menu_item.connect("activate", lambda w: self.show_login())
        menu_item.show()
        self.tray_menu_logged_out.append(menu_item)

        self.tray_menu_logged_out.append(gtk.SeparatorMenuItem())

        menu_item = gtk.MenuItem(_("Exit"))
        menu_item.connect("activate", lambda w: reactor.stop())
        menu_item.show()
        self.tray_menu_logged_out.append(menu_item)
        self.tray_menu_logged_out.show_all()

        self.tray_menu = self.tray_menu_logged_out

        # Show splash window
        splash = Splash(os.path.join(IMAGES_DIR, 'splash.png'))

    def set_login_status(self, is_login):
        if self.is_login == is_login:
            return
        self.is_login = is_login
        if is_login:
            if appindicator is not None:
                self.tray_indicator.set_menu(self.tray_menu_logged_in)
            else:
                self.tray_menu.popdown()
            self.tray_menu = self.tray_menu_logged_in

            if appindicator is None:
                self.tray_icon.set_from_file(
                    os.path.join(ICONS_DIR, "tray_icon_32.ico"))
        else:
            if appindicator is not None:
                self.tray_indicator.set_menu(self.tray_menu_logged_out)
            else:
                self.tray_menu.popdown()
            self.tray_menu = self.tray_menu_logged_out

            if appindicator is None:
                self.tray_icon.set_from_file(
                    os.path.join(ICONS_DIR, "tray_icon_gray_32.ico"))

    def show_menu(self, status_icon, button, activate_time):
        self.tray_menu.popup(None, None, None, button, activate_time,
                             status_icon)

    def hide_menu(self, *args, **kwargs):
        self.tray_menu.popdown()

    def show_web_map(self):
        import webbrowser, urlparse
        url = urlparse.urljoin(theApp.aggregator.base_url, '/map/')
        webbrowser.open(url)

    def show_dashboard(self):
        from umit.icm.agent.gui.dashboard.Dashboard import DashboardWindow
        wnd = DashboardWindow()
        wnd.show_all_modify()

    def show_event_list(self):
        from umit.icm.agent.gui.Event import EventWindow
        wnd = EventWindow()
        wnd.show_all()

    def show_logs(self):
        from umit.icm.agent.gui.Logs import LogsWindow
        wnd = LogsWindow()
        wnd.show_all()

    def show_preference(self):
        from umit.icm.agent.gui.Preference.Preference import PreferenceWindow
        wnd = PreferenceWindow()
        wnd.show_all()

    def show_software_update(self):
        from umit.icm.agent.gui.SoftwareUpdate import SoftwareUpdateDialog
        self.update_dialog = SoftwareUpdateDialog()
        self.update_dialog.show_all()

    def show_about(self):
        from umit.icm.agent.gui.About import About
        about = About()
        about.show_all()

    def show_login(self):
        if not self.login_dlg:
            from umit.icm.agent.gui.Login import LoginDialog
            self.login_dlg = LoginDialog()
            self.login_dlg.show_all()

    def set_to_logging_in(self):
        if appindicator is None:
            self.tray_icon.set_tooltip("Logging in...")
        self.tray_menu.get_children()[0].set_sensitive(False)
class GtkMain(object):
    def __init__(self, *args, **kwargs):
        self.is_login = False
        self.login_dlg = None
        self._create_tray()
        self._create_widgets()
        self.set_login_status(False)

    def _create_tray(self):
        
        self.tray_menu_logged_in = gtk.Menu()
        self.tray_menu_logged_out = gtk.Menu()

        if appindicator is not None:
            g_logger.info("APP INDICATOR!")
            # This means we're running on unity and we need a different tray
            self.tray_indicator = appindicator.Indicator("open-monitor", # APP ID
                                     "internet-feed-reader", # ICON NAME
                                     appindicator.CATEGORY_APPLICATION_STATUS) # APP CATEGORY
            self.tray_indicator.set_status(appindicator.STATUS_ACTIVE)
            self.tray_indicator.set_attention_icon("indicator-messages-new")
            self.tray_indicator.set_menu(self.tray_menu_logged_out)

        else:
            self.tray_icon = gtk.StatusIcon()
            self.tray_icon.connect('popup-menu', self.show_menu)
            self.tray_icon.set_tooltip("Open Monitor")
            self.tray_icon.set_from_file(
                            os.path.join(ICONS_DIR, "tray_icon_gray_32.ico"))

    def _create_widgets(self):
        menu_item = gtk.MenuItem(_("ICM Webpage"))
        menu_item.connect("activate", lambda w: self.show_web_map())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.ImageMenuItem(_("Dashboard"))
        menu_item.connect("activate", lambda w: self.show_dashboard())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.ImageMenuItem(_("Event List"))
        menu_item.connect("activate", lambda w: self.show_event_list())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.ImageMenuItem(_("Logs"))
        menu_item.connect("activate", lambda w: self.show_logs())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        self.tray_menu_logged_in.append(gtk.SeparatorMenuItem())

        menu_item = gtk.MenuItem(_("Preferences..."))
        menu_item.connect("activate", lambda w: self.show_preference())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.MenuItem(_("Software Update"))
        menu_item.connect("activate", lambda w: self.show_software_update())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)
        
        menu_item = gtk.MenuItem(_("About"))
        menu_item.connect("activate", lambda w: self.show_about())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        self.tray_menu_logged_in.append(gtk.SeparatorMenuItem())

        menu_item = gtk.MenuItem(_("Logout"))
        menu_item.connect("activate", lambda w: theApp.logout())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)

        menu_item = gtk.ImageMenuItem(_("Exit"))
        menu_item.connect("activate", lambda w: reactor.stop())
        menu_item.show()
        self.tray_menu_logged_in.append(menu_item)
        self.tray_menu_logged_in.show_all()
        ###

        menu_item = gtk.MenuItem(_("Login"))
        menu_item.connect("activate", lambda w: self.show_login())
        menu_item.show()
        self.tray_menu_logged_out.append(menu_item)

        self.tray_menu_logged_out.append(gtk.SeparatorMenuItem())

        menu_item = gtk.MenuItem(_("Exit"))
        menu_item.connect("activate", lambda w: reactor.stop())
        menu_item.show()
        self.tray_menu_logged_out.append(menu_item)
        self.tray_menu_logged_out.show_all()

        self.tray_menu = self.tray_menu_logged_out

        # Show splash window
        splash = Splash(os.path.join(IMAGES_DIR, 'splash.png'))

    def set_login_status(self, is_login):
        if self.is_login == is_login:
            return
        self.is_login = is_login
        if is_login:
            if appindicator is not None:
                self.tray_indicator.set_menu(self.tray_menu_logged_in)
            else:
                self.tray_menu.popdown()
            self.tray_menu = self.tray_menu_logged_in

            if appindicator is None:
                self.tray_icon.set_from_file(
                    os.path.join(ICONS_DIR, "tray_icon_32.ico"))
        else:
            if appindicator is not None:
                self.tray_indicator.set_menu(self.tray_menu_logged_out)
            else:
                self.tray_menu.popdown()
            self.tray_menu = self.tray_menu_logged_out

            if appindicator is None:
                self.tray_icon.set_from_file(
                    os.path.join(ICONS_DIR, "tray_icon_gray_32.ico"))

    def show_menu(self, status_icon, button, activate_time):
        self.tray_menu.popup(None, None, None, button, activate_time,
                             status_icon)

    def hide_menu(self, *args, **kwargs):
        self.tray_menu.popdown()

    def show_web_map(self):
        import webbrowser, urlparse
        url = urlparse.urljoin(theApp.aggregator.base_url, '/map/')
        webbrowser.open(url)

    def show_dashboard(self):
        from umit.icm.agent.gui.dashboard.Dashboard import DashboardWindow
        wnd = DashboardWindow()
        wnd.show_all_modify()

    def show_event_list(self):
        from umit.icm.agent.gui.Event import EventWindow
        wnd = EventWindow()
        wnd.show_all()

    def show_logs(self):
        from umit.icm.agent.gui.Logs import LogsWindow
        wnd = LogsWindow()
        wnd.show_all()

    def show_preference(self):
        from umit.icm.agent.gui.Preference.Preference import PreferenceWindow
        wnd = PreferenceWindow()
        wnd.show_all()
        
    def show_software_update(self):
        from umit.icm.agent.gui.SoftwareUpdate import SoftwareUpdateDialog
        self.update_dialog = SoftwareUpdateDialog()
        self.update_dialog.show_all()

    def show_about(self):
        from umit.icm.agent.gui.About import About
        about = About()
        about.show_all()

    def show_login(self):
        if not self.login_dlg:
            from umit.icm.agent.gui.Login import LoginDialog
            self.login_dlg = LoginDialog()
            self.login_dlg.show_all()

    def set_to_logging_in(self):
        if appindicator is None:
            self.tray_icon.set_tooltip("Logging in...")
        self.tray_menu.get_children()[0].set_sensitive(False)
Ejemplo n.º 3
0
 def show_software_update(self):
     from umit.icm.agent.gui.SoftwareUpdate import SoftwareUpdateDialog
     self.update_dialog = SoftwareUpdateDialog()
     self.update_dialog.show_all()
 def show_software_update(self):
     from umit.icm.agent.gui.SoftwareUpdate import SoftwareUpdateDialog
     self.update_dialog = SoftwareUpdateDialog()
     self.update_dialog.show_all()