Example #1
0
    def add_source_mark_pixbufs(self):
        attrs = GtkSource.MarkAttributes()
        color = Gdk.RGBA()
        parsed = color.parse("lightgreen")
        if parsed:
            attrs.set_background(color)
        attrs.set_stock_id(Gtk.STOCK_YES)
        attrs.connect("query-tooltip-markup", self.mark_tooltip_func)
        self._view.set_mark_attributes(self.MARK_TYPE_1, attrs, 1)

        attrs = GtkSource.MarkAttributes()
        color = Gdk.RGBA()
        parsed = color.parse("pink")
        if parsed:
            attrs.set_background(color)
        attrs.set_stock_id(Gtk.STOCK_NO)
        attrs.connect("query-tooltip-markup", self.mark_tooltip_func)
        self._view.set_mark_attributes(self.MARK_TYPE_2, attrs, 2)
 def register_marks(self):
     """
     Creates mark-attributes for all result severities.
     """
     self.view.set_show_line_marks(True)
     for name, val in RESULT_SEVERITY.str_dict.items():
         attr = GtkSource.MarkAttributes()
         attr.set_icon_name(RESULT_SEVERITY_ICONS[val])
         attr.connect("query_tooltip_markup", self.show_mark_tooltip)
         self.view.set_mark_attributes(get_mark_category(name), attr, 0)
         self.log_printer.info("Mark attribute created for", name)
Example #3
0
	def on_tab_added(self, window, tab, data=None) :
		#print("on_tab_added")
		doc = tab.get_document()
		doc.is_vhdl_file = False
		doc.connect_after("loaded", self.on_document_loaded) #workaround for the buf introduced in 3.14			
		doc.connect("saved", self.on_document_saved)

		tab.get_view().set_show_line_marks(True)
		mark_attributes = GtkSource.MarkAttributes()
		mark_attributes.set_stock_id(Gtk.STOCK_CANCEL)
		mark_attributes.connect("query_tooltip_text", self.tooltip_callback )
		tab.get_view().set_mark_attributes("vhdl", mark_attributes, 1) 
Example #4
0
    def gtk_initialize(self):
        self.frame = None

        self.do_step = Invoker("step")
        self.do_next = Invoker("next")
        self.do_continue = Invoker("continue")
        self.do_finish = Invoker("finish")
        self.do_stop = Invoker("interrupt")
        self.do_up = FrameCommandInvoker("up")
        self.do_down = FrameCommandInvoker("down")

        builder = gui.startup.create_builder('sourcewindow.xml')
        builder.connect_signals(self)
        self.window = builder.get_object("sourcewindow")
        self.view = builder.get_object("view")

        # Maybe there is a cleaner way?
        self.buttons = {}
        for name in BUTTON_NAMES:
            self.buttons[name] = builder.get_object(name)

        self.view.modify_font(gui.params.font_manager.get_font())
        self.view.set_show_line_numbers(gui.params.line_numbers.value)
        self.view.set_tab_width(gui.params.tab_width.value)

        attrs = GtkSource.MarkAttributes()
        attrs.set_pixbuf(self._get_pixmap('icons/ok.png'))
        self.view.set_mark_attributes('executable', attrs, 0)

        attrs = GtkSource.MarkAttributes()
        attrs.set_pixbuf(self._get_pixmap('icons/breakpoint-marker.png'))
        self.view.set_mark_attributes('breakpoint', attrs, 1)

        attrs = GtkSource.MarkAttributes()
        attrs.set_pixbuf(self._get_pixmap('icons/line-pointer.png'))
        self.view.set_mark_attributes('pointer', attrs, 2)

        self.view.set_buffer(buffer_manager.get_empty_buffer())
        lru_handler.add(self)
