Example #1
0
class TodoView(PidaView):

    key = 'todo.list'

    label_text = _('TODO')
    icon_name = 'accessories-text-editor'

    def create_ui(self):
        self.todo_list = ObjectList([
            Column('line', sorted=True),
            Column('todo', resizable=True, width=200, tooltip_attr='todo'),
            Column('marker', width=50),
        ])
        self.add_main_widget(self.todo_list)
        self.todo_list.show_all()

    def clear_items(self):
        gcall(self.todo_list.clear)

    def add_item(self, todo, line, marker):
        self.todo_list.append(TodoItem(todo, line, marker))

    def on_todo_list__item_activated(self, olist, item):
        self.svc.boss.editor.cmd('goto_line', line=item.line)

    def can_be_closed(self):
        self.svc.get_action('show_todo').set_active(False)
class ListSelectView(SlaveView):
    """
    ListSelectView for selecting an item from a list.
    """
    gsignal('selection-changed', object)

    def __init__(self, items, column_name='name'):
        self.column_name = column_name
        self.items = items
        super(SlaveView, self).__init__()

    def create_ui(self):
        self.widget = gtk.VBox()
        columns = [Column(attr=self.column_name, sortable=True, editable=False,
                          resizeable=True)]
        self.list_box = ObjectList(columns)
        for item in self.items:
            self.add_item(item)

        s = self.list_box.get_selection()
        s.set_mode(gtk.SELECTION_MULTIPLE)

        self.list_box.show_all()
        self.widget.pack_start(self.list_box)

    def add_item(self, item):
        item_object = DictAsAttrProxy({self.column_name: str(item)})
        self.list_box.append(item_object)

    def selected_items(self):
        return [i.as_dict.values()[0]
                for i in self.list_box.selected_items]

    def on_list_box__selection_changed(self, *args, **kwargs):
        self.emit('selection-changed', self.selected_items())
Example #3
0
    def create_ui(self):
        self._last_selected = None
        self.document = None
        self.tasks = {}
        self.restart = False
        self.errors_ol = ObjectList([Column('markup', use_markup=True)])
        self.errors_ol.set_headers_visible(False)
        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.show()
        self.scrolled_window.add(self.errors_ol)

        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
                                        gtk.POLICY_AUTOMATIC)
        self.add_main_widget(self.scrolled_window)

        self.errors_ol.show_all()
        self.sort_combo = AttrSortCombo(
            self.errors_ol,
            [
                ('lineno', _('Line Number')),
                ('message', _('Message')),
                ('type_', _('Type')),
            ],
            'lineno',
        )
        self.sort_combo.show()
        self.add_main_widget(self.sort_combo, expand=False)
Example #4
0
 def create_ui(self):
     self.todo_list = ObjectList([
         Column('line', sorted=True),
         Column('todo', resizable=True, width=200, tooltip_attr='todo'),
         Column('marker', width=50),
     ])
     self.add_main_widget(self.todo_list)
     self.todo_list.show_all()
Example #5
0
 def create_list(self):
     self.notify_list = ObjectList([
         Column('stock', use_stock=True),
         Column('time', sorted=True),
         Column('markup', use_markup=True, expand=True),
     ])
     self.notify_list.set_headers_visible(False)
     self._hbox.pack_start(self.notify_list)
Example #6
0
    def get_trace_view(self, exc, tb):
        olist = ObjectList([Column('markup', use_markup=True)])
        olist.set_headers_visible(False)

        while tb is not None:
            olist.append(TracebackEntry(tb))
            tb = tb.tb_next
        return olist
Example #7
0
 def create_list(self):
     self._list = ObjectList([
         Column('symbol', title=_('Symbol'), use_markup=True),
         Column('filename', title=_('Location'), use_markup=True),
         Column('dataline', title=_('Data'), use_markup=True),
     ])
     self._scroll = gtk.ScrolledWindow()
     self._scroll.add(self._list)
     self._list.connect('item-double-clicked', self._on_list_double_click)
     self._vbox.pack_start(self._scroll)
     self._scroll.show_all()
Example #8
0
 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()
Example #9
0
    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')
Example #10
0
 def create_ui(self):
     self.history_tree = ObjectList(
         [Column('markup', use_markup=True, expand=True)])
     self.history_tree.set_headers_visible(False)
     self.add_main_widget(self.history_tree)
     self.x11_clipboard = gtk.Clipboard(selection="PRIMARY")
     self.gnome_clipboard = gtk.Clipboard(selection="CLIPBOARD")
     self.history_tree.connect('item-right-clicked', self.on_paste_rclick)
     self.__pulse_bar = gtk.ProgressBar()
     self.add_main_widget(self.__pulse_bar, expand=False)
     # only show pulse bar if working
     self.__pulse_bar.hide()
     self.__pulse_bar.set_size_request(-1, 12)
     self.__pulse_bar.set_pulse_step(0.01)
     self.history_tree.show_all()
Example #11
0
File: gui.py Project: EnTeQuAk/nms
    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")
Example #12
0
    def create_ui(self):
        self._last_selected = None
        self.document = None
        self.tasks = {}
        self.restart = False
        self.errors_ol = ObjectList([
            Column('markup', use_markup=True)
        ])
        self.errors_ol.set_headers_visible(False)
        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.show()
        self.scrolled_window.add(self.errors_ol)

        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.add_main_widget(self.scrolled_window)

        self.errors_ol.show_all()
        self.sort_combo = AttrSortCombo(
            self.errors_ol,
            [
                ('lineno', _('Line Number')),
                ('message', _('Message')),
                ('type_', _('Type')),
            ],
            'lineno',
        )
        self.sort_combo.show()
        self.add_main_widget(self.sort_combo, expand=False)
Example #13
0
 def create_list(self):
     self.notify_list = ObjectList([
             Column('stock', use_stock=True),
             Column('time', sorted=True),
             Column('markup', use_markup=True, expand=True),
         ])
     self.notify_list.set_headers_visible(False)
     self._hbox.pack_start(self.notify_list)
Example #14
0
 def create_ui(self):
     self.vbox = gtk.VBox(spacing=3)
     self.vbox.set_border_width(6)
     self.hbox = gtk.HBox()
     self.entry = gtk.Entry()
     self.check = gtk.CheckButton(label='-k')
     self.list = ObjectList([
         Column('markup', title=_('Man page'), sorted=True,
                use_markup=True),
         Column('description', title=_('Description'), use_markup=True),
     ])
     self.scroll = gtk.ScrolledWindow()
     self.scroll.add(self.list)
     self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
     self.hbox.pack_start(self.entry)
     self.hbox.pack_start(self.check, expand=False)
     self.vbox.pack_start(self.hbox, expand=False)
     self.vbox.pack_start(self.scroll)
     self.add_main_widget(self.vbox)
     self.vbox.show_all()
    def create_ui(self):
        self.widget = gtk.VBox()
        columns = [Column(attr=self.column_name, sortable=True, editable=False,
                          resizeable=True)]
        self.list_box = ObjectList(columns)
        for item in self.items:
            self.add_item(item)

        s = self.list_box.get_selection()
        s.set_mode(gtk.SELECTION_MULTIPLE)

        self.list_box.show_all()
        self.widget.pack_start(self.list_box)
