Exemplo n.º 1
0
    def goto_defintion(self):
        doc = self.boss.cmd('buffer', 'get_current')
        definer = self.get_definer(doc)
        if not definer:
            self.boss.get_service('notify').notify(
                title=_('Goto Definition'),
                data=_('No support for this type found'),
                timeout=2000)
            return
        res = definer.run(doc.content, self.boss.editor.get_cursor_position())

        if isinstance(res, Definition):
            self.use_definition(res)
            return
        elif hasattr(res, '__iter__'):
            res = [x for x in res]

        if isinstance(res, (list, tuple)) and len(res) > 1:
            deflist = DefinitionView(self)
            deflist.set_list(res)
            self.boss.cmd('window', 'add_view', paned='Terminal', view=deflist)
            gcall(deflist.grab_focus)
        elif res:
            self.use_definition(res[0])
        else:
            self.boss.get_service('notify').notify(
                title=_('Goto Definition'),
                data=_('No definition found'),
                timeout=2000)
Exemplo n.º 2
0
 def show_rfc(self):
     self.boss.cmd('window', 'add_view', paned='Plugin', view=self._view)
     if not self._has_loaded:
         self._has_loaded = True
     if not self.is_refresh:
         gcall(self.refresh_index)
         self.is_refresh = True
Exemplo n.º 3
0
def start_editing_tv(tv):
    def _start(tv=tv):
        v = tv.get_treeview()
        path, col = v.get_cursor()
        v.set_cursor(path, col, start_editing=True)

    gcall(_start)
Exemplo n.º 4
0
    def add_view(self, name, view, removable=True, present=True, detachable=True):
        if name == PANE_EDITOR:
            self.add_child(view.get_toplevel())
        else:
            POS = POS_MAP[name]
            lab = PaneLabel(view.icon_name, None, view.label_text)
            if use_old:
                pane = self.insert_pane(view.get_toplevel(), lab, POS, POS)
            else:
                pane = view.key and self.lookup_pane(view.key) or None
                if pane:
                    # we will get a key collission if we dont remove first
                    self.remove_view(pane.view)

                pane = self.insert_pane(view.get_toplevel(), view.key, lab, POS, POS)

            pane.props.detachable = detachable
            #self.set_params(pane, keep_on_top=True)
            view.pane = pane
            pane._was_detached = False
            pane.connect('notify::params', self._on_pane_param_changed)
            pane.view = view
            if not removable:
                pane.set_property('removable', False)
            view._on_remove_attempt_id = pane.connect('remove', 
                                                      view.on_remove_attempt)
            view.toplevel.parent.set_name('PidaWindow')
            if present:
                gcall(self.present_pane, view.get_toplevel())
            self.show_all()
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 def do_callback(job):
     try:
         not_recalled.remove(job)
     except ValueError:
         pass
     if not len(not_recalled):
         self.log.debug('Update job done of {project_dir}',
                        project_dir=project.source_directory)
         gcall(self.notify_user, _("Update complete"), 
                                title=_("Project"))
         del self._update_tasks[project]
Exemplo n.º 8
0
 def do_callback(job):
     try:
         not_recalled.remove(job)
     except ValueError:
         pass
     if not len(not_recalled):
         self.log.debug('Update job done of {project_dir}',
                        project_dir=project.source_directory)
         gcall(self.notify_user,
               _("Update complete"),
               title=_("Project"))
         del self._update_tasks[project]
Exemplo n.º 9
0
 def add_notify(self, item):
     if not self.started:
         gcall(self.add_notify, item)
         return
     self._view.add_item(item)
     if self.opt('show_notify'):
         n = pynotify.Notification(item.title, item.data, item.stock)
         n.set_timeout(item.timeout)
         try:
             n.show()
         except:
             # depending on the notifier daemon, sometimes a glib.GError is raised
             # here.
             pass