Example #5
0
    def __init__(self):
        Gtk.VBox.__init__(self)
        self._gdb = None
        self.toolbar = Gtk.Toolbar()
        self.btnLoad = Gtk.ToolButton(label="Load", stock_id=Gtk.STOCK_OPEN)
        self.btnSave = Gtk.ToolButton(label="Save", stock_id=Gtk.STOCK_SAVE)
        self.toolbar.add(self.btnLoad)
        self.toolbar.add(self.btnSave)

        self.toolbar.add(Gtk.SeparatorToolItem())

        self.btnStart = Gtk.ToolButton(label="(Re)Start",
                                       stock_id=Gtk.STOCK_MEDIA_PLAY)
        self.toolbar.add(self.btnStart)

        self.btnStep = Gtk.ToolButton(label="s",
                                      stock_id=Gtk.STOCK_MEDIA_FORWARD)
        self.toolbar.add(self.btnStep)

        self.btnContinue = Gtk.ToolButton(label="c",
                                          stock_id=Gtk.STOCK_MEDIA_NEXT)
        self.toolbar.add(self.btnContinue)

        self.editor = GtkSource.View(monospace=True,
                                     show_line_numbers=True,
                                     show_line_marks=True,
                                     tab_width=4,
                                     auto_indent=True,
                                     insert_spaces_instead_of_tabs=True,
                                     show_right_margin=True,
                                     smart_backspace=True,
                                     highlight_current_line=True)

        self.code = GtkSource.Buffer(language=get_gtk_language("cpp"))

        self.editor.set_buffer(self.code)

        # register breakpoints
        mark_attributes = GtkSource.MarkAttributes()
        mark_attributes.set_icon_name(Gtk.STOCK_STOP)
        self.editor.set_mark_attributes(CATEGORY_BREAKPOINT, mark_attributes,
                                        1)

        # register exec marker
        mark_attributes = GtkSource.MarkAttributes()
        mark_attributes.set_icon_name(Gtk.STOCK_GO_FORWARD)
        mark_attributes.set_background(Gdk.RGBA(0, 1, 0, 1))
        self.editor.set_mark_attributes(CATEGORY_EXEC_MARKER, mark_attributes,
                                        0)

        self.editor.connect("line-mark-activated", self.on_line_mark)

        self.pack_start(self.toolbar, expand=False, fill=False, padding=0)
        self.pack_start(self.editor, expand=True, fill=True, padding=2)

        self.btnLoad.connect("clicked", self.load_interactive)
        self.btnSave.connect("clicked", self.save_interactive)

        self.btnStart.connect("clicked", self.gdb_run)
        self.btnStep.connect("clicked", self.gdb_step)
        self.btnContinue.connect("clicked", self.gdb_continue)

        self._breakpoints = dict()
