Exemplo n.º 1
0
    def __init__(self):
        gobject.GObject.__init__(self)

        if exists(join(USER_CFG_PATH, CFG_NAME)):
            from lib.migrate_to_gconf import migrate
            migrate(join(USER_CFG_PATH, CFG_NAME))

        self.gconf_client = Configuration()
        self.message = Message()
        # Connects to the database
        self.actions = Actions()

        self.ui = gtk.Builder()
        self.ui.add_from_file(os.path.join(DEFAULT_CFG_PATH, "main.ui"))

        self.window = self.ui.get_object("main_window")
        self.window.set_title("%s" % common.APPNAME)
        self.window.set_icon_from_file(common.APP_ICON)

        # ViewBill
        self.list = ViewBill()
        self.list.connect('cursor_changed', self._on_list_cursor_changed)
        self.list.connect('row_activated', self._on_list_row_activated)
        self.list.connect('button_press_event',
                          self._on_list_button_press_event)

        self.ui.get_object("bill_box").add(self.list)

        # Toolbar
        self.toolbar = self.ui.get_object("toolbar")

        # Menubar
        self._populate_menubar()

        # Statusbar
        self.statusbar = Statusbar()
        self.ui.get_object("statusbar_box").add(self.statusbar)

        # Restore timeline zoom
        timeline_count = self.gconf_client.get('timeline_count')

        # Timeline
        self.timeline = Timeline(count=timeline_count,
                                 callback=self.on_timeline_cb)
        self.timeline.connect("value-changed", self._on_timeline_changed)
        self.timeline.connect("cleared", self._on_timeline_cleared)
        self.ui.get_object("timeline_box").add(self.timeline)

        # Chart
        self.chart = ChartWidget()
        self.chart.set_border_width(10)
        self.ui.get_object("chart_box").add(self.chart)

        # Restore position and size of window
        width = self.gconf_client.get('window_width')
        height = self.gconf_client.get('window_height')
        x = self.gconf_client.get('window_position_x')
        y = self.gconf_client.get('window_position_y')
        if width and height:
            self.window.resize(width, height)
        if x and y:
            self.window.move(x, y)

        self.window.show_all()

        # Whether to display toolbar or not
        self.on_showToolbar_toggled(self.ui.get_object("showToolbar"))
        self.list.grab_focus()

        if self.gconf_client.get('start_in_tray'):
            self.window.hide()

        self.toggle_buttons()

        # Connects to the Daemon
        self.iface = None
        iface = get_dbus_interface(common.DBUS_INTERFACE, common.DBUS_PATH)
        if iface:
            iface.connect_to_signal("bill_edited", self.reloadTreeView)
            iface.connect_to_signal("bill_edited", self.reloadTimeline)
            iface.connect_to_signal("show_main_window", self.window.show)
            self.iface = iface
            timeout_add(2000, self._send_tray_hints)

        self.set_action_strings()
        self.ui.connect_signals(self)

        # populate treeview
        self.reloadTreeView()
        self.notify = NotifyIcon(self)

        # Integrate with Ubuntu Unity
        if UNITY:
            self.unity = UnityIntegration(self)