Example #16
0
    def create_file_list(self):
        self.file_list = ObjectList()
        self.file_list.set_headers_visible(False)

        def visible_func(item):
            return item is not None and item.visible

        self.file_list.set_visible_func(visible_func)
        self.file_list.set_columns(self._columns)
        self.file_list.connect('selection-changed', self.on_selection_changed)
        self.file_list.connect('item-activated', self.on_file_activated)
        self.file_list.connect('item-right-clicked', self.on_file_right_click)
        self.entries = {}
        self.update_to_path(self.svc.path)
        self.file_list.show()

        self._file_scroll = gtk.ScrolledWindow(
            hadjustment=self.file_list.props.hadjustment,
            vadjustment=self.file_list.props.vadjustment,
        )
        self._file_scroll.set_policy(gtk.POLICY_AUTOMATIC,
                                     gtk.POLICY_AUTOMATIC)
        self._file_scroll.add(self.file_list)
        self._file_scroll.show()

        self._vbox.pack_start(self._file_scroll)
        self._sort_combo = AttrSortCombo(self.file_list, [
            ('is_dir_sort', _('Directories First')),
            ('path', _('File Path')),
            ('lower_name', _('File Name')),
            ('name', _('File Name (Case Sensitive)')),
            ('extension_sort', _('Extension')),
            ('state', _('Version Control Status')),
        ], 'is_dir_sort')
        self._sort_combo.show()
        self._vbox.pack_start(self._sort_combo, expand=False)
        self.on_selection_changed(self.file_list)
Example #17
0
class NotifyView(PidaView):

    key = "notify.view"

    label_text = _('Notifications')
    icon_name = gtk.STOCK_INDEX

    def create_ui(self):
        self._hbox = gtk.HBox(spacing=3)
        self._hbox.set_border_width(6)
        self.create_list()
        self.create_toolbar()
        self.add_main_widget(self._hbox)
        self._hbox.show_all()

    def create_list(self):
        self.notify_list = ObjectList([
            Column('stock', use_stock=True),
            Column('time', sorted=True),
            Column('markup', use_markup=True, expand=True),
        ])
        self.notify_list.set_headers_visible(False)
        self._hbox.pack_start(self.notify_list)

    def create_toolbar(self):
        self._bar = gtk.VBox(spacing=1)
        self._clear_button = create_mini_button(gtk.STOCK_DELETE,
                                                _('Clear history'),
                                                self.on_clear_button)
        self._bar.pack_start(self._clear_button, expand=False)
        self._hbox.pack_start(self._bar, expand=False)
        self._bar.show_all()

    def on_notify_list__item_activated(self, olist, item):
        item.cb_clicked(None, None)

    def on_clear_button(self, w):
        self.clear()

    def add_item(self, item):
        self.notify_list.append(item)

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

    def clear(self):
        self.notify_list.clear()
Example #18
0
class NotifyView(PidaView):

    key = "notify.view"

    label_text = _('Notifications')
    icon_name = gtk.STOCK_INDEX

    def create_ui(self):
        self._hbox = gtk.HBox(spacing=3)
        self._hbox.set_border_width(6)
        self.create_list()
        self.create_toolbar()
        self.add_main_widget(self._hbox)
        self._hbox.show_all()

    def create_list(self):
        self.notify_list = ObjectList([
                Column('stock', use_stock=True),
                Column('time', sorted=True),
                Column('markup', use_markup=True, expand=True),
            ])
        self.notify_list.set_headers_visible(False)
        self._hbox.pack_start(self.notify_list)

    def create_toolbar(self):
        self._bar = gtk.VBox(spacing=1)
        self._clear_button = create_mini_button(
            gtk.STOCK_DELETE, _('Clear history'),
            self.on_clear_button)
        self._bar.pack_start(self._clear_button, expand=False)
        self._hbox.pack_start(self._bar, expand=False)
        self._bar.show_all()

    def on_notify_list__item_activated(self, olist, item):
        item.cb_clicked(None, None)

    def on_clear_button(self, w):
        self.clear()

    def add_item(self, item):
        self.notify_list.append(item)

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

    def clear(self):
        self.notify_list.clear()
Example #19
0
    def create_file_list(self):
        self.file_list = ObjectList()
        self.file_list.set_headers_visible(False)

        def visible_func(item):
            return item is not None and item.visible
        self.file_list.set_visible_func(visible_func)
        self.file_list.set_columns(self._columns);
        self.file_list.connect('selection-changed', self.on_selection_changed)
        self.file_list.connect('item-activated', self.on_file_activated)
        self.file_list.connect('item-right-clicked', self.on_file_right_click)
        self.entries = {}
        self.update_to_path(self.svc.path)
        self.file_list.show()

        self._file_scroll = gtk.ScrolledWindow(
                hadjustment=self.file_list.props.hadjustment,
                vadjustment=self.file_list.props.vadjustment,
                )
        self._file_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._file_scroll.add(self.file_list)
        self._file_scroll.show()

        self._vbox.pack_start(self._file_scroll)
        self._sort_combo = AttrSortCombo(self.file_list,
            [
                ('is_dir_sort', _('Directories First')),
                ('path', _('File Path')),
                ('lower_name', _('File Name')),
                ('name', _('File Name (Case Sensitive)')),
                ('extension_sort', _('Extension')),
                ('state', _('Version Control Status')),
            ],
            'is_dir_sort')
        self._sort_combo.show()
        self._vbox.pack_start(self._sort_combo, expand=False)
        self.on_selection_changed(self.file_list)
Example #20
0


class IconInfo(object):
    def __init__(self, stock_name, name):
        self.stock_name = stock_name
        self._name = name

    @property
    def name(self):
        return '<b>%s</b>'%self._name

icons = ObjectList([
    Column(title='Stock Data', cells=[
        Cell('stock_name', gtk.Pixmap, use_stock=True),
        Cell('stock_name', str),
        ], sorted=False),
    Column('name', str, 'Name', use_markup=True),
], sortable=True)

for id in gtk.stock_list_ids():
    lookup = gtk.stock_lookup(id)
    if lookup is None:
        continue
    stock_name, name = gtk.stock_lookup(id)[:2]
    name = name.replace('_', '')
    icons.append(IconInfo(stock_name, name))