Example #6
0
    def __init__(self, view, attrs):
        super(SourceView, self).__init__(view, attrs)

        vbox = gtk.VBox(homogeneous=False, spacing=2)
        sc_editor = gtk.ScrolledWindow()
        sc_editor.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sc_editor.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        sc_editor.set_size_request(-1, 80)

        language_manager = gtksourceview.LanguageManager.get_default()
        python = language_manager.get_language('python')
        self.sourcebuffer = gtksourceview.Buffer(language=python)
        self.sourcebuffer.connect('changed', self._clear_marks)

        self.sourceview = gtksourceview.View.new_with_buffer(self.sourcebuffer)
        self.sourceview.connect('focus-out-event',
                                lambda x, y: self._focus_out())
        self.sourceview.connect('key-press-event', self.send_modified)
        self.sourceview.connect('key-press-event', self._test_check)
        self.sourceview.set_insert_spaces_instead_of_tabs(True)
        self.sourceview.set_tab_width(4)
        self.sourceview.set_auto_indent(True)
        self.sourceview.set_show_line_numbers(True)
        self.sourceview.set_show_line_marks(True)

        tag_table = self.sourcebuffer.get_tag_table()
        for mark_type, (priority, stock_id) in list(MARKS.items()):
            mark_attrs = gtksourceview.MarkAttributes()
            mark_attrs.set_icon_name(stock_id)
            self.sourceview.set_mark_attributes(mark_type, mark_attrs,
                                                priority)
            tag = gtk.TextTag(name=mark_type)
            if mark_type in (ERROR, SYNTAX):
                tag.props.underline = pango.UNDERLINE_ERROR
                tag.props.underline_set = True
            tag_table.add(tag)

        mono_desc = pango.FontDescription('monospace')
        if mono_desc:
            self.sourceview.modify_font(mono_desc)

        sc_editor.add(self.sourceview)

        toolbar = gtk.Toolbar()
        undo_btn = gtk.ToolButton('gtk-undo')
        undo_btn.connect('clicked', self.undo)
        toolbar.insert(undo_btn, -1)
        redo_btn = gtk.ToolButton('gtk-redo')
        redo_btn.connect('clicked', self.redo)
        toolbar.insert(redo_btn, -1)
        #check_btn = gtk.ToolButton(label='Check Code')
        check_btn = gtk.ToolButton('gtk-apply')
        check_btn.connect('clicked', self.check_code)
        toolbar.insert(check_btn, -1)

        self.error_store = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING,
                                         gobject.TYPE_STRING)

        error_list = gtk.TreeView(self.error_store)
        error_list.set_enable_search(False)
        line_col = gtk.TreeViewColumn(_('L'))
        renderer = gtk.CellRendererText()
        line_col.pack_start(renderer, True)
        line_col.add_attribute(renderer, 'text', 0)
        line_col.add_attribute(renderer, 'cell-background', 2)
        error_list.append_column(line_col)
        error_col = gtk.TreeViewColumn(_('Message'))
        renderer = gtk.CellRendererText()
        error_col.pack_start(renderer, True)
        error_col.add_attribute(renderer, 'text', 1)
        error_col.add_attribute(renderer, 'cell-background', 2)
        error_list.append_column(error_col)
        sc_error = gtk.ScrolledWindow()
        sc_error.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        sc_error.add_with_viewport(error_list)
        self.error_tree = sc_error

        error_selection = error_list.get_selection()
        error_selection.connect_after('changed', self.focus_line)

        vbox.pack_start(toolbar, expand=False, fill=True)
        vbox.pack_start(sc_editor, expand=True, fill=True)
        vbox.pack_start(sc_error, expand=True, fill=True)
        vbox.show_all()

        self.tree_data_field = attrs.get('context_tree')
        if self.tree_data_field:
            sc_tree = gtk.ScrolledWindow()
            sc_tree.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
            sc_tree.set_shadow_type(gtk.SHADOW_ETCHED_IN)
            sc_tree.set_size_request(-1, 30)

            self.model = gtk.TreeStore(gobject.TYPE_PYOBJECT,
                                       gobject.TYPE_STRING)
            self.treeview = gtk.TreeView(self.model)
            self.treeview.set_headers_visible(False)
            self.treeview.set_tooltip_column(1)
            self.treeview.connect('query-tooltip', self.tree_display_tooltip)
            tree_cell = gtk.CellRendererText()
            tree_col = gtk.TreeViewColumn('Objects')
            tree_col.pack_start(tree_cell)

            def cell_setter(column, cell, store, iter):
                if not self.treeview.get_realized():
                    return
                record = store.get_value(iter, 0)
                cell.set_property('text', record['description'])

            tree_col.set_cell_data_func(tree_cell, cell_setter)
            self.treeview.append_column(tree_col)

            target_entry = gtk.TargetEntry('TREE_ROW', gtk.TARGET_SAME_APP, 0)

            self.treeview.drag_source_set(gdk.ModifierType.BUTTON1_MASK,
                                          [target_entry], gdk.DragAction.COPY)
            self.sourceview.drag_dest_set(gtk.DEST_DEFAULT_ALL, [target_entry],
                                          gdk.DragAction.COPY)
            self.treeview.connect('drag-data-get', self.drag_data_get)
            self.sourceview.connect('drag-data-received',
                                    self.drag_data_received_data)

            self.sourceview.connect('drag-drop', self.drag_drop)

            self.sourceview.drag_dest_set_target_list(None)
            self.treeview.drag_source_set_target_list(None)
            self.sourceview.drag_dest_add_text_targets()
            self.treeview.drag_source_add_text_targets()

            self.treeview.show_all()
            sc_tree.add(self.treeview)

            self.widget = gtk.HPaned()
            self.widget.pack1(sc_tree)
            self.widget.pack2(vbox)
            self.widget.set_position(250)
        else:
            self.widget = vbox

        self.tree_data = []
        self.known_funcs = set()
