示例#1
0
文件: gui.py 项目: EnTeQuAk/nms
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())
示例#2
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())