Exemplo n.º 10
0
    def _message_cb(self, connection, message):
        method_name = message.get_member()
        interface_name = message.get_interface()

        # should we move this stuff into the OptionsConfig and ActionConfig
        # classes ?
        args = message.get_args_list()

        if interface_name == 'org.freedesktop.DBus.Properties' and \
           len(args) > 1 and args[0] == self.dbus_ns:
            if method_name == "Get":
                opt = self._options[args[1]]
                typ = self.object_to_dbus(opt.type)
                _method_reply_return(connection,
                                     message,
                                     method_name,
                                     Signature(typ),
                                     opt.value)
                return
            elif method_name == "Set":
                self._options[args[1]] = args[2]
                return
            elif method_name == "GetAll":
                rv = {}
                for name, opt in self._options.iteritems():
                    rv[name] = opt.value
                _method_reply_return(connection,
                                     message,
                                     method_name,
                                     Signature('{sv}'),
                                     rv)
                return

        if interface_name == self.dbus_ns:
            if method_name[0:9] == "activate_" and \
               method_name[9:] not in self.dbus_no_activate:
                act = self._actions.get_action(method_name[9:])
                try:
                    #_method_reply_error(connection, message, exception)
                    gcall(act.emit, 'activate')
                    _method_reply_return(connection,
                                         message,
                                         method_name,
                                         Signature(''))
                except Exception, exception:
                    _method_reply_error(connection, message, exception)
                return
            elif method_name == 'CONFIG_CHANGED' or \
                 method_name == 'CONFIG_EXTRA_CHANGED':
                    return
Exemplo n.º 11
0
 def add_notify(self, item):
     if not self.started:
         gcall(self.add_notify, item)
         return
     self._view.add_item(item)
     if self.opt('show_notify'):
         n = pynotify.Notification(item.title, item.data, item.stock)
         n.set_timeout(item.timeout)
         try:
             n.show()
         except:
             # depending on the notifier daemon, sometimes a glib.GError is raised
             # here.
             pass
Exemplo n.º 12
0
    def __init__(self, view, channel):
        self.tree = {}
        self.stack = [ None ]

        self.view = view
        self.channel = channel
        channel.setcallback(lambda msg: gcall(self.callback, *msg))
Exemplo n.º 13
0
def run_pida():
    from pida.core.boss import Boss
    b = Boss() #XXX: relocate firstrun

    # handle start params
    try:
        #XXX: this sucks, needs propper errors
        b.start() # might raise runtime error
        if environment.opts.files:
            from pygtkhelpers.gthreads import gcall
            gcall(b.cmd, 'buffer', 'open_files', files=environment.opts.files)
        b.loop_ui()
        return 0
    except Exception, e:
        traceback.print_exc()
        die_gui("Pida has failed to start",  traceback.format_exc())
        return 1
Exemplo n.º 14
0
    def __init__(self, command=None):
        """
        The WorkspaceWindow is displayed whenever the user should choose a 
        workspace to run.
        
        @fire_command: dbus command to send to an already running 
        @command: run command when one workspace is choosen
        @spawn_new: on the default handle. spawn a new process
        """
        #self.set_role('workspace')
        #self.set_name('Pidaworkspace')

        self.workspaces = []
        self.command = command
        self.list_complete = False
        self.new_workspace = ""
        self.user_action = None

        super(WorkspaceWindow, self).__init__()

        #self.set_role('workspace')
        self.widget.set_name('Pidaworkspace')

        import pida  #XXX: not zip save
        base = os.path.join(pida.__path__[0], 'resources', 'pixmaps')
        self.pic_on = gtk.gdk.pixbuf_new_from_file(
            os.path.join(base, 'online.png'))
        self.pic_off = gtk.gdk.pixbuf_new_from_file(
            os.path.join(base, 'offline.png'))

        self.workspace_view.set_columns([
            Column('id', visible=False),
            Column('pid', visible=False),
            Column('status', title=' ', width=30,
                   type=gtk.gdk.Pixbuf),  #, expand=False, expander=False),
            Column(
                'workspace',
                title=_('Workspace'),
            ),  # searchable=True, sorted=True, expand=True),
            Column('project', title=_('Project'), expand=True),
            Column('open_files', title=_('Open Files'), type=int),
        ])

        gcall(self.update_workspaces)