scroll = gtk.ScrolledWindow()
scroll.add(icons)
Example #21
0
class GtagsView(PidaView):
    """
    Window wich shows the seach entry and update button for gtags
    """

    key = 'gtags.list'

    label_text = _('Gtags')

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

    def create_searchbar(self):
        h = gtk.HBox(spacing=3)
        h.set_border_width(2)
        # label
        l = gtk.Label()
        l.set_text(_('Pattern : '))
        h.pack_start(l, expand=False)
        # pattern
        self._search = gtk.Entry()
        self._search.connect('changed', self._on_search_changed)
        self._search.set_sensitive(False)
        h.pack_start(self._search)
        # info
        self._info = gtk.Label()
        self._info.set_text('-')
        h.pack_start(self._info, expand=False)
        self._vbox.pack_start(h, expand=False)
        self._search.show_all()

    def create_toolbar(self):
        self._bar = gtk.VBox(spacing=1)
        self._refresh_button = create_mini_button(
            gtk.STOCK_REFRESH, _('Build TAGS database'),
            self._on_refresh_button_clicked)
        self._bar.pack_start(self._refresh_button, expand=False)
        self._hbox.pack_start(self._bar, expand=False)
        self._bar.show_all()

    def create_list(self):
        self._list = ObjectList([
            Column('symbol', title=_('Symbol'), use_markup=True),
            Column('filename', title=_('Location'), use_markup=True),
            Column('dataline', title=_('Data'), use_markup=True),
        ])
        self._scroll = gtk.ScrolledWindow()
        self._scroll.add(self._list)
        self._list.connect('item-double-clicked', self._on_list_double_click)
        self._vbox.pack_start(self._scroll)
        self._scroll.show_all()

    def create_progressbar(self):
        self._progressbar = gtk.ProgressBar()
        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 add_item(self, item):
        self._list.append(item)
        #XXX: ngettext
        self._info.set_text('%d matches' % len(self._list))

    def clear_items(self):
        self._list.clear()
        self._info.set_text('-')

    def activate(self, activate):
        self._search.set_sensitive(activate)
        self._list.set_sensitive(activate)

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

    def _on_search_changed(self, w):
        self.svc.tag_search(self._search.get_text())

    def _on_refresh_button_clicked(self, w):
        self.svc.build_db()

    def _on_list_double_click(self, o, w):
        file_name = os.path.join(self.svc._project.source_directory, w.file)
        self.svc.boss.cmd('buffer',
                          'open_file',
                          file_name=file_name,
                          line=int(w.line))
Example #22
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())
Example #23
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())
Example #24
0
class ValidatorView(PidaView):

    key = 'language.validator'

    icon_name = 'python-icon'
    label_text = _('Validator')

    def create_ui(self):
        self._last_selected = None
        self.document = None
        self.tasks = {}
        self.restart = False
        self.errors_ol = ObjectList([Column('markup', use_markup=True)])
        self.errors_ol.set_headers_visible(False)
        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.show()
        self.scrolled_window.add(self.errors_ol)

        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
                                        gtk.POLICY_AUTOMATIC)
        self.add_main_widget(self.scrolled_window)

        self.errors_ol.show_all()
        self.sort_combo = AttrSortCombo(
            self.errors_ol,
            [
                ('lineno', _('Line Number')),
                ('message', _('Message')),
                ('type_', _('Type')),
            ],
            'lineno',
        )
        self.sort_combo.show()
        self.add_main_widget(self.sort_combo, expand=False)

    def set_validator(self, validator, document):
        # this is quite an act we have to do here because of the many cornercases
        # 1. Jobs once started run through. This is for caching purpuses as a validator
        # is supposed to cache results, somehow.
        # 2. buffers can switch quite often and n background jobs are still
        # running

        # set the old task job to default priorty again
        old = self.tasks.get(self.document, None)
        if old:
            old.priority = PRIO_LOW

        self.document = document
        self.clear()

        if self.tasks.has_key(document):
            # set the priority of the current validator higher, so it feels
            # faster on the current view
            if self.svc.boss.window.paned.is_visible_pane(self.pane):
                prio = PRIO_FOREGROUND
            else:
                prio = PRIO_DEFAULT
            self.tasks[document].priorty = prio
            # when restart is set, the set_validator is run again so the
            # list gets updated from the validator cache. this happens when
            # the buffer switched to another file and back again
            self.restart = True
            self.svc.log.debug(_('Validator task for {doc} already running'),
                               doc=document)
            return

        self.restart = False

        if validator:

            def wrap_add_node(document, *args):
                # we need this proxy function as a task may be still running in
                # background and the document already switched
                # this way we still can fill up the cache by letting the task run
                # sometimes args have a lengh of 0 so we have to catch this
                if self.document == document and args:
                    item = args[0]
                    self.add_node(item)
                    if self._last_selected:
                        if self._last_selected[0] == self.document:
                            if item.lineno == self._last_selected[1]:
                                self.errors_ol.selected_item = item

            def on_complete(document, validator):
                del self.tasks[document]
                # refire the task and hope the cache will just display stuff,
                # elsewise the task is run again
                validator.sync()

                if document == self.document and self.restart:
                    self.set_validator(validator, document)

            radd = partial(wrap_add_node, document)
            rcomp = partial(on_complete, document, validator)

            if self.svc.boss.window.paned.is_visible_pane(self.pane):
                prio = PRIO_FOREGROUND
            else:
                prio = PRIO_DEFAULT

            task = GeneratorTask(validator.run_cached,
                                 radd,
                                 complete_callback=rcomp,
                                 priority=prio)
            self.tasks[document] = task
            task.start()

    def add_node(self, node):
        if node:
            node.lookup_color = self.errors_ol.style.lookup_color
            self.errors_ol.append(node)

    def clear(self):
        self.errors_ol.clear()

    def on_errors_ol__selection_changed(self, ol):
        item = ol.selected_item  # may be None
        self._last_selected = (self.document, getattr(item, 'lineno', 0))

    def on_errors_ol__item_activated(self, ol, item):
        self.svc.boss.editor.cmd('goto_line', line=int(item.lineno))

    def can_be_closed(self):
        self.svc.get_action('show_validator').set_active(False)
