Exemplo n.º 1
0
    def set_language(self, key):
        manager = GtkSource.LanguageManager()
        language = manager.get_language(key)

        self.start_undoable()
        self.get_buffer().set_language(language)
        self.stop_undoable()
Exemplo n.º 2
0
    def __init__(self, config, begin, end):
        super(changesWindow, self).__init__()
        builder = Gtk.Builder()
        GObject.type_register(GtkSource.View)
        builder.add_from_file(
            pkg_resources.resource_filename("snappergui",
                                            "glade/changesWindow.glade"))

        builder.get_object("titlelabel").set_text("%s -> %s" % (begin, end))
        self.window = builder.get_object("changesWindow")
        self.statusbar = builder.get_object("statusbar1")
        self.pathstreeview = builder.get_object("pathstreeview")
        self.fileview = builder.get_object("fileview")
        self.choicesviewgroup = builder.get_object("actiongroup")
        builder.connect_signals(self)

        # save mountpoints for begin and end snapshots
        self.beginpath = snapper.GetMountPoint(config, begin)
        self.endpath = snapper.GetMountPoint(config, end)
        self.config = config
        self.snapshot_begin = begin
        self.snapshot_end = end

        self.choicesviewgroup.get_action("begin").set_label(str(begin))
        self.choicesviewgroup.get_action("end").set_label(str(end))

        self.sourcebuffer = GtkSource.Buffer()
        self.fileview.set_buffer(self.sourcebuffer)

        self.window.show_all()
        GObject.idle_add(self.on_idle_init_paths_tree)
Exemplo n.º 3
0
 def __init__(self, note):
     """Initializes the stickynotes window"""
     self.path = os.path.abspath(
         os.path.join(os.path.dirname(__file__), '..'))
     self.note = note
     self.noteset = note.noteset
     self.locked = self.note.properties.get("locked", False)
     self.builder = Gtk.Builder()
     GObject.type_register(GtkSource.View)
     self.builder.add_from_file(os.path.join(self.path,
                                             "StickyNotes.glade"))
     self.builder.connect_signals(self)
     # Get necessary objects
     self.winMain = self.builder.get_object("MainWindow")
     self.winMain.set_name("main-window")
     widgets = [
         "txtNote", "bAdd", "imgAdd", "imgResizeR", "eResizeR", "bLock",
         "imgLock", "imgUnlock", "bClose", "confirmDelete"
     ]
     for w in widgets:
         setattr(self, w, self.builder.get_object(w))
     # Create menu
     self.menu = Gtk.Menu()
     self.populate_menu()
     # Load CSS template and initialize Gtk.CssProvider
     with open(os.path.join(self.path, "style.css")) as css_file:
         self.css_template = Template(css_file.read())
     self.css = Gtk.CssProvider()
     self.style_contexts = [
         self.winMain.get_style_context(),
         self.txtNote.get_style_context()
     ]
     # Update window-specific style. Global styles are loaded initially!
     self.update_style()
     self.update_font()
     # Ensure buttons are displayed with images
     settings = Gtk.Settings.get_default()
     settings.props.gtk_button_images = True
     # Set text buffer
     self.bbody = GtkSource.Buffer()
     self.bbody.begin_not_undoable_action()
     self.bbody.set_text(self.note.body)
     self.bbody.set_highlight_matching_brackets(False)
     self.bbody.end_not_undoable_action()
     self.txtNote.set_buffer(self.bbody)
     # Make resize work
     self.winMain.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
     self.eResizeR.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
     # Move Window
     self.winMain.move(*self.note.properties.get("position", (10, 10)))
     self.winMain.resize(*self.note.properties.get("size", (200, 150)))
     # Show the window
     self.winMain.show()
     # Mouse over
     self.eResizeR.get_window().set_cursor(
         Gdk.Cursor.new_for_display(
             self.eResizeR.get_window().get_display(),
             Gdk.CursorType.BOTTOM_RIGHT_CORNER))
     # Set locked state
     self.set_locked_state(self.locked)