Exemplo n.º 15
0
 def use_definition(self, res):
     doc = self.boss.cmd('buffer', 'get_current')
     if res and res.offset is not None:
         if res.file_name == doc.filename:
             self.boss.editor.set_cursor_position(res.offset)
         else:
             self.boss.cmd('buffer',
                           'open_file',
                           file_name=res.file_name,
                           offset=res.offset)
         gcall(self.boss.editor.grab_focus)
     elif res and res.line is not None:
         if res.file_name == doc.filename:
             self.boss.editor.goto_line(res.line)
         else:
             self.boss.cmd('buffer',
                           'open_file',
                           file_name=res.file_name,
                           line=res.line)
         gcall(self.boss.editor.grab_focus)
Exemplo n.º 16
0
    def __init__(self, command=None):
        """
        The WorkspaceWindow is displayed whenever the user should choose a 
        workspace to run.
        
        @fire_command: dbus command to send to an already running 
        @command: run command when one workspace is choosen
        @spawn_new: on the default handle. spawn a new process
        """
        #self.set_role('workspace') 
        #self.set_name('Pidaworkspace')

        self.workspaces = []
        self.command = command
        self.list_complete = False
        self.new_workspace = ""
        self.user_action = None

        super(WorkspaceWindow, self).__init__()

        #self.set_role('workspace') 
        self.widget.set_name('Pidaworkspace')
        
        import pida #XXX: not zip save
        base = os.path.join(pida.__path__[0], 'resources', 'pixmaps')
        self.pic_on = gtk.gdk.pixbuf_new_from_file(
                    os.path.join(base, 'online.png'))
        self.pic_off = gtk.gdk.pixbuf_new_from_file(
                    os.path.join(base, 'offline.png'))


        self.workspace_view.set_columns([
            Column('id', visible=False),
            Column('pid', visible=False),
            Column('status', title=' ', width=30, type=gtk.gdk.Pixbuf), #, expand=False, expander=False),
            Column('workspace', title=_('Workspace'),),# searchable=True, sorted=True, expand=True),
            Column('project', title=_('Project'), expand=True),
            Column('open_files', title=_('Open Files'), type=int),
        ])

        gcall(self.update_workspaces)
Exemplo n.º 17
0
    def _download_index(self):
        self.get_action('rfc_downloadindex').set_sensitive(False)
        self._view.show_progressbar(True)
        sock = urllib.urlopen(self.url_rfcindex)
        fp = self._filename.open('w')
        progress_max = 0
        progress_current = 0
        if sock.headers.has_key('content-length'):
            progress_max = int(sock.headers.getheader('content-length'))
        try:
            while True:
                buffer = sock.read(self.buffer_len)
                if buffer == '':
                    break
                fp.write(buffer)
                progress_current += len(buffer)
                gcall(self._view.update_progressbar, progress_current,
                    progress_max)
        finally:
            sock.close()
            fp.close()

        yield None
Exemplo n.º 18
0
    def add_view(self,
                 name,
                 view,
                 removable=True,
                 present=True,
                 detachable=True):
        if name == PANE_EDITOR:
            self.add_child(view.get_toplevel())
        else:
            POS = POS_MAP[name]
            lab = PaneLabel(view.icon_name, None, view.label_text)
            if use_old:
                pane = self.insert_pane(view.get_toplevel(), lab, POS, POS)
            else:
                pane = view.key and self.lookup_pane(view.key) or None
                if pane:
                    # we will get a key collission if we dont remove first
                    self.remove_view(pane.view)

                pane = self.insert_pane(view.get_toplevel(), view.key, lab,
                                        POS, POS)

            pane.props.detachable = detachable
            #self.set_params(pane, keep_on_top=True)
            view.pane = pane
            pane._was_detached = False
            pane.connect('notify::params', self._on_pane_param_changed)
            pane.view = view
            if not removable:
                pane.set_property('removable', False)
            view._on_remove_attempt_id = pane.connect('remove',
                                                      view.on_remove_attempt)
            view.toplevel.parent.set_name('PidaWindow')
            if present:
                gcall(self.present_pane, view.get_toplevel())
            self.show_all()