Example #25
0
class PasteHistoryView(PidaView):

    key = 'pastebin.history'

    label_text = _('Paste History')
    icon_name = gtk.STOCK_PASTE

    #glade_file_name = 'paste-history.glade'

    def create_ui(self):
        self.history_tree = ObjectList(
            [Column('markup', use_markup=True, expand=True)])
        self.history_tree.set_headers_visible(False)
        self.add_main_widget(self.history_tree)
        self.x11_clipboard = gtk.Clipboard(selection="PRIMARY")
        self.gnome_clipboard = gtk.Clipboard(selection="CLIPBOARD")
        self.history_tree.connect('item-right-clicked', self.on_paste_rclick)
        self.__pulse_bar = gtk.ProgressBar()
        self.add_main_widget(self.__pulse_bar, expand=False)
        # only show pulse bar if working
        self.__pulse_bar.hide()
        self.__pulse_bar.set_size_request(-1, 12)
        self.__pulse_bar.set_pulse_step(0.01)
        self.history_tree.show_all()

    @property
    def tree_selected(self):
        return self.history_tree.selected_item

    def set(self, pastes):
        '''Sets the paste list to the tree view.
           First reset it, then rebuild it.
        '''
        self.history_tree.clear()
        self.history_tree.expand(pastes)
        self.tree_selected = None

    def add_paste(self, item):
        self.history_tree.append(item)

    def copy_current_paste(self):
        '''Callback function bound to the toolbar button view that copies the
        selected paste'''
        if self.tree_selected != None:
            self.x11_clipboard.set_text(self.tree_selected.get_url())
            self.gnome_clipboard.set_text(self.tree_selected.get_url())

    def view_current_paste(self):
        '''Callback function bound to the toolbar button view that shows the
        selected paste'''
        if self.tree_selected != None:
            self.service.boss.call_command('pastemanager',
                                           'view_paste',
                                           paste=self.tree_selected)
        else:
            print _("ERROR: No paste selected")

    def remove_current_paste(self):
        '''Callback function bound to the toolbar button delete that removes the
        selected paste'''
        if self.tree_selected != None:
            self.service.boss.call_command('pastemanager',
                                           'delete_paste',
                                           paste=self.tree_selected)
        else:
            print _("ERROR: No paste selected")

    def cb_paste_db_clicked(self, ol, item):
        """
        Callback function called when an item is double clicked, and copy it
        to the gnome/gtk clipboard
        """
        if item is not None:
            self.svc.boss.cmd('browseweb', 'browse', url=item.url)
            # self.__gnome_clipboard.set_text(self.__tree_selected.get_url())
            # aa: view the paste

    def cb_paste_m_clicked(self, paste, tree_item):
        '''Callback function called when an item is middle clicked, and copy it
        to the mouse buffer clipboard'''
        if self.__tree_selected != None:
            self.__x11_clipboard.set_text(self.__tree_selected.get_url())

    def cb_paste_r_clicked(self, paste, tree_item, event):
        menu = gtk.Menu()
        sensitives = (tree_item is not None)
        for action in [
                'pastemanager+new_paste', None, 'pastemanager+remove_paste',
                'pastemanager+view_paste', None,
                'pastemanager+copy_url_to_clipboard'
        ]:
            if action is None:
                menu.append(gtk.SeparatorMenuItem())
            else:
                act = self.service.action_group.get_action(action)
                if 'new_paste' not in action:
                    act.set_sensitive(sensitives)
                mi = gtk.ImageMenuItem()
                act.connect_proxy(mi)
                mi.show()
                menu.append(mi)
        menu.show_all()
        menu.popup(None, None, None, event.button, event.time)

    def on_paste_rclick(self, ol, item, event):
        self.svc.boss.cmd('contexts',
                          'popup_menu',
                          context='url-menu',
                          url=item.url,
                          event=event)

    def start_pulse(self):
        '''Starts the pulse'''
        self._pulsing = True
        self.__pulse_bar.show()
        gobject.timeout_add(100, self._pulse)

    def stop_pulse(self):
        self.__pulse_bar.hide()
        self._pulsing = False

    def _pulse(self):
        self.__pulse_bar.pulse()
        return self._pulsing

    def can_be_closed(self):
        self.svc.get_action('show_pastes').set_active(False)
