Beispiel #1
0
class PreferencesDialog(BaseDialog):
    def __init__(self, parent):
        BaseDialog.__init__(self, "preferences", parent, "core.glade")
        ctx.logger.debug("initalizing preferences dialog")

        # init some data
        mapping = self.mail_cfg = {
            "smtp_host": "text",
            "smtp_user": "******",
            "smtp_password": "******",
            "mail_encoding": "text",
            "mail_default_from": "text",
            "smtp_port": "value",
            "smtp_use_tls": "active",
            "smtp_raise_error": "active",
            "debug": "active",
            "log_timeformat": "text",
        }
        cfg, w = ctx.settings, self.widgets
        # load values from the preferences module and visualize
        # them in the preferences dialog
        for widget, property in mapping.iteritems():
            w[widget].set_property(property, cfg[widget])
        ctx.logger.debug("loaded preferences from database")

        # the combo box to change the active project
        self._themes = ObjectList([Column("display_name", str, "Name"), Column("author", str, "Autor")])
        self._themes.connect("item-activated", self.on_theme_choice_changed)
        self._themes.set_border_width(10)
        self.widgets.theme_vbox.pack_end(self._themes)
        # add all themes to the combo
        self._refresh_themes()

        # init the recipients ObjectList
        vbox = self.widgets.recipients_vbox
        self._recipients = ObjectList(
            [
                Column("name", str, "Name", editable=True),
                Column("mail", str, "E-Mail", editable=True),
                Column("active", str, "Mail senden", editable=True),
                Column("comment", str, "Bemerkung", editable=True),
            ],
            sortable=True,
        )
        self._recipients.connect("item-changed", self._on_recipient_edited)
        vbox.pack_start(self._recipients)
        self._update_recipients()
        self._recipients.show()
        ctx.logger.debug("inialized recipients preferences dialog-page")

    def on_add_recipient_button_clicked(self, sender, arg=None):
        ctx.logger.debug("add_recipient_button clicked")
        rdata = new_recipient_dialog(u"Neuer Empfänger", u"Trage hier die Daten für einen neuen Empfänger ein.")
        if rdata is not None:
            recipient = Recipient(*rdata)
            self._recipients.append(recipient)
            db.save(recipient)
            db.commit()

    def on_delete_recipient_button_clicked(self, sender, arg=None):
        ctx.logger.debug("delte_recipient_button clicked")
        obj = self._recipients.get_selected()
        if obj is not None:
            self._recipients.remove(obj)
            db.delete(obj)
            db.commit()

    def _update_recipients(self):
        rlist = set(self._recipients)
        rdb = set(db.query(Recipient).order_by(Recipient.name).all())
        rdiff = list(rdb - rlist)
        if rdiff:
            if len(rdiff) > 1:
                self._recipients.extend(rdiff)
            else:
                self._recipients.append(rdiff[0])

    def _on_recipient_edited(self, sender, object, attr, value):
        db.commit()
        ctx.logger.debug("recipient edited")

    @property
    def recipients(self):
        self._update_recipients()
        return self._recipients

    def _refresh_themes(self):
        self._themes.clear()
        a = None
        themes = list(find_themes())
        if not themes:
            self._themes.hide()
            self.widgets.no_themes_found.show()
        else:
            for theme in themes:
                self._themes.append(theme)
                if theme.name == ctx.theme_loader.current.name:
                    a = theme
            # if a: self._themes.select(a)
            self.widgets.no_themes_found.hide()
            self._themes.show()
        ctx.logger.debug("themes refreshed and repacked")

    def on_theme_choice_changed(self, sender, obj):
        # set the new theme in ctx.settings
        if obj is not None:
            ctx.settings["theme_choice"] = obj.name
            sender.emit_stop_by_name("item-changed")
        ctx.logger.debug("theme choice changed to %s" % ctx.settings["theme_choice"])

    def on_theme_path_selection_changed(self, sender):
        new_dir = self.widgets.theme_chooser.get_current_folder()
        ctx.settings["theme_path"] = new_dir
        sender.emit_stop_by_name("current-folder-changed")
        self._refresh_themes()
        ctx.logger.debug("theme path changed to %s" % new_dir)

    def get_response_data(self):
        cfg, w = ctx.settings, self.widgets
        return dict((x, w[x].get_property(y)) for x, y in self.mail_cfg.iteritems())
