Beispiel #1
0
APP_TITLE = 'Comical'
APP_VERSION = 0
APP_SUBVERSION = 1
APP_REVISION = 14

import gi
gi.require_version('Gtk', '3.0')

from gi.repository import Gtk

from backend.IssueLoader import IssueLoader
from ui.MainWindow import MainWindow

issue_loader = IssueLoader()

main_window = MainWindow(title=APP_TITLE)

main_window.connect('load_issue', issue_loader.handle_load_issue)
main_window.connect('delete-event', Gtk.main_quit)

issue_loader.connect('issue_ready', main_window.handle_issue_ready)

main_window.show_all()
Gtk.main()
Beispiel #2
0
class UI:
    ICON_CONNECTED = "evolution-mail"
    ICON_DISCONNECTED = "edit-delete-mail"
    ICON_NEW_EMAIL = "mail-mark-unread"

    current_picture = None
    window = None

    refresh_enabled = True

    window_size = (400, 350)

    def __init__(self, config):
        GObject.threads_init()
        self.queue = Queue()
        self.config = config

        self.app = Application(self.update, self.queue, self.config)
        self.info = self.app.last_info

    def start(self):
        Thread(target=self.app.check_queue).start()
        scheduler = Thread(target=self.app.schedule_check_new)
        scheduler.daemon = True
        scheduler.start()

        self.icon = Gtk.StatusIcon()
        self._update()
        self.icon.connect("activate", self.show_window)

        Gtk.main()

    def quit(self, arg):
        self.icon.set_visible(False)
        if self.window is not None:
            self.destroy_window()
        Gtk.main_quit()
        self.queue.put((self.app.close, None))

    def update(self, data):
        GLib.idle_add(self._update, data)

    def _update(self, data=None):
        if data is not None:
            self.info = pickle.loads(data)

        picture = UI.ICON_DISCONNECTED
        if self.info.is_connected:
            picture = UI.ICON_CONNECTED
        if len(self.info.emails) > 0:
            picture = UI.ICON_NEW_EMAIL
        if picture != self.current_picture:
            self.current_picture = picture
            self.icon.set_from_icon_name(picture)

        if self.window is not None:
            self.window.update(self.info)

    def show_window(self, arg):
        if self.window is None:
            self.window = MainWindow(self)
            self.window.set_default_size(self.window_size[0], self.window_size[1])
            self.window.connect("delete-event", self.destroy_window)
            self.window.update(self.info)
        else:
            self.destroy_window()

    def destroy_window(self, arg1=None, arg2=None):
        self.window_size = self.window.get_size()
        self.window.destroy()
        self.window = None