Exemplo n.º 4
0
    def __init__(self, find_widget, wrap_widget, find_box_widget,
                 replace_box_widget, match_case_checkbox, whole_word_checkbox,
                 regex_checkbox):
        self.widget = find_widget
        self.search_context = None
        self.wrap_widget = wrap_widget
        self.find_box_widget = find_box_widget
        self.replace_box_widget = replace_box_widget
        self.is_searching_backwards = False
        self.text_view = None

        self.search_settings = GtkSource.SearchSettings()
        match_case_checkbox.bind_property('active', self.search_settings,
                                          'case-sensitive')
        whole_word_checkbox.bind_property('active', self.search_settings,
                                          'at-word-boundaries')
        regex_checkbox.bind_property('active', self.search_settings,
                                     'regex-enabled')
        self.find_box_widget.bind_property('text', self.search_settings,
                                           'search-text')

        self.search_settings.set_wrap_around(True)
        self.widget.connect('key-press-event', self.on_find_bar_key_press)
        self.find_box_widget.connect('key-press-event',
                                     self.on_find_box_key_press)
        self.find_box_widget.connect('key-release-event',
                                     self.on_find_box_key_release)
Exemplo n.º 5
0
 def __init__(self):
     GtkSource.Buffer.__init__(self)
     self.language = None
     self.language_setted = False
     self.languages = [_("Plain text")]
     self.language_manager = GtkSource.LanguageManager()
     self.languages.extend(self.language_manager.get_language_ids())
Exemplo n.º 6
0
    def get_buffer(self, symtab, filename):
        if filename in self.buffers:
            return self.buffers[filename]

        if not self.lang_manager:
            self.lang_manager = GtkSource.LanguageManager.get_default()

        buff = GtkSource.Buffer()
        if filename:
            buff.set_language(self.lang_manager.guess_language(filename))
        buff.set_style_scheme(gui.params.source_theme.get_scheme())
        buff.begin_not_undoable_action()
        try:
            contents = open(filename).read()
        except:
            return None
        buff.set_text(contents)
        buff.end_not_undoable_action()
        buff.set_modified(False)
        buff.filename = filename

        if symtab is not None:
            gdb.post_event(lambda: self._get_lines_update(buff, symtab))

        self.buffers[filename] = buff
        return buff
Exemplo n.º 7
0
    def _create_editor(self):

        editor = GtkSource.View()

        editor.set_cursor_visible(True)
        editor.set_show_line_numbers(True)  # 显示行号
        editor.set_auto_indent(True)  # 自动缩进
        #editor.set_insert_spaces_instead_of_tabs(True) # 用空格代替tab
        editor.set_tab_width(4)  # tab宽度4
        editor.set_highlight_current_line(True)  # 高亮度显示当前行

        self._ide_set_font(editor, "Ubuntu mono 12")  # 设置字体。

        # 左边的标记区域
        gutter = editor.get_gutter(Gtk.TextWindowType.LEFT)
        gutter.set_padding(5, 0)

        src_buffer = self._create_buffer(None)
        editor.set_buffer(src_buffer)

        scrolledCtrl = Gtk.ScrolledWindow()
        scrolledCtrl.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        scrolledCtrl.set_hexpand(True)
        scrolledCtrl.set_vexpand(True)
        scrolledCtrl.add(editor)

        return (scrolledCtrl, editor)
Exemplo n.º 8
0
    def do_create_configure_widget(self):
        box = Gtk.Box()
        language_manager = GtkSource.LanguageManager()
        self.undecided = []
        for id in language_manager.get_language_ids():
            if id not in whitelist and id not in blacklist:
                self.undecided.append(id)

        self.whitelist_widget = ListWidget(whitelist, 'Always wrap',
                                           'whitelist.json')
        self.blacklist_widget = ListWidget(blacklist, 'Never wrap',
                                           'blacklist.json')
        self.undecided_widget = ListWidget(self.undecided)

        self.button_add_whitelist = Gtk.Button('<')
        self.button_remove_whitelist = Gtk.Button('>')
        self.button_add_blacklist = Gtk.Button('>')
        self.button_remove_blacklist = Gtk.Button('<')

        self.button_add_whitelist.connect('clicked', self.whitelist_add)
        self.button_remove_whitelist.connect('clicked', self.whitelist_remove)
        self.button_add_blacklist.connect('clicked', self.blacklist_add)
        self.button_remove_blacklist.connect('clicked', self.blacklist_remove)

        box.add(self.whitelist_widget)
        box.add(self.button_add_whitelist)
        box.add(self.button_remove_whitelist)
        box.add(self.undecided_widget)
        box.add(self.button_remove_blacklist)
        box.add(self.button_add_blacklist)
        box.add(self.blacklist_widget)

        box.set_size_request(500, 700)
        return box