Example #26
0
File: gui.py Project: 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())
Example #27
0
class FilemanagerView(PidaView):

    _columns = [
        Column("icon_stock_id", use_stock=True),
        Column("state_markup", use_markup=True),
        Column("markup", use_markup=True),
        Column("lower_name", visible=False, searchable=True),
        ]

    label_text = _('Files')
    icon_name = 'file-manager'
    key = 'filemanager.list'

    def create_ui(self):
        self._vbox = gtk.VBox()
        self._vbox.show()
        self.create_toolbar()
        self._file_hidden_check_actions = {}
        self._create_file_hidden_check_toolbar()
        self.create_file_list()
        self._clipboard_file = None
        self._fix_paste_sensitivity()
        self.add_main_widget(self._vbox)

    def create_file_list(self):
        self.file_list = ObjectList()
        self.file_list.set_headers_visible(False)

        def visible_func(item):
            return item is not None and item.visible
        self.file_list.set_visible_func(visible_func)
        self.file_list.set_columns(self._columns);
        self.file_list.connect('selection-changed', self.on_selection_changed)
        self.file_list.connect('item-activated', self.on_file_activated)
        self.file_list.connect('item-right-clicked', self.on_file_right_click)
        self.entries = {}
        self.update_to_path(self.svc.path)
        self.file_list.show()

        self._file_scroll = gtk.ScrolledWindow(
                hadjustment=self.file_list.props.hadjustment,
                vadjustment=self.file_list.props.vadjustment,
                )
        self._file_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._file_scroll.add(self.file_list)
        self._file_scroll.show()

        self._vbox.pack_start(self._file_scroll)
        self._sort_combo = AttrSortCombo(self.file_list,
            [
                ('is_dir_sort', _('Directories First')),
                ('path', _('File Path')),
                ('lower_name', _('File Name')),
                ('name', _('File Name (Case Sensitive)')),
                ('extension_sort', _('Extension')),
                ('state', _('Version Control Status')),
            ],
            'is_dir_sort')
        self._sort_combo.show()
        self._vbox.pack_start(self._sort_combo, expand=False)
        self.on_selection_changed(self.file_list)

    def create_toolbar(self):
        self._uim = gtk.UIManager()
        self._uim.insert_action_group(self.svc.get_action_group(), 0)
        self._uim.add_ui_from_string(
                pkgutil.get_data(
                    __name__,
                    'uidef/filemanager-toolbar.xml'))
        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_MENU)
        self._vbox.pack_start(self._toolbar, expand=False)
        self._toolbar.show_all()

    def add_or_update_file(self, name, basepath, state, select=False,
                           parent_link=False):
        if basepath != self.path and not parent_link:
            return
        entry = self.entries.setdefault(name,
                                        FileEntry(name, basepath, self,
                                                  parent_link=parent_link))
        entry.state = state

        self.show_or_hide(entry, select=select)

    def show_or_hide(self, entry, select=False):
        def check(checker):
            if (checker.identifier in self._file_hidden_check_actions) and \
               (self._file_hidden_check_actions[checker.identifier].get_active()):
                return checker(name=entry.name, path=entry.parent_path,
                    state=entry.state, )
            else:
                return True

        if self.svc.opt('show_hidden') or entry.parent_link:
            show = True
        else:
            show = all(check(x)
                        for x in self.svc.features['file_hidden_check'])

        entry.visible = show
        if entry not in self.file_list:
            self.file_list.append(entry)
        self.file_list.update(entry)

        if show and select:
            self.file_list.selected_item = entry

    def update_to_path(self, new_path=None, select=None):
        if new_path is None:
            new_path = self.path
        else:
            self.path = check_or_home(new_path)

        self.file_list.clear()
        self.entries.clear()

        if self.svc.opt('show_parent'):
            parent = os.path.normpath(os.path.join(new_path, os.path.pardir))
            # skip if we are already on the root
            if parent != new_path:
                self.add_or_update_file(os.pardir, parent, 
                                        'normal', parent_link=True)

        def work(basepath):
            dir_content = listdir(basepath)
            # add all files from vcs and remove the corresponding items 
            # from dir_content
            for item in self.svc.boss.cmd('versioncontrol', 'list_file_states',
              path=self.path):
                if (item[1] == self.path):
                    try:
                        dir_content.remove(item[0])
                    except:
                        pass
                    yield item
            # handle remaining files
            for filename in dir_content:
                if (path.isdir(path.join(basepath, filename))):
                    state = 'normal'
                else:
                    state = 'unknown'
                yield filename, basepath, state

        # wrap add_or_update_file to set select accordingly
        def _add_or_update_file(name, basepath, state):
            self.add_or_update_file(name, basepath, state, select=(name==select))

        GeneratorTask(work, _add_or_update_file).start(self.path)

        self.create_ancest_tree()

    def update_single_file(self, name, basepath, select=False):
        if basepath != self.path:
            return
        if name not in self.entries:
            self.add_or_update_file(name, basepath, 'normal', select=select)

    def update_removed_file(self, filename):
        entry = self.entries.pop(filename, None)
        if entry is not None and entry.visible:
            self.file_list.remove(entry)

    def create_dir(self, name=None):
        if not name:
            #XXX: inputdialog or filechooser
            name = dialogs.input('Create New Directory',
                                 label=_("Directory name"))
        if name:
            npath = os.path.join(self.path, name)
            if not os.path.exists(npath):
                os.mkdir(npath)
            self.update_single_file(name, self.path, select=True)

    def on_file_activated(self, ol, fileentry):
        if os.path.exists(fileentry.path): 
            if fileentry.is_dir: 
                self.svc.browse(fileentry.path)
            else:
                self.svc.boss.cmd('buffer', 'open_file', file_name=fileentry.path)
        else:
            self.update_removed_file(fileentry.name)

    def on_file_right_click(self, ol, item, event=None):
        if item.is_dir: 
            self.svc.boss.cmd('contexts', 'popup_menu', context='dir-menu',
                          dir_name=item.path, event=event, filemanager=True) 
        else:
            self.svc.boss.cmd('contexts', 'popup_menu', context='file-menu',
                          file_name=item.path, event=event, filemanager=True)

    def on_selection_changed(self, ol):
        for act_name in ['toolbar_copy',  'toolbar_delete']:
            self.svc.get_action(act_name).set_sensitive(ol.selected_item is not None)

    def rename_file(self, old, new, entry):
        print 'renaming', old, 'to' ,new

    def create_ancest_tree(self):
        task = AsyncTask(self._get_ancestors, self._show_ancestors)
        task.start(self.path)

    def _on_act_up_ancestor(self, action, directory):
        self.svc.browse(directory)

    def _show_ancestors(self, ancs):
        toolitem = self.svc.get_action('toolbar_up').get_proxies()[0]
        menu = gtk.Menu()
        for anc in ancs:
            action = gtk.Action(anc, anc, anc, 'directory')
            action.connect('activate', self._on_act_up_ancestor, anc)
            menuitem = action.create_menu_item()
            menu.add(menuitem)
        menu.show_all()
        toolitem.set_menu(menu)

    def _get_ancestors(self, directory):
        ancs = [directory]
        parent = None
        while True:
            parent = os.path.dirname(directory)
            if parent == directory:
                break
            ancs.append(parent)
            directory = parent
        return ancs

    def _on_act_file_hidden_check(self, action, check):
        if (check.scope == filehiddencheck.SCOPE_GLOBAL):
            # global
            active_checker = self.svc.opt('file_hidden_check')
            if (action.get_active()):
                active_checker.append(check.identifier)
            else:
                active_checker.remove(check.identifier)
            self.svc.set_opt('file_hidden_check', active_checker)
        else:
            # project
            if (self.svc.current_project is not None):
                section = self.svc.current_project.options.get('file_hidden_check', {})
                section[check.identifier] = action.get_active()
                self.svc.current_project.options['file_hidden_check'] = section
        self.update_to_path()
    
    def __file_hidden_check_scope_project_set_active(self, action):
        """sets active state of a file hidden check action with
           scope = project
           relies on action name = identifier of checker"""
        if (self.svc.current_project is not None):
            section = self.svc.current_project.options.get('file_hidden_check')
            action.set_active(
              (section is not None) and
              (action.get_name() in section) and
              (section[action.get_name()] == 'True'))
        else:
            action.set_active(False)
        
    
    def refresh_file_hidden_check(self):
        """refreshes active status of actions of project scope checker"""
        for checker in self.svc.features['file_hidden_check']:
            if (checker.scope == filehiddencheck.SCOPE_PROJECT):
                action = self._file_hidden_check_actions[checker.identifier]
                self.__file_hidden_check_scope_project_set_active(action)
    
    def _create_file_hidden_check_toolbar(self):
        self._file_hidden_check_actions = {}
        menu = gtk.Menu()
        separator = gtk.SeparatorMenuItem()
        project_scope_count = 0
        menu.append(separator)
        for checker in self.svc.features['file_hidden_check']:
            action = gtk.ToggleAction(checker.identifier, checker.label,
              checker.label, None)
            # active?
            if (checker.scope == filehiddencheck.SCOPE_GLOBAL):
                action.set_active(
                    checker.identifier in self.svc.opt('file_hidden_check'))
            else:
                self.__file_hidden_check_scope_project_set_active(action)

            action.connect('activate', self._on_act_file_hidden_check, checker)
            self._file_hidden_check_actions[checker.identifier] = action
            menuitem = action.create_menu_item()
            if (checker.scope == filehiddencheck.SCOPE_GLOBAL):
                menu.prepend(menuitem)
            else:
                menu.append(menuitem)
                project_scope_count += 1
        menu.show_all()
        if (project_scope_count == 0):
            separator.hide()
        toolitem = None
        for proxy in self.svc.get_action('toolbar_hidden_menu').get_proxies():
            if (isinstance(proxy, DropDownMenuToolButton)):
                toolitem = proxy
                break
        if (toolitem is not None):
            toolitem.set_menu(menu)

    def get_selected_filename(self):
        fileentry = self.file_list.selected_item
        if fileentry is not None:
            return fileentry.path

    def copy_clipboard(self):
        current = self.get_selected_filename()
        if os.path.exists(current):
            self._clipboard_file = current
        else:
            self._clipboard_file = None
        self._fix_paste_sensitivity()

    def _fix_paste_sensitivity(self):
        self.svc.get_action('toolbar_paste').set_sensitive(self._clipboard_file
                                                           is not None)

    def paste_clipboard(self):
        newname = os.path.join(self.path, os.path.basename(self._clipboard_file))
        if newname == self._clipboard_file:
            self.svc.error_dlg(_('Cannot copy files to themselves.'))
            return
        if not os.path.exists(self._clipboard_file):
            self.svc.error_dlg(_('Source file has vanished.'))
            return
        if os.path.exists(newname):
            self.svc.error_dlg(_('Destination already exists.'))
            return
        
        task = AsyncTask(self._paste_clipboard, lambda: None)
        task.start()

    def _paste_clipboard(self):
        #XXX: in thread
        newname = os.path.join(self.path, os.path.basename(self._clipboard_file))
        #XXX: GIO?
        if os.path.isdir(self._clipboard_file):
            shutil.copytree(self._clipboard_file, newname)
        else:
            shutil.copy2(self._clipboard_file, newname)

    def remove_path(self, path):
        task = AsyncTask(self._remove_path, lambda: None)
        task.start(path)

    def _remove_path(self, path):
        if os.path.isdir(path):
            shutil.rmtree(path)
        else:
            os.remove(path)
        if path == self._clipboard_file:
            self._clipboard_file = None
            gcall(self._fix_paste_sensitivity)
