def set_type(self, typo):
        log.debug('called with type = %d' % typo)

        if typo == TrayPlugin.TYPE_WINDOWS and WIN32_PRESENT:

            self.icon = StatusIcon()
            self.type = TrayPlugin.TYPE_WINDOWS

            log.debug('Now notifications will use win32 api')

        elif typo == TrayPlugin.TYPE_LIBNOTIFY and NOTIFY_PRESENT:

            if pynotify.init('UMIT'):
                self.notifier = pynotify.Notification
                self.type = TrayPlugin.TYPE_LIBNOTIFY

                log.debug('Now notifications will use LibNotify')
            else:
                self.set_type(TrayPlugin.TYPE_HIGTOOLTIP)
        else:

            self.type = TrayPlugin.TYPE_HIGTOOLTIP
            self.notifier = HIGTooltip()

            log.debug('Now notifications will use HIGTooltip')
Beispiel #2
0
    def set_type(self, typo):
        log.debug('called with type = %d' % typo)

        if typo == TrayPlugin.TYPE_WINDOWS and WIN32_PRESENT:

            self.icon = StatusIcon()
            self.type = TrayPlugin.TYPE_WINDOWS

            log.debug('Now notifications will use win32 api')

        elif typo == TrayPlugin.TYPE_LIBNOTIFY and NOTIFY_PRESENT:
            
            if pynotify.init('UMIT'):
                self.notifier = pynotify.Notification
                self.type = TrayPlugin.TYPE_LIBNOTIFY

                log.debug('Now notifications will use LibNotify')
            else:
                self.set_type(TrayPlugin.TYPE_HIGTOOLTIP)
        else:

            self.type = TrayPlugin.TYPE_HIGTOOLTIP
            self.notifier = HIGTooltip()

            log.debug('Now notifications will use HIGTooltip')
class TrayPlugin(Plugin):
    TYPE_LIBNOTIFY = 0
    TYPE_HIGTOOLTIP = 1
    TYPE_WINDOWS = 2

    def start(self, reader):
        self.reader = reader

        self.icon = None
        self.wnd_pos = (0, 0)

        self.menu = gtk.Menu()
        self.menu.show()

        action = gtk.Action(None, '_Quit', 'Quit from UMIT', gtk.STOCK_QUIT)
        action.connect('activate', self.__on_quit)

        item = action.create_menu_item()
        item.show()

        self.menu.append(item)

        self.type = self.notifier = None

        # Force to use win32 module
        if WIN32_PRESENT:
            self.set_type(TrayPlugin.TYPE_WINDOWS)
        else:
            self.set_type(tray_prefs.parser['notifications']['type'].value)
            tray_prefs.parser['notifications']['type'].value = self.type

            logo = os.path.join(Path.icons_dir, 'umit_16.ico')
            log.debug('Creating status icon with %s as logo' % logo)

            self.icon = gtk.status_icon_new_from_file(logo)
            tray_prefs.change_cb = self.set_type

        self.icon.connect('popup-menu', self.__on_right_click)
        self.icon.connect('activate', self.__on_activate)

    def set_type(self, typo):
        log.debug('called with type = %d' % typo)

        if typo == TrayPlugin.TYPE_WINDOWS and WIN32_PRESENT:

            self.icon = StatusIcon()
            self.type = TrayPlugin.TYPE_WINDOWS

            log.debug('Now notifications will use win32 api')

        elif typo == TrayPlugin.TYPE_LIBNOTIFY and NOTIFY_PRESENT:

            if pynotify.init('UMIT'):
                self.notifier = pynotify.Notification
                self.type = TrayPlugin.TYPE_LIBNOTIFY

                log.debug('Now notifications will use LibNotify')
            else:
                self.set_type(TrayPlugin.TYPE_HIGTOOLTIP)
        else:

            self.type = TrayPlugin.TYPE_HIGTOOLTIP
            self.notifier = HIGTooltip()

            log.debug('Now notifications will use HIGTooltip')

    def remove_status_icon(self):
        if not self.icon:
            return

        if self.type == TrayPlugin.TYPE_WINDOWS:
            self.icon.remove()
        else:
            self.icon.set_visible(False)
            del self.icon

        self.icon = None

    def stop(self):
        self.remove_status_icon()

    def __on_right_click(self, w, evt, evt_time):
        self.popup_menu.popup(None, None,
            (self.type != TrayPlugin.TYPE_WINDOWS) and \
                 (gtk.status_icon_position_menu)or (None), evt, \
                              evt_time, w)

    def __on_activate(self, widget):
        mainwnd = Core().mainwindow

        if mainwnd.flags() & gtk.VISIBLE:
            self.wndpos = mainwnd.get_position()
            mainwnd.hide()
        else:
            mainwnd.move(*self.wndpos)
            mainwnd.show()

    def __on_quit(self, action):
        # Ask to the main window to exit
        Core().mainwindow.emit('delete-event', None)

    def show_notification(self, msg, title=_("<span size=\"medium\">"
                                             "<b>Information</b></span>"),
                          stock=gtk.STOCK_DIALOG_INFO, fname=None, \
                          timeout=5000):
        """
        Show a notification message by using libnotify or HIGTooltip class
        @param msg The text message of the notification
        @param title The title of the notification
        @param stock The stock image to use
        @param fname The image filename with full path to be used as image
                     instead the stock image
        @param timeout Time to live of the notification expressed in msecs.
                       (pass None for persistent notification)
        """

        if self.type == TrayPlugin.TYPE_WINDOWS:
            if self.icon.notify_icon:
                title = pango.parse_markup(title)[1]
                msg = pango.parse_markup(msg)[1]
                self.icon.notify_icon.show_balloon(title, msg,
                                                   (timeout is None) and (0)
                                                   or (timeout), stock)

        elif self.type == TrayPlugin.TYPE_HIGTOOLTIP:
            rect = self.icon.get_geometry()

            if rect is not None:
                rect = rect[1]
            else:
                return

            data = HIGTooltipData(msg, title, stock, fname)
            self.notifier.show_at(self.icon, data, rect.x, rect.y, timeout)
        else:
            title = pango.parse_markup(title)[1]
            notify = self.notifier(title, msg, \
                                   (fname is None) and (stock) or (None))
            if fname:
                pixbuf = gtk.gdk.pixbuf_new_from_file(fname)
                notify.set_icon_from_pixbuf(pixbuf)
            if timeout:
                notify.set_timeout(timeout)
            notify.show()

    def get_popup_menu(self):
        return self.menu

    def get_status_icon(self):
        return self.icon

    popup_menu = property(get_popup_menu)
    status_icon = property(get_status_icon)