Exemplo n.º 9
0
 def addEditPage(self, path: str):
     scrolled_window = Gtk.ScrolledWindow()
     src_view = GtkSource.View()
     src_view.set_show_line_numbers(True)
     src_view.set_highlight_current_line(True)
     src_view.set_auto_indent(True)
     src_view.set_monospace(True)
     src_view.set_vexpand(True)
     buf = src_view.get_buffer()
     lua_lang = self.src_lang_manager.get_language("lua")
     # print(f"Schemes: {self.scheme_manager.get_scheme_ids()}")
     scheme = self.scheme_manager.get_scheme("oblivion")
     buf.set_language(lua_lang)
     buf.set_style_scheme(scheme)
     with open(path) as f:
         buf.set_text(f.read())
     name = os.path.basename(path)
     notebook = self.builder.get_object("edit_notebook")
     scrolled_window.add(src_view)
     notebook.append_page(scrolled_window, Gtk.Label(name))
     notebook.show_all()
     pagenr = len(self.edit_pages)
     notebook.set_current_page(pagenr)
     self.edit_pages.append(path)
     sname = HawckMainWindow.getScriptName(path)
     self.scripts[sname] = {
         "pagenr": pagenr,
         "buffer": buf,
         "view": src_view
     }
Exemplo n.º 10
0
 def __init__(self):
     super().__init__(application_id='mlv.knrf.pastebinReader')
     GLib.set_application_name('Pastebin Reader')
     GLib.set_prgname('mlv.knrf.pastebinReader')
     self.backend  = App_Backend()
     self.cat_name = "javascript"
     self.lang_mang = GtkSource.LanguageManager()
    def do_activate(self):
        self.tab = self.view.get_parent().get_parent().get_parent()
        self.tab.set_orientation(Gtk.Orientation.HORIZONTAL)

        # hide vertical scrollbar
        self.scrolled = self.view.get_parent()
        self.scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,
                                 Gtk.PolicyType.EXTERNAL)

        self.source_map = GtkSource.Map()
        self.set_font_desc()
        self.source_map.set_view(self.view)
        self.source_map.show()

        self.sep = Gtk.Separator()
        self.tab.pack_end(self.sep, False, True, 0)
        self.tab.pack_end(self.source_map, False, True, 0)

        self.update_display_on_left()
        self.on_separator_changed()
        if settings is not None:
            self.settings_handlers = [
                settings.connect('changed::display-on-left',
                                 self.on_display_on_left_changed),
                settings.connect('changed::show-separator',
                                 self.on_separator_changed)
            ]
Exemplo n.º 12
0
    def __init__(self, window, method):
        """
        creates an entire function new-tab
        :param window: the Main Window in main.py
        :param method: action type (create)
        :return: Gtk.Grid that can be packed directly into a tab
        """
        fc = FileChooser(window, method)
        response = fc.run()

        if response == Gtk.ResponseType.OK:
            print("File Selected : %s" % fc.get_filename())
        self.filename = fc.get_filename()
        fc.close()
        footer.Footer.__init__(self)
        Gtk.Grid.__init__(self)
        core.Language.__init__(self)
        self.code = GtkSource.View()
        self.language = None
        self.terminal = terminal.Terminal()
        self.revealer = Gtk.Revealer()
        self.revealer.set_reveal_child(True)

        # add customization
        self.customize()
        Tabs.page_count += 1

        # pack everything into self (Gtk.Grid)
        self.get_packed()
Exemplo n.º 13
0
    def __init__(self, file_path, lenguaje, texto):

        GtkSource.View.__init__(self)

        self.file_path = file_path
        manager = GtkSource.LanguageManager()
        self.set_buffer(GtkSource.Buffer())
        self.set_insert_spaces_instead_of_tabs(True)
        self.set_tab_width(4)
        #self.set_auto_indent(True)
        #self.set_smart_home_end(True)
        self.set_highlight_current_line(True)
        self.get_buffer().set_highlight_syntax(True)
        self.get_buffer().set_language(manager.get_language(lenguaje))
        self.get_buffer().set_text(texto)
        self.show_all()
