Beispiel #1
0
    def __init__(self):

        cream.Module.__init__(self)

        cream.ipc.Object.__init__(self,
            'org.cream.Melange',
            '/org/cream/Melange'
        )

        self.run_server()

        self.screen = cream.util.pywmctrl.Screen()
        self.display = gtk.gdk.display_get_default()

        self.widgets = WidgetManager()

        # Scan for themes...
        theme_dir = os.path.join(self.context.working_directory, 'themes')
        self.themes = cream.manifest.ManifestDB(theme_dir, type='org.cream.melange.Theme')

        # Scan for widgets...
        self.available_widgets = cream.manifest.ManifestDB('widgets', type='org.cream.melange.Widget')

        self.add_widget_dialog = AddWidgetDialog()

        # Load widgets stored in configuration.
        for widget in self.config.widgets:
            self.load_widget(**widget)

        widgets = sorted(self.available_widgets.by_id.itervalues(), key=itemgetter('name'))
        for widget in widgets:
            self.add_widget_dialog.add(widget, self.context.working_directory)
        self.hotkeys.connect('hotkey-activated', self.hotkey_activated_cb)
Beispiel #2
0
class Melange(cream.Module, cream.ipc.Object):
    """ The main class of the Melange module. """

    def __init__(self):

        cream.Module.__init__(self)

        cream.ipc.Object.__init__(self,
            'org.cream.Melange',
            '/org/cream/Melange'
        )

        self.run_server()

        self.screen = cream.util.pywmctrl.Screen()
        self.display = gtk.gdk.display_get_default()

        self.widgets = WidgetManager()

        # Scan for themes...
        theme_dir = os.path.join(self.context.working_directory, 'themes')
        self.themes = cream.manifest.ManifestDB(theme_dir, type='org.cream.melange.Theme')

        # Scan for widgets...
        self.available_widgets = cream.manifest.ManifestDB('widgets', type='org.cream.melange.Widget')

        self.add_widget_dialog = AddWidgetDialog()

        # Load widgets stored in configuration.
        for widget in self.config.widgets:
            self.load_widget(**widget)

        widgets = sorted(self.available_widgets.by_id.itervalues(), key=itemgetter('name'))
        for widget in widgets:
            self.add_widget_dialog.add(widget, self.context.working_directory)
        self.hotkeys.connect('hotkey-activated', self.hotkey_activated_cb)


    def run_server(self):
        server = HttpServer(self)
        thread.start_new_thread(server.run, (HTTPSERVER_HOST, HTTPSERVER_PORT))


    def add_widget(self):

        self.add_widget_dialog.dialog.show_all()

        if self.add_widget_dialog.dialog.run() == 1:
            selection = self.add_widget_dialog.treeview.get_selection()
            model, iter = selection.get_selected()

            id = model.get_value(iter, 2)
            self.load_widget(id, False, False)
        self.add_widget_dialog.dialog.hide()


    def hotkey_activated_cb(self, source, action):

        if action == 'toggle_overlay':
            pass


    @cream.ipc.method('', '')
    def debug_memory(self):

        from guppy import hpy
        h = hpy()
        print h.heap()


    @cream.ipc.method('svv', '')
    def load_widget(self, name, x=None, y=None):
        """
        Load a widget with the given name at the specified coordinates (optional).

        :param name: The name of the widget.
        :param x: The x-coordinate.
        :param y: The y-coordinate.

        :type name: `str`
        :type x: `int`
        :type y: `int`
        """

        x, y = int(x), int(y)

        self.messages.debug("Loading widget '%s'..." % name)

        # Initialize the widget...
        widget = Widget(self.available_widgets.get_by_name(name)._path, backref=self)

        widget.set_position(x, y)

        # Add the widget to the list of currently active widgets:
        self.widgets.add(widget, x, y)

        widget.show()


    @cream.ipc.method('', 'a{sa{ss}}')
    def list_widgets(self):
        """
        List all available widgets.

        :return: List of widgets.
        :rtype: `list`
        """

        res = {}

        for id, w in self.available_widgets.by_id.iteritems():
            res[id] = {
                'name': w['name'],
                'description': '',
                'path': '',
                'id': w['id'],
                }

        return res


    def quit(self):
        """ Quit the module. """

        self.config.widgets = self.widgets.values()
        cream.Module.quit(self)