Exemplo n.º 19
0
def start_editing_tv(tv):
    def _start(tv=tv):
        v = tv.get_treeview()
        path, col = v.get_cursor()
        v.set_cursor(path, col, start_editing=True)
    gcall(_start)
Exemplo n.º 20
0
 def _download_index_finished():
     self._view.show_progressbar(False)
     self.get_action('rfc_downloadindex').set_sensitive(True)
     self.boss.cmd('notify', 'notify', title=_('RFC'), data=_('Index download completed'))
     gcall(self.refresh_index)
Exemplo n.º 21
0
 def filter(self, pattern):
     self._filter_id += 1
     gcall(self._filter, pattern, self._filter_id)
Exemplo n.º 22
0
 def update(self, newlineno):
     gcall(self._do_set_line, newlineno)
Exemplo n.º 23
0
 def emit(self, record):
     gcall(self._in_mainloop, record)
Exemplo n.º 24
0
 def update(self, newlineno):
     gcall(self._do_set_line, newlineno)
Exemplo n.º 25
0
 def emit(self, record):
     gcall(self._in_mainloop, record)
Exemplo n.º 26
0
 def append(self, text, tag):
     self._buffer.insert_with_tags_by_name(
         self._buffer.get_end_iter(), text, tag)
     gcall(self._scroll_to_end)
Exemplo n.º 27
0
 def on_show(self, *args):
     gcall(self.filter.child.grab_focus)
Exemplo n.º 28
0
 def append(self, text, tag):
     self._buffer.insert_with_tags_by_name(self._buffer.get_end_iter(),
                                           text, tag)
     gcall(self._scroll_to_end)