Exemplo n.º 14
0
    def __init__(self, filediff):
        super().__init__("patch-dialog.ui", "patchdialog")

        self.widget.set_transient_for(filediff.widget.get_toplevel())
        self.filediff = filediff

        buf = GtkSource.Buffer()
        self.textview.set_buffer(buf)
        lang = LanguageManager.get_language_from_mime_type("text/x-diff")
        buf.set_language(lang)
        buf.set_highlight_syntax(True)

        self.textview.modify_font(meldsettings.font)
        self.textview.set_editable(False)

        self.index_map = {
            self.left_radiobutton: (0, 1),
            self.right_radiobutton: (1, 2)
        }
        self.left_patch = True
        self.reverse_patch = self.reverse_checkbutton.get_active()

        if self.filediff.num_panes < 3:
            self.side_selection_label.hide()
            self.side_selection_box.hide()

        meldsettings.connect('changed', self.on_setting_changed)
Exemplo n.º 15
0
    def __init__(self, config):

        GtkSource.View.__init__(self)

        self.actualizador = False
        self.control = False
        self.archivo = False
        self.lenguaje = False
        self.tab = "    "

        self.set_show_line_numbers(config['numeracion'])

        self.lenguaje_manager = GtkSource.LanguageManager()

        self.lenguajes = {}
        for _id in self.lenguaje_manager.get_language_ids():
            lang = self.lenguaje_manager.get_language(_id)
            self.lenguajes[_id] = lang.get_mime_types()

        self.set_insert_spaces_instead_of_tabs(True)
        self.set_tab_width(4)
        self.set_show_right_margin(True)
        self.set_auto_indent(True)
        self.set_smart_home_end(True)
        self.set_highlight_current_line(True)
        #self.set_accepts_tab(True)
        #self.set_pixels_above_lines(5)

        font = "%s %s" % (config['fuente'], config['tamanio'])
        self.modify_font(Pango.FontDescription(font))

        self.show_all()

        self.connect("key-press-event", self.__key_press_event)
Exemplo n.º 16
0
    def __init__(self, parent):
        super().__init__()
        self.init_template()

        self.search_context = None
        self.notify_id = None
        self.set_text_view(None)

        # Setup a signal for when the find bar loses focus
        parent.connect('set-focus-child', self.on_focus_child)

        # Create and bind our GtkSourceSearchSettings
        settings = GtkSource.SearchSettings()
        self.match_case.bind_property('active', settings, 'case-sensitive')
        self.whole_word.bind_property('active', settings, 'at-word-boundaries')
        self.regex.bind_property('active', settings, 'regex-enabled')
        self.find_entry.bind_property('text', settings, 'search-text')
        settings.set_wrap_around(True)
        self.search_settings = settings

        # Bind visibility and layout for find-and-replace mode
        self.bind_property('replace_mode', self.replace_entry, 'visible')
        self.bind_property('replace_mode', self.replace_all_button, 'visible')
        self.bind_property('replace_mode', self.replace_button, 'visible')
        self.bind_property(
            'replace_mode', self, 'row-spacing', GObject.BindingFlags.DEFAULT,
            lambda binding, replace_mode: 6 if replace_mode else 0)
Exemplo n.º 17
0
    def on_row_activated(self, listbox, cell, listboxrow):

        try:
            self.save_note('', '', '', '', self.id)
            self.scrolledwindow.destroy()
        except:
            pass

        (model, pathlist) = listbox.get_selection().get_selected_rows()
        for path in pathlist:

            tree_iter = model.get_iter(path)
            id = model.get_value(tree_iter, 1)

            nota = self.database.get_note(id)

            self.scrolledwindow = Gtk.ScrolledWindow()
            self.scrolledwindow.set_hexpand(True)
            self.scrolledwindow.set_vexpand(True)

            self.note_box = GtkSource.View()
            textbuffer = self.note_box.get_buffer()
            textbuffer.set_text(nota.text)
            self.notestree = Gtk.TreeView(model=self.notes_liststore)
            self.note_box.set_show_line_numbers(True)

            self.scrolledwindow.add(self.note_box)
            self.note_box.show()
            self.scrolledwindow.show()

            self.notes_view.add(self.scrolledwindow)
            self.note_box.connect("move-cursor", self.save_note, id)

            self.id = id