Example #28
0
class ValidatorView(PidaView):

    key = 'language.validator'

    icon_name = 'python-icon'
    label_text = _('Validator')

    def create_ui(self):
        self._last_selected = None
        self.document = None
        self.tasks = {}
        self.restart = False
        self.errors_ol = ObjectList([
            Column('markup', use_markup=True)
        ])
        self.errors_ol.set_headers_visible(False)
        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.show()
        self.scrolled_window.add(self.errors_ol)

        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.add_main_widget(self.scrolled_window)

        self.errors_ol.show_all()
        self.sort_combo = AttrSortCombo(
            self.errors_ol,
            [
                ('lineno', _('Line Number')),
                ('message', _('Message')),
                ('type_', _('Type')),
            ],
            'lineno',
        )
        self.sort_combo.show()
        self.add_main_widget(self.sort_combo, expand=False)

    def set_validator(self, validator, document):
        # this is quite an act we have to do here because of the many cornercases
        # 1. Jobs once started run through. This is for caching purpuses as a validator
        # is supposed to cache results, somehow.
        # 2. buffers can switch quite often and n background jobs are still 
        # running

        # set the old task job to default priorty again
        old = self.tasks.get(self.document, None)
        if old:
            old.priority = PRIO_LOW

        self.document = document
        self.clear()

        if self.tasks.has_key(document):
            # set the priority of the current validator higher, so it feels 
            # faster on the current view
            if self.svc.boss.window.paned.is_visible_pane(self.pane):
                prio = PRIO_FOREGROUND
            else:
                prio = PRIO_DEFAULT
            self.tasks[document].priorty = prio
            # when restart is set, the set_validator is run again so the 
            # list gets updated from the validator cache. this happens when
            # the buffer switched to another file and back again
            self.restart = True
            self.svc.log.debug(_('Validator task for {doc} already running'),
                               doc=document)
            return

        self.restart = False

        if validator:

            def wrap_add_node(document, *args):
                # we need this proxy function as a task may be still running in 
                # background and the document already switched
                # this way we still can fill up the cache by letting the task run
                # sometimes args have a lengh of 0 so we have to catch this
                if self.document == document and args:
                    item = args[0]
                    self.add_node(item)
                    if self._last_selected:
                        if self._last_selected[0] == self.document:
                            if item.lineno == self._last_selected[1]:
                                self.errors_ol.selected_item = item

            def on_complete(document, validator):
                del self.tasks[document]
                # refire the task and hope the cache will just display stuff,
                # elsewise the task is run again
                validator.sync()

                if document == self.document and self.restart:
                    self.set_validator(validator, document)

            radd = partial(wrap_add_node, document)
            rcomp = partial(on_complete, document, validator)

            if self.svc.boss.window.paned.is_visible_pane(self. pane):
                prio = PRIO_FOREGROUND
            else:
                prio = PRIO_DEFAULT

            task = GeneratorTask(validator.run_cached, 
                                 radd,
                                 complete_callback=rcomp,
                                 priority=prio)
            self.tasks[document] = task
            task.start()

    def add_node(self, node):
        if node:
            node.lookup_color = self.errors_ol.style.lookup_color
            self.errors_ol.append(node)


    def clear(self):
        self.errors_ol.clear()

    def on_errors_ol__selection_changed(self, ol):
        item = ol.selected_item # may be None
        self._last_selected = (self.document, getattr(item, 'lineno', 0))

    def on_errors_ol__item_activated(self, ol, item):
        self.svc.boss.editor.cmd('goto_line', line=int(item.lineno))

    def can_be_closed(self):
        self.svc.get_action('show_validator').set_active(False)
Example #29
0
class ManView(PidaView):

    key = 'man.form'

    icon_name = 'gtk-library'
    label_text = 'Man'

    def create_ui(self):
        self.vbox = gtk.VBox(spacing=3)
        self.vbox.set_border_width(6)
        self.hbox = gtk.HBox()
        self.entry = gtk.Entry()
        self.check = gtk.CheckButton(label='-k')
        self.list = ObjectList([
            Column('markup', title=_('Man page'), sorted=True,
                   use_markup=True),
            Column('description', title=_('Description'), use_markup=True),
        ])
        self.scroll = gtk.ScrolledWindow()
        self.scroll.add(self.list)
        self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.hbox.pack_start(self.entry)
        self.hbox.pack_start(self.check, expand=False)
        self.vbox.pack_start(self.hbox, expand=False)
        self.vbox.pack_start(self.scroll)
        self.add_main_widget(self.vbox)
        self.vbox.show_all()

    def clear_items(self):
        self.list.clear()

    def add_item(self, item):
        self.list.append(item)

    def close(self, term, dummy):
        term.close_view()

    def open(self, item):
        commandargs = ['/usr/bin/env', 'man', item.number, item.pattern]
        directory = os.path.dirname(commandargs[0])
        self.svc.boss.cmd('commander',
                          'execute',
                          commandargs=commandargs,
                          cwd=directory,
                          icon='gnome-library',
                          eof_handler=self.close,
                          title='%(pattern)s(%(number)d)' %
                          dict(pattern=item.pattern, number=int(item.number)))

    def on_list__item_activated(self, olist, item):
        self.open(item)

    def on_entry__changed(self, w):
        if self.check.get_active():
            options = '-k'
        else:
            options = '-f'
        self.svc.cmd_find(options=options, pattern=self.entry.get_text())

    on_check__toggled = on_entry__changed

    def can_be_closed(self):
        self.svc.get_action('show_man').set_active(False)
