Example #1
0
    def __init__(self, parent_window, priority=model.TODO):
        super(BaseActivityView, self).__init__(False, 0)
        self.parent_window = parent_window
        self.priority = priority
        self.act_name = gtk.Entry()
        self.act_name.set_property('secondary-icon-stock', gtk.STOCK_ADD)
        self.act_name.set_property('secondary-icon-tooltip-text',
                                   'Add new activity')
        self.act_name.set_property('secondary-icon-activatable', True)
        self.act_name.connect('activate', self._on_add)
        self.act_name.connect('icon-press', self._on_add)
        self.act_name.connect('focus-in-event', self._on_focus)

        finish_btn = util.new_small_button(
            'dialog-ok',
            self._on_mark_finish,
            tooltip=_('Mark the selected activity as finished'))

        del_btn = util.new_small_button(
            'edit-delete',
            self._on_delete,
            tooltip=_('Remove the selected activity'))

        buttons = [finish_btn, del_btn]
        for btn, pos in self._create_additional_buttons():
            buttons.insert(pos, btn)
        toolbar_box = gtk.HBox(False, 0)
        for btn in buttons:
            toolbar_box.pack_start(btn, False, False)
        toolbar_box.pack_end(self.act_name, True, True)

        self.act_model = ActivityStore(priority=self.priority)
        self.act_view = self._create_list_view(self.act_model)
        self.connect('destroy', lambda arg: self.act_model.close())
        act_wnd = gtk.ScrolledWindow()
        act_wnd.add(self.act_view)
        act_wnd.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        topbox = gtk.HBox(False, 0)
        topbox.pack_start(toolbar_box, True, True, padding=5)
        self.pack_start(topbox, False, False, padding=5)
        self.pack_end(act_wnd, True, True)
Example #2
0
    def __init__(self, parent_window, priority=model.TODO):
        super(BaseActivityView, self).__init__(False, 0)
        self.parent_window = parent_window
        self.priority = priority
        self.act_name = gtk.Entry()
        self.act_name.set_property('secondary-icon-stock', gtk.STOCK_ADD)
        self.act_name.set_property('secondary-icon-tooltip-text',
                'Add new activity')
        self.act_name.set_property('secondary-icon-activatable', True)
        self.act_name.connect('activate', self._on_add)
        self.act_name.connect('icon-press', self._on_add)
        self.act_name.connect('focus-in-event', self._on_focus)

        finish_btn = util.new_small_button(
                'dialog-ok',
                self._on_mark_finish,
                tooltip=_('Mark the selected activity as finished'))

        del_btn = util.new_small_button(
                'edit-delete',
                self._on_delete,
                tooltip=_('Remove the selected activity'))

        buttons = [finish_btn, del_btn]
        for btn, pos in self._create_additional_buttons():
            buttons.insert(pos, btn)
        toolbar_box = gtk.HBox(False, 0)
        for btn in buttons:
            toolbar_box.pack_start(btn, False, False)
        toolbar_box.pack_end(self.act_name, True, True)

        self.act_model = ActivityStore(priority=self.priority)
        self.act_view = self._create_list_view(self.act_model)
        self.connect('destroy', lambda arg : self.act_model.close())
        act_wnd = gtk.ScrolledWindow()
        act_wnd.add(self.act_view)
        act_wnd.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        topbox = gtk.HBox(False, 0)
        topbox.pack_start(toolbar_box, True, True, padding=5)
        self.pack_start(topbox, False, False, padding=5)
        self.pack_end(act_wnd, True, True)