Exemplo n.º 18
0
    def build_note(self):
        self.builder = Gtk.Builder()
        GObject.type_register(GtkSource.View)
        self.builder.add_from_file(os.path.join(self.path, "StickyNotes.ui"))
        self.builder.connect_signals(self)
        self.winMain = self.builder.get_object("MainWindow")

        # Get necessary objects
        self.winMain.set_name("main-window")
        widgets = [
            "txtNote", "bAdd", "imgAdd", "imgResizeR", "eResizeR", "bLock",
            "imgLock", "imgUnlock", "imgClose", "imgDropdown", "bClose",
            "confirmDelete", "movebox1", "movebox2"
        ]
        for w in widgets:
            setattr(self, w, self.builder.get_object(w))
        self.style_contexts = [
            self.winMain.get_style_context(),
            self.txtNote.get_style_context()
        ]
        # Update window-specific style. Global styles are loaded initially!
        self.update_style()
        self.update_font()
        # Ensure buttons are displayed with images
        settings = Gtk.Settings.get_default()
        settings.props.gtk_button_images = True
        # Set text buffer
        self.bbody = GtkSource.Buffer()
        self.bbody.begin_not_undoable_action()
        self.bbody.set_text(self.note.body)
        self.bbody.set_highlight_matching_brackets(False)
        self.bbody.end_not_undoable_action()
        self.txtNote.set_buffer(self.bbody)
        # Make resize work
        self.winMain.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.eResizeR.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        # Move Window
        self.winMain.move(*self.note.properties.get("position", (10, 10)))
        self.winMain.resize(*self.note.properties.get("size", (200, 150)))
        # Show the window
        self.winMain.set_skip_pager_hint(True)
        self.winMain.show_all()
        # Mouse over
        self.eResizeR.get_window().set_cursor(
            Gdk.Cursor.new_for_display(
                self.eResizeR.get_window().get_display(),
                Gdk.CursorType.BOTTOM_RIGHT_CORNER))
        # Set locked state
        self.set_locked_state(self.locked)

        # call set_keep_above just to have the note appearing
        # above everything else.
        # without it, it still won't appear above a window
        # in which a cursor is active
        self.winMain.set_keep_above(True)

        # immediately undo the set keep above after the window
        # is shown, so that windows won't stay up if we switch to
        # a different window
        self.winMain.set_keep_above(False)
Exemplo n.º 19
0
	def set_auto_completation(self):
		"""
		1)
		Set up a provider that get words from what has already been entered
		in the gtkSource.Buffer that is tied to the GtkSourceView
		2)
		Set up a second buffer that stores the keywords we want to be available
		3)
		Setup an instance of our custome completion class to handle special characters with
		auto complete.
		"""
		# This gets the GtkSourceView completion that's already tied to the GtkSourceView
		# We need it to attached our providers to it
		self.gsv_completion = self.editor.get_completion()

		# 1) Make a new provider, attach it to the main buffer add to view_autocomplete
		self.gsv_autocomplete = GtkSource.CompletionWords.new('main')
		self.gsv_autocomplete.register(self.textbuff)
		self.gsv_completion.add_provider(self.gsv_autocomplete)

		# 2) Make a new buffer, add a str to it, make a provider, add it to the view_autocomplete
		self.keybuff = GtkSource.Buffer()
		self.keybuff.begin_not_undoable_action()
		self.keybuff.set_text(self.keywords)
		self.keybuff.end_not_undoable_action()
		self.gsv_keyword_complete = GtkSource.CompletionWords.new('keyword')
		self.gsv_keyword_complete.register(self.keybuff)
		self.gsv_completion.add_provider(self.gsv_keyword_complete)

		# 3) Set up our custom provider for syntax completion.
		custom_completion_provider = CustomCompletionProvider()
		self.gsv_completion.add_provider(custom_completion_provider)
		self.custom_completion_provider = custom_completion_provider
		return
Exemplo n.º 20
0
def read_file_contents(filename,
                       parent_names,
                       buffer,
                       load_file_cb,
                       in_trash=False):
    parent_dir = sep.join(parent_names)
    fpath = join(BASE_TEXT_DIR, parent_dir, filename)
    if in_trash:
        fpath = join(TRASH_DIR, filename)

    def load_finish_cb(loader, res, user_data):
        gsf = user_data
        try:
            success = loader.load_finish(res)
        except Exception as e:
            # TODO: Warn file read error so overwriting path with blank file...
            write_to_file(gsf.get_location(), "")
        finally:
            load_file_cb(gsf, buffer)

    f = Gio.File.new_for_path(fpath)
    gsf = GtkSource.File(location=f)
    loader = GtkSource.FileLoader.new(buffer, gsf)
    loader.load_async(GLib.PRIORITY_HIGH, None, None, None, load_finish_cb,
                      gsf)