Example #30
0
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        assert sex in ('m','f')
        self.sex = sex

    def __str__(self):
        return '<User: name=%r age=%r sex=%r>' % (self.name, self.age,
                                                  self.sex)



listing = ObjectList([
    Column('name', str, editable=False, resizable=True),
    Column('age', int, editable=True),
    Column('sex', str, choices=[
        ('m', 'Male'),
        ('f', 'Female'),
        ]),
    ])

def _on_left_clicked(ol, item, event):
    print 'Left clicked', item

def _on_right_clicked(ol, item, event):
    print 'Right clicked', item

def _on_middle_clicked(ol, item, event):
    print 'Middle clicked', item

def _on_double_clicked(ol, item, event):
    print 'Double clicked', item
Example #31
0
class FilemanagerView(PidaView):

    _columns = [
        Column("icon_stock_id", use_stock=True),
        Column("state_markup", use_markup=True),
        Column("markup", use_markup=True),
        Column("lower_name", visible=False, searchable=True),
    ]

    label_text = _('Files')
    icon_name = 'file-manager'
    key = 'filemanager.list'

    def create_ui(self):
        self._vbox = gtk.VBox()
        self._vbox.show()
        self.create_toolbar()
        self._file_hidden_check_actions = {}
        self._create_file_hidden_check_toolbar()
        self.create_file_list()
        self._clipboard_file = None
        self._fix_paste_sensitivity()
        self.add_main_widget(self._vbox)

    def create_file_list(self):
        self.file_list = ObjectList()
        self.file_list.set_headers_visible(False)

        def visible_func(item):
            return item is not None and item.visible

        self.file_list.set_visible_func(visible_func)
        self.file_list.set_columns(self._columns)
        self.file_list.connect('selection-changed', self.on_selection_changed)
        self.file_list.connect('item-activated', self.on_file_activated)
        self.file_list.connect('item-right-clicked', self.on_file_right_click)
        self.entries = {}
        self.update_to_path(self.svc.path)
        self.file_list.show()

        self._file_scroll = gtk.ScrolledWindow(
            hadjustment=self.file_list.props.hadjustment,
            vadjustment=self.file_list.props.vadjustment,
        )
        self._file_scroll.set_policy(gtk.POLICY_AUTOMATIC,
                                     gtk.POLICY_AUTOMATIC)
        self._file_scroll.add(self.file_list)
        self._file_scroll.show()

        self._vbox.pack_start(self._file_scroll)
        self._sort_combo = AttrSortCombo(self.file_list, [
            ('is_dir_sort', _('Directories First')),
            ('path', _('File Path')),
            ('lower_name', _('File Name')),
            ('name', _('File Name (Case Sensitive)')),
            ('extension_sort', _('Extension')),
            ('state', _('Version Control Status')),
        ], 'is_dir_sort')
        self._sort_combo.show()
        self._vbox.pack_start(self._sort_combo, expand=False)
        self.on_selection_changed(self.file_list)

    def create_toolbar(self):
        self._uim = gtk.UIManager()
        self._uim.insert_action_group(self.svc.get_action_group(), 0)
        self._uim.add_ui_from_string(
            pkgutil.get_data(__name__, 'uidef/filemanager-toolbar.xml'))
        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_MENU)
        self._vbox.pack_start(self._toolbar, expand=False)
        self._toolbar.show_all()

    def add_or_update_file(self,
                           name,
                           basepath,
                           state,
                           select=False,
                           parent_link=False):
        if basepath != self.path and not parent_link:
            return
        entry = self.entries.setdefault(
            name, FileEntry(name, basepath, self, parent_link=parent_link))
        entry.state = state

        self.show_or_hide(entry, select=select)

    def show_or_hide(self, entry, select=False):
        def check(checker):
            if (checker.identifier in self._file_hidden_check_actions) and \
               (self._file_hidden_check_actions[checker.identifier].get_active()):
                return checker(
                    name=entry.name,
                    path=entry.parent_path,
                    state=entry.state,
                )
            else:
                return True

        if self.svc.opt('show_hidden') or entry.parent_link:
            show = True
        else:
            show = all(
                check(x) for x in self.svc.features['file_hidden_check'])

        entry.visible = show
        if entry not in self.file_list:
            self.file_list.append(entry)
        self.file_list.update(entry)

        if show and select:
            self.file_list.selected_item = entry

    def update_to_path(self, new_path=None, select=None):
        if new_path is None:
            new_path = self.path
        else:
            self.path = check_or_home(new_path)

        self.file_list.clear()
        self.entries.clear()

        if self.svc.opt('show_parent'):
            parent = os.path.normpath(os.path.join(new_path, os.path.pardir))
            # skip if we are already on the root
            if parent != new_path:
                self.add_or_update_file(os.pardir,
                                        parent,
                                        'normal',
                                        parent_link=True)

        def work(basepath):
            dir_content = listdir(basepath)
            # add all files from vcs and remove the corresponding items
            # from dir_content
            for item in self.svc.boss.cmd('versioncontrol',
                                          'list_file_states',
                                          path=self.path):
                if (item[1] == self.path):
                    try:
                        dir_content.remove(item[0])
                    except:
                        pass
                    yield item
            # handle remaining files
            for filename in dir_content:
                if (path.isdir(path.join(basepath, filename))):
                    state = 'normal'
                else:
                    state = 'unknown'
                yield filename, basepath, state

        # wrap add_or_update_file to set select accordingly
        def _add_or_update_file(name, basepath, state):
            self.add_or_update_file(name,
                                    basepath,
                                    state,
                                    select=(name == select))

        GeneratorTask(work, _add_or_update_file).start(self.path)

        self.create_ancest_tree()

    def update_single_file(self, name, basepath, select=False):
        if basepath != self.path:
            return
        if name not in self.entries:
            self.add_or_update_file(name, basepath, 'normal', select=select)

    def update_removed_file(self, filename):
        entry = self.entries.pop(filename, None)
        if entry is not None and entry.visible:
            self.file_list.remove(entry)

    def create_dir(self, name=None):
        if not name:
            #XXX: inputdialog or filechooser
            name = dialogs.input('Create New Directory',
                                 label=_("Directory name"))
        if name:
            npath = os.path.join(self.path, name)
            if not os.path.exists(npath):
                os.mkdir(npath)
            self.update_single_file(name, self.path, select=True)

    def on_file_activated(self, ol, fileentry):
        if os.path.exists(fileentry.path):
            if fileentry.is_dir:
                self.svc.browse(fileentry.path)
            else:
                self.svc.boss.cmd('buffer',
                                  'open_file',
                                  file_name=fileentry.path)
        else:
            self.update_removed_file(fileentry.name)

    def on_file_right_click(self, ol, item, event=None):
        if item.is_dir:
            self.svc.boss.cmd('contexts',
                              'popup_menu',
                              context='dir-menu',
                              dir_name=item.path,
                              event=event,
                              filemanager=True)
        else:
            self.svc.boss.cmd('contexts',
                              'popup_menu',
                              context='file-menu',
                              file_name=item.path,
                              event=event,
                              filemanager=True)

    def on_selection_changed(self, ol):
        for act_name in ['toolbar_copy', 'toolbar_delete']:
            self.svc.get_action(act_name).set_sensitive(
                ol.selected_item is not None)

    def rename_file(self, old, new, entry):
        print 'renaming', old, 'to', new

    def create_ancest_tree(self):
        task = AsyncTask(self._get_ancestors, self._show_ancestors)
        task.start(self.path)

    def _on_act_up_ancestor(self, action, directory):
        self.svc.browse(directory)

    def _show_ancestors(self, ancs):
        toolitem = self.svc.get_action('toolbar_up').get_proxies()[0]
        menu = gtk.Menu()
        for anc in ancs:
            action = gtk.Action(anc, anc, anc, 'directory')
            action.connect('activate', self._on_act_up_ancestor, anc)
            menuitem = action.create_menu_item()
            menu.add(menuitem)
        menu.show_all()
        toolitem.set_menu(menu)

    def _get_ancestors(self, directory):
        ancs = [directory]
        parent = None
        while True:
            parent = os.path.dirname(directory)
            if parent == directory:
                break
            ancs.append(parent)
            directory = parent
        return ancs

    def _on_act_file_hidden_check(self, action, check):
        if (check.scope == filehiddencheck.SCOPE_GLOBAL):
            # global
            active_checker = self.svc.opt('file_hidden_check')
            if (action.get_active()):
                active_checker.append(check.identifier)
            else:
                active_checker.remove(check.identifier)
            self.svc.set_opt('file_hidden_check', active_checker)
        else:
            # project
            if (self.svc.current_project is not None):
                section = self.svc.current_project.options.get(
                    'file_hidden_check', {})
                section[check.identifier] = action.get_active()
                self.svc.current_project.options['file_hidden_check'] = section
        self.update_to_path()

    def __file_hidden_check_scope_project_set_active(self, action):
        """sets active state of a file hidden check action with
           scope = project
           relies on action name = identifier of checker"""
        if (self.svc.current_project is not None):
            section = self.svc.current_project.options.get('file_hidden_check')
            action.set_active((section is not None)
                              and (action.get_name() in section)
                              and (section[action.get_name()] == 'True'))
        else:
            action.set_active(False)

    def refresh_file_hidden_check(self):
        """refreshes active status of actions of project scope checker"""
        for checker in self.svc.features['file_hidden_check']:
            if (checker.scope == filehiddencheck.SCOPE_PROJECT):
                action = self._file_hidden_check_actions[checker.identifier]
                self.__file_hidden_check_scope_project_set_active(action)

    def _create_file_hidden_check_toolbar(self):
        self._file_hidden_check_actions = {}
        menu = gtk.Menu()
        separator = gtk.SeparatorMenuItem()
        project_scope_count = 0
        menu.append(separator)
        for checker in self.svc.features['file_hidden_check']:
            action = gtk.ToggleAction(checker.identifier, checker.label,
                                      checker.label, None)
            # active?
            if (checker.scope == filehiddencheck.SCOPE_GLOBAL):
                action.set_active(
                    checker.identifier in self.svc.opt('file_hidden_check'))
            else:
                self.__file_hidden_check_scope_project_set_active(action)

            action.connect('activate', self._on_act_file_hidden_check, checker)
            self._file_hidden_check_actions[checker.identifier] = action
            menuitem = action.create_menu_item()
            if (checker.scope == filehiddencheck.SCOPE_GLOBAL):
                menu.prepend(menuitem)
            else:
                menu.append(menuitem)
                project_scope_count += 1
        menu.show_all()
        if (project_scope_count == 0):
            separator.hide()
        toolitem = None
        for proxy in self.svc.get_action('toolbar_hidden_menu').get_proxies():
            if (isinstance(proxy, DropDownMenuToolButton)):
                toolitem = proxy
                break
        if (toolitem is not None):
            toolitem.set_menu(menu)

    def get_selected_filename(self):
        fileentry = self.file_list.selected_item
        if fileentry is not None:
            return fileentry.path

    def copy_clipboard(self):
        current = self.get_selected_filename()
        if os.path.exists(current):
            self._clipboard_file = current
        else:
            self._clipboard_file = None
        self._fix_paste_sensitivity()

    def _fix_paste_sensitivity(self):
        self.svc.get_action('toolbar_paste').set_sensitive(
            self._clipboard_file is not None)

    def paste_clipboard(self):
        newname = os.path.join(self.path,
                               os.path.basename(self._clipboard_file))
        if newname == self._clipboard_file:
            self.svc.error_dlg(_('Cannot copy files to themselves.'))
            return
        if not os.path.exists(self._clipboard_file):
            self.svc.error_dlg(_('Source file has vanished.'))
            return
        if os.path.exists(newname):
            self.svc.error_dlg(_('Destination already exists.'))
            return

        task = AsyncTask(self._paste_clipboard, lambda: None)
        task.start()

    def _paste_clipboard(self):
        #XXX: in thread
        newname = os.path.join(self.path,
                               os.path.basename(self._clipboard_file))
        #XXX: GIO?
        if os.path.isdir(self._clipboard_file):
            shutil.copytree(self._clipboard_file, newname)
        else:
            shutil.copy2(self._clipboard_file, newname)

    def remove_path(self, path):
        task = AsyncTask(self._remove_path, lambda: None)
        task.start(path)

    def _remove_path(self, path):
        if os.path.isdir(path):
            shutil.rmtree(path)
        else:
            os.remove(path)
        if path == self._clipboard_file:
            self._clipboard_file = None
            gcall(self._fix_paste_sensitivity)