Example #3
0
class BaseActivityView(gtk.VBox):
    """Base class for activity views"""
    def __init__(self, parent_window, priority=model.TODO):
        super(BaseActivityView, self).__init__(False, 0)
        self.parent_window = parent_window
        self.priority = priority
        self.act_name = gtk.Entry()
        self.act_name.set_property('secondary-icon-stock', gtk.STOCK_ADD)
        self.act_name.set_property('secondary-icon-tooltip-text',
                                   'Add new activity')
        self.act_name.set_property('secondary-icon-activatable', True)
        self.act_name.connect('activate', self._on_add)
        self.act_name.connect('icon-press', self._on_add)
        self.act_name.connect('focus-in-event', self._on_focus)

        finish_btn = util.new_small_button(
            'dialog-ok',
            self._on_mark_finish,
            tooltip=_('Mark the selected activity as finished'))

        del_btn = util.new_small_button(
            'edit-delete',
            self._on_delete,
            tooltip=_('Remove the selected activity'))

        buttons = [finish_btn, del_btn]
        for btn, pos in self._create_additional_buttons():
            buttons.insert(pos, btn)
        toolbar_box = gtk.HBox(False, 0)
        for btn in buttons:
            toolbar_box.pack_start(btn, False, False)
        toolbar_box.pack_end(self.act_name, True, True)

        self.act_model = ActivityStore(priority=self.priority)
        self.act_view = self._create_list_view(self.act_model)
        self.connect('destroy', lambda arg: self.act_model.close())
        act_wnd = gtk.ScrolledWindow()
        act_wnd.add(self.act_view)
        act_wnd.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        topbox = gtk.HBox(False, 0)
        topbox.pack_start(toolbar_box, True, True, padding=5)
        self.pack_start(topbox, False, False, padding=5)
        self.pack_end(act_wnd, True, True)

    def _create_list_view(self, act_model):
        def _act_name_render_func(col, renderer, model, iter, user_data=None):
            name = model.get_value(iter, ActivityStore.TITLE_COL)
            finished = model.get_value(iter, ActivityStore.FINISHED_COL)
            if finished:
                name = '<span foreground="#32CD32"><s>%s</s></span>' % name
            renderer.set_property('markup', name)

        act_view = gtk.TreeView()
        act_view.set_model(act_model)

        toggle_renderer = gtk.CellRendererToggle()
        toggle_renderer.set_property('activatable', True)
        toggle_renderer.connect('toggled', self._on_toggle_finish)
        toggle_col = gtk.TreeViewColumn('#', toggle_renderer, active=1)
        toggle_col.set_expand(False)
        title_col = util.new_text_col(_('Activity'), _act_name_render_func)
        title_col.set_resizable(True)
        title_col.set_expand(True)
        title_col.get_cell_renderers()[0].set_property('editable', True)
        title_col.get_cell_renderers()[0].connect('edited', self._on_update)

        other_cols = self._create_additional_columns()
        act_view.append_column(toggle_col)
        act_view.append_column(title_col)
        for col in other_cols:
            act_view.append_column(col)

        sel = act_view.get_selection()
        sel.set_mode(gtk.SELECTION_SINGLE)
        act_model.load_activities()
        return act_view

    def _create_additional_buttons(self):
        #Should be overriden by sub class
        return tuple()

    def _create_additional_columns(self):
        #Should be overriden by sub class
        return tuple()

    def refresh(self):
        self.act_model.load_activities()

    def _on_add(self, widget, *args, **kwargs):
        name = self.act_name.get_text().decode('UTF-8')
        self.act_name.set_text('')
        self.act_model.add_activity(model.Activity(name=name))
        return True

    def _on_focus(self, widget, *args, **kwargs):
        name = self.act_name.get_text()
        self.act_name.select_region(0, len(name))

    def _on_toggle_finish(self, renderer, path, user_data=None):
        activity = self.act_model.get_activity_bypath(path)
        if activity.is_finished():
            activity.unfinish()
        else:
            activity.finish()
        self.act_model.update_activity(activity)
        return True

    def _on_mark_finish(self, widget):
        (_, it) = self.act_view.get_selection().get_selected()
        activity = self.act_model.get_activity_byiter(it)
        if not activity.is_finished():
            activity.finish()
        self.act_model.update_activity(activity)
        return True

    def _on_update(self, cell, path, new_text, user_data=None):
        activity = self.act_model.get_activity_bypath(path)
        if not new_text.strip():
            return
        new_name = new_text.decode('UTF-8')
        activity.name = new_name
        self.act_model.update_activity(activity)
        return True

    def _on_delete(self, widget):
        (_, it) = self.act_view.get_selection().get_selected()
        if not it:
            util.show_message_dialog(_("Please select an activity"))
            return
        self.act_model.delete_activity_byiter(it)
        return True