Exemplo n.º 21
0
    def add_note(self, widget):
        """ add a note to the db """

        try:
            self.scrolledwindow.destroy()
        except:
            pass

        title, id = self.database.add_note(self.host.id, "note " +
                                           str(len(self.notes_liststore)),
                                           "")  # FIXME
        self.notes_liststore.append([title, id])

        self.scrolledwindow = Gtk.ScrolledWindow()
        self.scrolledwindow.set_hexpand(True)
        self.scrolledwindow.set_vexpand(True)

        self.note_box = GtkSource.View()
        textbuffer = self.note_box.get_buffer()
        textbuffer.set_text("")
        self.notestree = Gtk.TreeView(model=self.notes_liststore)
        self.note_box.set_show_line_numbers(True)

        self.scrolledwindow.add(self.note_box)
        self.note_box.show()
        self.scrolledwindow.show()

        self.notes_view.add(self.scrolledwindow)

        self.note_box.connect("move-cursor", self.save_note, id)

        self.id = id
Exemplo n.º 22
0
 def __init__(self, ventana, firmware_ruta, nombre_arch, carga_buf):
     # create buffer
     lm = GtkSource.LanguageManager.get_default()
     self.firmware_ruta = firmware_ruta
     self.nombre_arch = nombre_arch
     view = GtkSource.View()
     #view = Gtk.TextView()#buffer=lm)
     self.buffer = view.get_buffer()
     self.buffer.set_language(lm.get_language(carga_buf))
     self.buffer.set_highlight_syntax(True)
     view.set_show_line_numbers(True)
     self.ventana = ventana
     self.vbox = Gtk.VBox(0, True)
     #notebook.append_page(vbox, Gtk.Label(etiqueta))
     #tool1 = Gtk.Toolbar()
     #tool1.show()
     #self.vbox.pack_start(tool1, False, False,1)
     sw = Gtk.ScrolledWindow()
     sw.add(view)
     self.vbox.pack_start(sw, True, True, 1)
     self.vbox.show_all()
     # main loop
     self.dir_conf = os.path.expanduser(
         '~') + "/" + self.firmware_ruta + "/firmware/"
     self.cadena_user_c = self.dir_conf + self.nombre_arch
     self.buf = self.open_file(self.buffer, self.cadena_user_c)
Exemplo n.º 23
0
    def __init__(self, main_window, codes):
        """
        This method is the constructor.
        """
        Gtk.Dialog.__init__(
            self, "Code Window", main_window,
            Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
            (Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.codes = codes
        self.main_window = main_window
        self.set_default_size(800, 600)
        box = self.get_content_area()
        vbox = Gtk.VBox()
        box.pack_start(vbox, True, True, 0)

        toolbar = Gtk.Toolbar()
        toolbar.set_style(Gtk.ToolbarStyle.BOTH)
        toolbar.set_hexpand(False)
        toolbar.set_property("expand", False)
        vbox.pack_start(toolbar, False, False, 0)

        button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_SAVE_AS)
        button.set_expand(False)
        button.set_label(_("Save Source"))
        button.set_is_important(True)
        button.connect("clicked", self.__save_button_clicked, None)
        toolbar.add(button)

        button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_EXECUTE)
        button.set_expand(False)
        button.set_label(_("Run this code"))
        button.set_is_important(True)
        button.connect("clicked", self.__run_button_clicked, None)
        toolbar.add(button)

        self.notebook = Gtk.Notebook()
        vbox.pack_start(self.notebook, True, True, 0)

        self.buffers = {}

        for key in self.codes:
            code = self.codes[key]
            lang_manager = GtkSource.LanguageManager()
            textbuffer = GtkSource.Buffer.new_with_language(
                lang_manager.get_language('c'))
            textview = GtkSource.View.new_with_buffer(textbuffer)
            textview.set_show_line_numbers(True)
            textview.set_left_margin(10)
            textview.set_right_margin(10)
            textview.get_buffer().set_text(code)
            self.buffers[key] = textview.get_buffer()

            sw = Gtk.ScrolledWindow()
            sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            sw.add(textview)
            textview.show()
            self.notebook.append_page(sw, Gtk.Label(key))
        self.show_all()
Exemplo n.º 24
0
    def __init__(self):

        GtkSource.View.__init__(self)

        self.set_buffer(GtkSource.Buffer())
        from gi.repository import Pango
        self.modify_font(Pango.FontDescription('Monospace 10'))
        self.show_all()