Example #7
0
 def add_mark_category(self, category, bg_color):
     att = GtkSource.MarkAttributes()
     color = Gdk.RGBA()
     color.parse(bg_color)
     att.set_background(color)
     self.set_mark_attributes(category, att, 1)
Example #8
0
    def do_live_linting(self, *args):

        #print('Lint called and: {}, has file? {}'.format(self.fileChanged, self.curFile is not None))

        if self.fileChanged and self.curFile is not None:

            self.fileChanged = False

            # Stuff

            # command = "clang-check /tmp/pyidetmp/*.* --"
            # process = subprocess.Popen(command.split(), cwd=self.parent.projectPath, stdout=subprocess.PIPE)
            #
            # output, error = process.communicate()

            with open(
                    '/tmp/pyidetmp/' +
                    self.curFile.replace(self.parent.projectPath, ''),
                    'w+') as f:
                f.write(self.parent.getCurrentText())

            #output = os.system("clang-check `find /tmp/pyidetmp | egrep '\.(c|h|cpp)$'` --")

            files = subprocess.check_output(
                "find /tmp/pyidetmp | egrep '\.(c|h|cpp)$'", shell=True)

            files = list(filter(
                None,
                files.decode('utf-8').split(
                    '\n')))  # Get the files filtering possible empty results

            filesStr = ' '.join(
                files)  # files array to string separated by spaces

            self.parent.sbuff.remove_tag_by_name(
                'error-tag', self.parent.sbuff.get_start_iter(),
                self.parent.sbuff.get_end_iter())

            try:
                res = subprocess.check_output("clang-check " + filesStr +
                                              ' --',
                                              stderr=subprocess.STDOUT,
                                              shell=True)

                self.errors = 0
                self.parent.stateEntry.set_icon_from_icon_name(
                    Gtk.EntryIconPosition.SECONDARY, 'emblem-ok-symbolic')
                self.linterModule.set_errors(self.errors)

            except subprocess.CalledProcessError as e:
                output = e.output.decode('utf-8')

                output = output.replace('/tmp/pyidetmp',
                                        self.parent.projectPath)

                lin = [
                    l for l in output.split('\n')
                    if re.match('[0-9]+ (error|errors) generated.', l)
                ]

                #print('Output: {},,,, Lin: {}'.format(output, lin))

                errors = None

                if len(lin) > 0:
                    errors = lin[0].split(' ')[0]
                else:
                    errors = 0

                print(self.parent.projectPath + '/[a-zA-Z0-9.]')

                errorPos = [
                    [l.split(':')[1], l.split(':')[2]]
                    for l in output.split('\n')
                    if re.match(self.parent.projectPath + '/[a-zA-Z0-9.]', l)
                ]

                errorMark = GtkSource.Mark.new('error', 'error-category')
                errorMarkAttr = GtkSource.MarkAttributes()
                errorMarkAttr.set_icon_name('dialog-warning-symbolic')

                for arr in errorPos:
                    sit = self.parent.sbuff.get_iter_at_line_offset(
                        int(arr[0]) - 1, 0)
                    eit = self.parent.sbuff.get_iter_at_line_offset(
                        int(arr[0]) - 1, int(arr[1]))
                    self.parent.sbuff.apply_tag_by_name('error-tag', sit, eit)

                print(errorPos)

                self.errors = errors

                self.parent.stateEntry.set_icon_from_icon_name(
                    Gtk.EntryIconPosition.SECONDARY, 'dialog-error-symbolic')
                self.parent.stateEntry.set_icon_activatable(
                    Gtk.EntryIconPosition.SECONDARY, True)
                self.parent.stateEntry.connect(
                    'icon-press', self.linterModule.show_linter_pop)

                self.linterModule.set_errors(errors)

                print('Errors: {}'.format(errors))

            self.parent.stateEntry.set_text(
                '{} error found.'.format(self.errors) if int(self.errors) ==
                1 else 'No errors found.' if self.errors ==
                0 else '{} errors found.'.format(self.errors))

            if not self.task is None:
                self.task.cancel()

            self.task = Timer(self.liveDelay, self.do_live_linting)
            self.task.start()