Example #4
0
class BaseActivityView(gtk.VBox):
    """Base class for activity views"""
    def __init__(self, parent_window, priority=model.TODO):
        super(BaseActivityView, self).__init__(False, 0)
        self.parent_window = parent_window
        self.priority = priority
        self.act_name = gtk.Entry()
        self.act_name.set_property('secondary-icon-stock', gtk.STOCK_ADD)
        self.act_name.set_property('secondary-icon-tooltip-text',
                'Add new activity')
        self.act_name.set_property('secondary-icon-activatable', True)
        self.act_name.connect('activate', self._on_add)
        self.act_name.connect('icon-press', self._on_add)
        self.act_name.connect('focus-in-event', self._on_focus)

        finish_btn = util.new_small_button(
                'dialog-ok',
                self._on_mark_finish,
                tooltip=_('Mark the selected activity as finished'))

        del_btn = util.new_small_button(
                'edit-delete',
                self._on_delete,
                tooltip=_('Remove the selected activity'))

        buttons = [finish_btn, del_btn]
        for btn, pos in self._create_additional_buttons():
            buttons.insert(pos, btn)
        toolbar_box = gtk.HBox(False, 0)
        for btn in buttons:
            toolbar_box.pack_start(btn, False, False)
        toolbar_box.pack_end(self.act_name, True, True)

        self.act_model = ActivityStore(priority=self.priority)
        self.act_view = self._create_list_view(self.act_model)
        self.connect('destroy', lambda arg : self.act_model.close())
        act_wnd = gtk.ScrolledWindow()
        act_wnd.add(self.act_view)
        act_wnd.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        topbox = gtk.HBox(False, 0)
        topbox.pack_start(toolbar_box, True, True, padding=5)
        self.pack_start(topbox, False, False, padding=5)
        self.pack_end(act_wnd, True, True)

    def _create_list_view(self, act_model):

        def _act_name_render_func(col, renderer, model, iter, user_data=None):
            name = model.get_value(iter, ActivityStore.TITLE_COL)
            finished = model.get_value(iter, ActivityStore.FINISHED_COL)
            if finished:
                name = '<span foreground="#32CD32"><s>%s</s></span>' % name
            renderer.set_property('markup', name)

        act_view = gtk.TreeView()
        act_view.set_model(act_model)

        toggle_renderer = gtk.CellRendererToggle()
        toggle_renderer.set_property('activatable', True)
        toggle_renderer.connect('toggled', self._on_toggle_finish)
        toggle_col = gtk.TreeViewColumn('#', toggle_renderer, active=1)
        toggle_col.set_expand(False)
        title_col = util.new_text_col(_('Activity'), _act_name_render_func)
        title_col.set_resizable(True)
        title_col.set_expand(True)
        title_col.get_cell_renderers()[0].set_property('editable', True)
        title_col.get_cell_renderers()[0].connect('edited', self._on_update)

        other_cols = self._create_additional_columns()
        act_view.append_column(toggle_col)
        act_view.append_column(title_col)
        for col in other_cols:
            act_view.append_column(col)

        sel = act_view.get_selection()
        sel.set_mode(gtk.SELECTION_SINGLE)
        act_model.load_activities()
        return act_view

    def _create_additional_buttons(self):
        #Should be overriden by sub class
        return tuple()

    def _create_additional_columns(self):
        #Should be overriden by sub class
        return tuple()

    def refresh(self):
        self.act_model.load_activities()

    def _on_add(self, widget, *args, **kwargs):
        name = self.act_name.get_text().decode('UTF-8')
        self.act_name.set_text('')
        self.act_model.add_activity(model.Activity(name=name))
        return True

    def _on_focus(self, widget, *args, **kwargs):
        name = self.act_name.get_text()
        self.act_name.select_region(0, len(name))

    def _on_toggle_finish(self, renderer, path, user_data=None):
        activity = self.act_model.get_activity_bypath(path)
        if activity.is_finished():
            activity.unfinish()
        else:
            activity.finish()
        self.act_model.update_activity(activity)
        return True

    def _on_mark_finish(self, widget):
        (_, it) = self.act_view.get_selection().get_selected()
        activity = self.act_model.get_activity_byiter(it)
        if not activity.is_finished():
            activity.finish()
        self.act_model.update_activity(activity)
        return True

    def _on_update(self, cell, path, new_text, user_data=None):
        activity = self.act_model.get_activity_bypath(path)
        if not new_text.strip():
            return
        new_name = new_text.decode('UTF-8')
        activity.name = new_name
        self.act_model.update_activity(activity)
        return True

    def _on_delete(self, widget):
        (_, it) = self.act_view.get_selection().get_selected()
        if not it:
            util.show_message_dialog(_("Please select an activity"))
            return
        self.act_model.delete_activity_byiter(it)
        return True