Exemplo n.º 25
0
def set_sourceview_configuration(widget, editable=False):
    lenguage_managuer = GtkSource.LanguageManager()
    lenguage = lenguage_managuer.get_language("sql")
    buffer = widget.get_buffer()
    buffer.set_highlight_syntax(True)
    buffer.set_language(lenguage)      
        
    widget.set_show_line_numbers(True)
Exemplo n.º 26
0
    def __init__(self):
        GtkSource.View.__init__(self)

        language_manager = GtkSource.LanguageManager()
        self.get_buffer().set_language(language_manager.get_language("cpp"))
        self.get_buffer().set_highlight_syntax(True)
        self.modify_font(Pango.FontDescription("Monospace 10"))
        self.set_show_line_numbers(True)
Exemplo n.º 27
0
	def do_populate(self, context):
		proposals = []
			#GtkSource.CompletionItem(label='Hello World!', text='Hello World!', icon=None, info=None),  # always proposed
			#GtkSource.CompletionItem(label='[Paketci]', text='[Paketci]', icon=None, info=None)  # always proposed

		# found difference in Gtk Versions
		end_iter = context.get_iter()
		if not isinstance(end_iter, Gtk.TextIter):
			_, end_iter = context.get_iter()

		if end_iter:
			mps_list ={
				"[paket]":["tanim\t\t=","paketci\t\t=","grup\t\t\t=","url\t\t\t\t="],
				"[kaynak]":["gz\t\t\t\t=","xz\t\t\t\t=","dosya\t\t\t=","bz2\t\t\t\t=","github\t\t=","1\t\t\t\t\t=","2\t\t\t\t\t=","3\t\t\t\t\t="],
				"[sha256]":["1\t\t\t\t\t=","2\t\t\t\t\t=","3\t\t\t\t\t=","4\t\t\t\t\t=","5\t\t\t\t\t=","6\t\t\t\t\t="],
				"[derle]":["betik\t\t\t=","dosya\t\t\t=","yama\t\t\t=","tip\t\t\t\t=","ekconf\t\t="],
				"[pakur]":["tip\t\t\t\t=","dosya\t\t\t=","betik\t\t\t=","strip\t\t\t="]}


			buf = end_iter.get_buffer()
			mov_iter = end_iter.copy()
			if mov_iter.backward_search('[', Gtk.TextSearchFlags.VISIBLE_ONLY):
				mov_iter, _ = mov_iter.backward_search('[', Gtk.TextSearchFlags.VISIBLE_ONLY)
				left_text = buf.get_text(mov_iter, end_iter, True)
				text = left_text.split("\n")
				if len(text) == 1:
					for key in mps_list.keys():
						proposals.append(GtkSource.CompletionItem(label=key, text=key[1:], icon=None, info=None))
				elif text[0] == "[paket]" and "=" not in text[-1]:
					for key in mps_list["[paket]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
				elif text[0] == "[kaynak]" and "=" not in text[-1]:
					for key in mps_list["[kaynak]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
				elif text[0] == "[sha256]" and "=" not in text[-1]:
					for key in mps_list["[sha256]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
				elif text[0] == "[derle]" and "=" not in text[-1]:
					for key in mps_list["[derle]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
				elif text[0] == "[pakur]" and "=" not in text[-1]:
					for key in mps_list["[pakur]"]:
						proposals.append(GtkSource.CompletionItem(label=key, text=key, icon=None, info=None))
			else:
				left_text = ''

			if re.match(r'.*\{\{\s*custom\.$', left_text):
				proposals.append(
					GtkSource.CompletionItem(label='foo', text='foo }}')  # optionally proposed based on left search via regex
				)
				proposals.append(
					GtkSource.CompletionItem(label='bar', text='bar }}')  # optionally proposed based on left search via regex
				)

		context.add_proposals(self, proposals, True)
		return
Exemplo n.º 28
0
 def add_completion(self, header, words_arr):
     keybuff = GtkSource.Buffer()
     keybuff.begin_not_undoable_action()
     keybuff.set_text('\n'.join(words_arr))
     keybuff.end_not_undoable_action()
     autocomplete = GtkSource.CompletionWords.new(header)
     autocomplete.register(keybuff)
     self.custom_completors.append(autocomplete)
Exemplo n.º 29
0
    def __init__(self, *args, **kwargs):
        super(Notepad, self).__init__(*args, **kwargs)

        self.scrolled = Gtk.ScrolledWindow()
        self.scrolled.set_hexpand(True)
        self.scrolled.set_vexpand(True)
        self.sourceview = GtkSource.View()
        self.sourcebuffer = self.sourceview.get_buffer()
        self.sourceview.set_smart_home_end(0)
        self.sourceview.set_auto_indent(True)
        self.scrolled.add(self.sourceview)
        start, end = self.sourcebuffer.get_bounds()
        self.sourcebuffer.ensure_highlight(start, end)
        self.sourcesearch = GtkSource.SearchContext.new(self.sourcebuffer)
        self.sourcesearchsettings = GtkSource.SearchSettings()
        self.sourcesearchsettings.set_search_text("deneme")
        self.sourcesearch.set_settings(self.sourcesearchsettings) 

        self.searchtoolbar = Gtk.Toolbar()

        self.toolitem = Gtk.ToolItem()
        self.search_bar = Gtk.Entry()
        self.search_bar.set_width_chars(30)
        self.search_bar.connect("activate", self.search)
        self.toolitem.add(self.search_bar)
        self.searchtoolbar.insert(self.toolitem, 0)

        self.toolitem2 = Gtk.ToolItem()
        self.search_forward = Gtk.Button()
        self.search_forward.set_label("Sonraki")
        self.search_forward.connect("clicked", self.searchforward)
        self.toolitem2.add(self.search_forward)
        self.searchtoolbar.insert(self.toolitem2, 1)

        self.toolitem3 = Gtk.ToolItem()
        self.search_backward= Gtk.Button()
        self.search_backward.set_label("Önceki")
        self.search_backward.connect("clicked", self.searchbackward)
        self.toolitem3.add(self.search_backward)
        self.searchtoolbar.insert(self.toolitem3, 2)


        self.pack_start(self.scrolled, True, True, 0)
        self.pack_start(self.searchtoolbar, False, True, 0)

        self.show_all()
Exemplo n.º 30
0
 def get_source_language_manager():
     if ServiceLocator.source_language_manager == None:
         ServiceLocator.source_language_manager = GtkSource.LanguageManager(
         )
         path = os.path.join(ServiceLocator.get_resources_path(),
                             'gtksourceview', 'language-specs')
         ServiceLocator.source_language_manager.set_search_path((path, ))
     return ServiceLocator.source_language_manager
Exemplo n.º 31
0
    def make_encoding_combo(self):
        """Create the combo box for text encoding selection"""
        codecs = []
        current = GtkSource.encoding_get_current()
        codecs.append((current.to_string(), current.get_charset()))
        codecs.append((None, None))
        for encoding in GtkSource.encoding_get_all():
            codecs.append((encoding.to_string(), encoding.get_charset()))

        self.encoding_store.clear()
        for entry in codecs:
            self.encoding_store.append(entry)

        combo = Gtk.ComboBox()
        combo.set_model(self.encoding_store)
        cell = Gtk.CellRendererText()
        combo.pack_start(cell, True)
        combo.add_attribute(cell, 'text', 0)
        combo.set_row_separator_func(
            lambda model, it, data: not model.get_value(it, 1), None)
        combo.props.active = 0
        return combo
Exemplo n.º 32
0
    def find_cb(self, action, user_data=None):
        dialog = SearchDialog(self, False, None, None)

        if dialog.is_case_sensitive:
            search_flags = GtkSource.SearchFlags.CASE_INSENSITIVE
        else:
            search_flags = 0

        if dialog.run_search():
            i = self._buf.get_iter_at_mark(self._buf.get_insert())

            searched, start, end = GtkSource.iter_forward_search(i, dialog.get_search_text(),
                                                                 search_flags, None)
            if searched:
                self._buf.select_range(start, end)
            else:
                end = i
                i = self._buf.get_start_iter()

                searched, start, end = GtkSource.iter_forward_search(i, dialog.get_search_text(),
                                                                     search_flags, end)
                if searched:
                    self._buf.select_range(start, end)
Exemplo n.º 33
0
    def replace_cb(self, action, user_data=None):
        dialog = SearchDialog(self, False, None, None)

        if dialog.is_case_sensitive:
            search_flags = GtkSource.SearchFlags.CASE_INSENSITIVE
        else:
            search_flags = 0

        i = self._buf.get_start_iter()

        while True:
            searched, start, end = GtkSource.iter_forward_search(i, dialog.get_search_text(),
                                                                 search_flags, None)

            if not searched:
                break

            self._buf.delete(start, end)
            self._buf.insert(start, dialog.get_replace_text())
            i = start