Beispiel #2
0
class RfcView(PidaView):

    key = 'rfc.list'

    label_text = 'RFC'

    def create_ui(self):
        self._vbox = gtk.VBox(spacing=3)
        self._vbox.set_border_width(6)
        self.add_main_widget(self._vbox)
        self.create_toolbar()
        self.create_searchbar()
        self.create_list()
        self.create_progressbar()
        self._vbox.show_all()

    def create_searchbar(self):
        h = gtk.HBox()
        self._search_description = gtk.Entry()
        self._search_description.connect('changed', self._on_search_changed)
        l = gtk.Label()
        l.set_text(_('Filter : '))
        h.pack_start(l, expand=False)
        h.pack_start(self._search_description)
        self._vbox.pack_start(h, expand=False)
        self._search_description.show_all()

    def create_toolbar(self):
        self._uim = gtk.UIManager()
        self._uim.insert_action_group(self.svc.get_action_group(), 0)
        uidef_data = pkgutil.get_data(__name__, 'uidef/rfc-toolbar.xml')
        self._uim.add_ui_from_string(uidef_data)
        self._uim.ensure_update()
        self._toolbar = self._uim.get_toplevels('toolbar')[0]
        self._toolbar.set_style(gtk.TOOLBAR_ICONS)
        self._toolbar.set_icon_size(gtk.ICON_SIZE_SMALL_TOOLBAR)
        self._vbox.pack_start(self._toolbar, expand=False)
        self._toolbar.show_all()

    def create_list(self):
        self._list = ObjectList(
                [
                    Column('number', title=_('Number')),
                    Column('description', title=_('Description'))
                ]
        )
        self._scroll = gtk.ScrolledWindow()
        self._scroll.add(self._list)
        self._list.connect('item-activated', self._on_list_double_click)
        self._vbox.pack_start(self._scroll)
        self._list.show_all()

    def create_progressbar(self):
        self._progressbar = gtk.ProgressBar()
        self._progressbar.set_text(_('Download RFC Index'))
        self._vbox.pack_start(self._progressbar, expand=False)
        self._progressbar.set_no_show_all(True)
        self._progressbar.hide()

    def update_progressbar(self, current, max):
        if max > 1:
            self._progressbar.set_fraction(float(current) / float(max))

    def show_progressbar(self, show):
        self._progressbar.set_no_show_all(False)
        if show:
            self._progressbar.show()
        else:
            self._progressbar.hide()

    def set_items(self, items):
        self._list.extend(items)

    def clear(self):
        self._list.clear()

    def can_be_closed(self):
        self.svc.get_action('show_rfc').set_active(False)

    def _on_list_double_click(self, ot, item):
        self.svc.browse(id=item.number)

    def _on_search_changed(self, w):
        self.svc.filter(self._search_description.get_text())
Beispiel #3
0
def _on_middle_clicked(ol, item, event):
    print 'Middle clicked', item

def _on_double_clicked(ol, item, event):
    print 'Double clicked', item

def _on_item_activated(ol, item):
    print 'Item activated', item

listing.connect('item-left-clicked', _on_left_clicked)
listing.connect('item-right-clicked', _on_right_clicked)
listing.connect('item-middle-clicked', _on_middle_clicked)
listing.connect('item-double-clicked', _on_double_clicked)
listing.connect('item-activated', _on_item_activated)

listing.append(
    User("test", 12, 'm')
    )
listing.extend([
    User('hans', 34, 'm'),
    User('Zok', 60, 'm'),
    ])

window = gtk.Window()
window.add(listing)