Beispiel #4
0
class TrayPlugin(Plugin):
    TYPE_LIBNOTIFY = 0
    TYPE_HIGTOOLTIP = 1
    TYPE_WINDOWS = 2

    def start(self, reader):
        self.reader = reader

        self.icon = None
        self.wnd_pos = (0, 0)

        self.menu = gtk.Menu()
        self.menu.show()

        action = gtk.Action(None, '_Quit', 'Quit from UMIT', gtk.STOCK_QUIT)
        action.connect('activate', self.__on_quit)

        item = action.create_menu_item()
        item.show()

        self.menu.append(item)

        self.type = self.notifier = None

        # Force to use win32 module
        if WIN32_PRESENT:
            self.set_type(TrayPlugin.TYPE_WINDOWS)
        else:
            self.set_type(tray_prefs.parser['notifications']['type'].value)
            tray_prefs.parser['notifications']['type'].value = self.type

            logo = os.path.join(Path.icons_dir, 'umit_16.ico')
            log.debug('Creating status icon with %s as logo' % logo)

            self.icon = gtk.status_icon_new_from_file(logo)
            tray_prefs.change_cb = self.set_type

        self.icon.connect('popup-menu', self.__on_right_click)
        self.icon.connect('activate', self.__on_activate)

    def set_type(self, typo):
        log.debug('called with type = %d' % typo)

        if typo == TrayPlugin.TYPE_WINDOWS and WIN32_PRESENT:

            self.icon = StatusIcon()
            self.type = TrayPlugin.TYPE_WINDOWS

            log.debug('Now notifications will use win32 api')

        elif typo == TrayPlugin.TYPE_LIBNOTIFY and NOTIFY_PRESENT:
            
            if pynotify.init('UMIT'):
                self.notifier = pynotify.Notification
                self.type = TrayPlugin.TYPE_LIBNOTIFY

                log.debug('Now notifications will use LibNotify')
            else:
                self.set_type(TrayPlugin.TYPE_HIGTOOLTIP)
        else:

            self.type = TrayPlugin.TYPE_HIGTOOLTIP
            self.notifier = HIGTooltip()

            log.debug('Now notifications will use HIGTooltip')

    def remove_status_icon(self):
        if not self.icon:
            return

        if self.type == TrayPlugin.TYPE_WINDOWS:
            self.icon.remove()
        else:
            self.icon.set_visible(False)
            del self.icon

        self.icon = None

    def stop(self):
        self.remove_status_icon()

    def __on_right_click(self, w, evt, evt_time):
        self.popup_menu.popup(None, None,
            (self.type != TrayPlugin.TYPE_WINDOWS) and \
                 (gtk.status_icon_position_menu)or (None), evt, \
                              evt_time, w)

    def __on_activate(self, widget):
        mainwnd = Core().mainwindow

        if mainwnd.flags() & gtk.VISIBLE:
            self.wndpos = mainwnd.get_position()
            mainwnd.hide()
        else:
            mainwnd.move(*self.wndpos)
            mainwnd.show()

    def __on_quit(self, action):
        # Ask to the main window to exit
        Core().mainwindow.emit('delete-event', None)

    def show_notification(self, msg, title=_("<span size=\"medium\">"
                                             "<b>Information</b></span>"),
                          stock=gtk.STOCK_DIALOG_INFO, fname=None, \
                          timeout=5000):
        """
        Show a notification message by using libnotify or HIGTooltip class
        @param msg The text message of the notification
        @param title The title of the notification
        @param stock The stock image to use
        @param fname The image filename with full path to be used as image
                     instead the stock image
        @param timeout Time to live of the notification expressed in msecs.
                       (pass None for persistent notification)
        """

        if self.type == TrayPlugin.TYPE_WINDOWS:
            if self.icon.notify_icon:
                title = pango.parse_markup(title)[1]
                msg = pango.parse_markup(msg)[1]
                self.icon.notify_icon.show_balloon(title, msg,
                    (timeout is None) and (0) or (timeout), stock)

        elif self.type == TrayPlugin.TYPE_HIGTOOLTIP:
            rect = self.icon.get_geometry()

            if rect is not None:
                rect = rect[1]
            else:
                return

            data = HIGTooltipData(msg, title, stock, fname)
            self.notifier.show_at(self.icon, data, rect.x, rect.y, timeout)
        else:
            title = pango.parse_markup(title)[1]
            notify = self.notifier(title, msg, \
                                   (fname is None) and (stock) or (None))
            if fname:
                pixbuf = gtk.gdk.pixbuf_new_from_file(fname)
                notify.set_icon_from_pixbuf(pixbuf)
            if timeout:
                notify.set_timeout(timeout)
            notify.show()

    def get_popup_menu(self):
        return self.menu

    def get_status_icon(self):
        return self.icon

    popup_menu = property(get_popup_menu)
    status_icon = property(get_status_icon)