Exemplo n.º 29
0
class Buffer(Service):
    """
    Buffer is a graphical manager for editor buffers.
    """

    commands_config = BufferCommandsConfig
    actions_config = BufferActionsConfig
    events_config = BufferEventsConfig
    features_config = BufferFeaturesConfig
    dbus_config = BufferDbusConfig
    options_config = BufferOptionsConfig

    def pre_start(self):
        self._documents = {}
        self._current = None
        #XXX hideous hack for vim
        self._last_added_document = None
        self._view = BufferListView(self)
        self._view.set_display_attr(attributes[self.opt('display_type')])
        self.get_action('close').set_sensitive(False)
        self._refresh_buffer_action_sensitivities()

    def pre_stop(self):
        self.set_opt('open_files', [
            d.filename
            for d in self._documents.itervalues() if d.filename is not None
        ])
        return True

    def get_view(self):
        return self._view

    def _refresh_buffer_action_sensitivities(self):
        for action_name in ['switch_next_buffer', 'switch_prev_buffer']:
            self.get_action(action_name).set_sensitive(bool(self._documents))

    def new_file(self, do_open=True, with_editor_id=None):
        return self.open_file(editor_buffer_id=with_editor_id)

    def open_file(self,
                  file_name=None,
                  document=None,
                  line=None,
                  offset=None,
                  editor_buffer_id=None,
                  do_open=True):
        if file_name:
            file_name = os.path.realpath(file_name)
        if document is None:
            # try to find the document
            if editor_buffer_id is not None:
                document = self._get_document_for_editor_id(editor_buffer_id)
            if document is None and file_name is not None:
                document = self._get_document_for_filename(file_name)
            elif file_name is None and editor_buffer_id is not None:
                #XXX new file just switched, can't know, have to guess!
                # normally fall back to filename
                if self._last_added_document and self._last_added_document.is_new:
                    document = self._last_added_document
                    self._last_added_document = None
            # can't find it
            if document is None:
                document = Document(self.boss, file_name)
                if editor_buffer_id is not None:
                    document.editor_buffer_id = editor_buffer_id
                self._add_document(document)
        self.view_document(document, line=line, offset=offset, do_open=do_open)
        self.emit('document-opened', document=document)
        return document

    def open_files(self, files):
        if not files:
            # empty list
            return
        docs = []
        for file_name in files:
            document = Document(self.boss, file_name)
            self._add_document(document)
            docs.append(document)
        self.boss.editor.cmd('open_list', documents=docs)
        for document in docs:
            self.emit('document-opened', document=document)

    def recover_loading_error(self, error):
        # recover from a loading exception
        if error.document:
            filename = error.document.filename
        else:
            filename = ""
        self.notify_user(error.message,
                         title=_("Can't load file %s") % filename)
        self.log.warning('error loading file(s): {files}', files=error.message)
        if error.document:
            self._remove_document(error.document)
        # switch to the first doc to make sure editor gets consistent
        if self._documents:
            self.view_document(self._documents[self._documents.keys()[0]])
        #self.log.exception(err)

    def close_current(self):
        document = self._current
        if document is not None:
            if self.boss.editor.cmd('close', document=document):
                self._remove_document(document)
                self.emit('document-closed', document=document)

    def close_file(self, file_name=None, document=None, editor_buffer_id=None):

        if not document:
            if editor_buffer_id is not None:
                document = self._get_document_for_editor_id(editor_buffer_id)
            if not document and file_name is not None:
                document = self._get_document_for_filename(file_name)
        if document is not None:
            if editor_buffer_id is not None:
                self._remove_document(document)
                self.emit('document-closed', document=document)
            else:
                if self.boss.editor.cmd('close', document=document):
                    self._remove_document(document)
                    self.emit('document-closed', document=document)

    def close_all(self):
        docs = self._documents.values()[:]
        for document in docs:
            if self.boss.editor.cmd('close', document=document):
                self._remove_document(document)
                self.emit('document-closed', document=document)
            else:
                break

    def _get_document_for_filename(self, file_name):
        for uid, doc in self._documents.iteritems():
            if doc.filename == file_name:
                return doc

    def _get_document_for_editor_id(self, bufid):
        for uid, doc in self._documents.iteritems():
            if doc.editor_buffer_id == bufid:
                return doc

    def _add_document(self, document):
        self._last_added_document = document
        self._documents[id(document)] = document
        self._view.add_document(document)
        self._refresh_buffer_action_sensitivities()

    def _remove_document(self, document):
        "_remove_doc", document
        del self._documents[id(document)]
        self._view.remove_document(document)
        self._refresh_buffer_action_sensitivities()

    def view_document(self, document, line=None, offset=None, do_open=True):
        self._view.buffers_ol.update(document)
        if document is not None and self._current != document:
            self._current = document
            self._current.usage += 1
            self._current.last_opend = time.time()
            self._view.set_document(document)
            try:
                if do_open:
                    self.boss.editor.cmd('open', document=document)
            except DocumentException, e:
                # document can't be loaded. we have to remove the document from
                # the system
                self.recover_loading_error(e)
                return
            self.emit('document-changed', document=document)
        if offset is not None:
            if line is not None:
                raise ValueError('Cannot pass offset and line')
            else:
                gcall(self.boss.editor.set_cursor_position, offset)
        elif line is not None:
            gcall(self.boss.editor.goto_line, line)
        self.get_action('close').set_sensitive(document is not None)
Exemplo n.º 30
0
 def clear_items(self):
     gcall(self.todo_list.clear)
Exemplo n.º 31
0
 def on_filter_keypress(self, widget, event):
     if event.keyval == gtk.keysyms.Tab and len(self.olist):
         gcall(self.olist.grab_focus)
     if event.keyval == gtk.keysyms.Escape and self.pane.get_params().detached:
         self.can_be_closed()
Exemplo n.º 32
0
 def doit():
     gcall(data.append, 1)