window.connect("destroy", gtk.main_quit)
window.show_all()
gtk.main()
Beispiel #4
0
class PreferencesDialog(BaseDialog):

    def __init__(self, parent):
        BaseDialog.__init__(self, 'preferences',
            parent, 'core.glade')
        ctx.logger.debug('initalizing preferences dialog')

        # init some data
        mapping = self.mail_cfg = {
            'smtp_host':            'text',
            'smtp_user':            '******',
            'smtp_password':        '******',
            'mail_encoding':        'text',
            'mail_default_from':    'text',
            'smtp_port':            'value',
            'smtp_use_tls':         'active',
            'smtp_raise_error':     'active',
            'debug':                'active',
            'log_timeformat':       'text',
        }
        cfg, w = ctx.settings, self.widgets
        # load values from the preferences module and visualize
        # them in the preferences dialog
        for widget, property in mapping.iteritems():
            w[widget].set_property(property, cfg[widget])
        ctx.logger.debug('loaded preferences from database')

        # the combo box to change the active project
        self._themes = ObjectList([
            Column('display_name', str, 'Name'),
            Column('author', str, 'Autor')
        ])
        self._themes.connect('item-activated', self.on_theme_choice_changed)
        self._themes.set_border_width(10)
        self.widgets.theme_vbox.pack_end(self._themes)
        # add all themes to the combo
        self._refresh_themes()

        # init the recipients ObjectList
        vbox = self.widgets.recipients_vbox
        self._recipients = ObjectList([
            Column('name', str, 'Name', editable=True),
            Column('mail', str, 'E-Mail', editable=True),
            Column('active', str, 'Mail senden', editable=True),
            Column('comment', str, 'Bemerkung', editable=True)
        ], sortable=True)
        self._recipients.connect('item-changed', self._on_recipient_edited)
        vbox.pack_start(self._recipients)
        self._update_recipients()
        self._recipients.show()
        ctx.logger.debug('inialized recipients preferences dialog-page')

    def on_add_recipient_button_clicked(self, sender, arg=None):
        ctx.logger.debug('add_recipient_button clicked')
        rdata = new_recipient_dialog(u'Neuer Empfänger',
            u'Trage hier die Daten für einen neuen Empfänger ein.')
        if rdata is not None:
            recipient = Recipient(*rdata)
            self._recipients.append(recipient)
            db.save(recipient)
            db.commit()

    def on_delete_recipient_button_clicked(self, sender, arg=None):
        ctx.logger.debug('delte_recipient_button clicked')
        obj = self._recipients.get_selected()
        if obj is not None:
            self._recipients.remove(obj)
            db.delete(obj)
            db.commit()

    def _update_recipients(self):
        rlist = set(self._recipients)
        rdb = set(db.query(Recipient).order_by(Recipient.name).all())
        rdiff = list(rdb - rlist)
        if rdiff:
            if len(rdiff) > 1:
                self._recipients.extend(rdiff)
            else:
                self._recipients.append(rdiff[0])

    def _on_recipient_edited(self, sender, object, attr, value):
        db.commit()
        ctx.logger.debug('recipient edited')

    @property
    def recipients(self):
        self._update_recipients()
        return self._recipients

    def _refresh_themes(self):
        self._themes.clear()
        a = None
        themes = list(find_themes())
        if not themes:
            self._themes.hide()
            self.widgets.no_themes_found.show()
        else:
            for theme in themes:
                self._themes.append(theme)
                if theme.name ==  ctx.theme_loader.current.name:
                    a = theme
            #if a: self._themes.select(a)
            self.widgets.no_themes_found.hide()
            self._themes.show()
        ctx.logger.debug('themes refreshed and repacked')

    def on_theme_choice_changed(self, sender, obj):
        # set the new theme in ctx.settings
        if obj is not None:
            ctx.settings['theme_choice'] = obj.name
            sender.emit_stop_by_name('item-changed')
        ctx.logger.debug('theme choice changed to %s'
            % ctx.settings['theme_choice'])

    def on_theme_path_selection_changed(self, sender):
        new_dir = self.widgets.theme_chooser.get_current_folder()
        ctx.settings['theme_path'] = new_dir
        sender.emit_stop_by_name('current-folder-changed')
        self._refresh_themes()
        ctx.logger.debug('theme path changed to %s' % new_dir)

    def get_response_data(self):
        cfg, w = ctx.settings, self.widgets
        return dict((x, w[x].get_property(y)) for x, y in \
                    self.mail_cfg.iteritems())