Exemplo n.º 1
0
    def __init__(self):
        super().__init__()

        self.document = None

        self.buffer = GtkSource.Buffer()
        self.manager = GtkSource.LanguageManager()
        self.buffer.set_language(self.manager.get_language("markdown"))

        self.view = GtkSource.View()
        self.view.set_buffer(self.buffer)
        self.view.set_wrap_mode(Gtk.WrapMode.WORD)
        self.view.set_auto_indent(True)
        self.view.set_smart_home_end(True)
        self.view.set_insert_spaces_instead_of_tabs(True)
        self.view.set_tab_width(4)

        self.view.set_pixels_above_lines(4)
        self.view.set_pixels_below_lines(4)
        self.view.set_left_margin(8)
        self.view.set_right_margin(8)
        self.view.get_style_context().add_class('norka-editor')

        self.view.connect('key-release-event', self.on_key_release_event)

        self.font_desc = Pango.FontDescription()
        self.spellchecker = GtkSpell.Checker()

        self.add(self.view)
Exemplo n.º 2
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.º 3
0
    def __init__(self,mainprog):
        self.conn = mainprog.conn
        self.db = mainprog.db
        self.mainprog = mainprog
        self.original_text = ""                                     
        self.filename = "New query " +str(len(mainprog.apps)+1)
        self.is_new_file = True        
        self.result_sets = []
        self.change_checked = False
        paned =  Gtk.VPaned()
        lbl = self.create_tab_label(self.filename)        
        mainprog.notebook.append_page(paned,lbl)        
        queryw = Gtk.ScrolledWindow()
        queryw.set_policy(Gtk.PolicyType.AUTOMATIC,Gtk.PolicyType.AUTOMATIC)
        paned.pack1(queryw,True)
        self.textbuffer = GtkSource.Buffer()

        self.textview = GtkSource.View(buffer=self.textbuffer)        
        self.textview.modify_font(Pango.FontDescription("Courier New 16 bold"))
        self.textview.set_wrap_mode(Gtk.WrapMode.WORD)

        #self.textview.connect("change?", self.textarea_enter_notify)
        queryw.add(self.textview)        
        self.result_win = Gtk.ScrolledWindow()
        self.result_win.set_policy(Gtk.PolicyType.AUTOMATIC,Gtk.PolicyType.AUTOMATIC)
        paned.pack2(self.result_win,True)
        rbox = Gtk.VBox(homogeneous=False,spacing=1)
        self.result_win.add_with_viewport(rbox)
        paned.show_all()
        self.textview.grab_focus()
        mainprog.notebook.set_focus_child(self.textview)
Exemplo n.º 4
0
    def __init__(self, parent_window=None):

        Gtk.Window.__init__(self)

        self.parent_window = parent_window
        self.set_title("Informe de Introspección")
        self.set_transient_for(self.parent_window)
        self.set_border_width(5)

        self.source = GtkSource.View()
        self.source.set_insert_spaces_instead_of_tabs(True)
        self.source.set_tab_width(4)
        self.source.set_auto_indent(True)
        self.source.set_highlight_current_line(True)
        self.source.set_editable(False)
        self.source.set_border_width(5)
        self.source.set_buffer(GtkSource.Buffer())

        scroll = Gtk.ScrolledWindow()
        scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scroll.add(self.source)

        self.resize(w / 3, h - 40)
        self.move(w - w / 3, 40)

        #text = ""
        #_dict = self.infonotebook.introspeccion._dict
        #for key in _dict:
        #    text = "%s\n%s" % (text, _dict[key])
        #source.get_buffer().set_text(text)

        self.add(scroll)
        self.show_all()
Exemplo n.º 5
0
    def __init__(self, code_type, text=None):
        Gtk.ScrolledWindow.__init__(self)
        self.get_style_context().add_class(code_type)
        self._view = GtkSource.View()
        self.add(self._view)
        text_buffer = GtkSource.Buffer()

        lang_manager = GtkSource.LanguageManager.get_default()
        lang_ids = lang_manager.get_language_ids()
        langs = [lang_manager.get_language(lang_id)
                 for lang_id in lang_ids]
        for lang in langs:
            for m in lang.get_mime_types():
                if m == 'text/' + code_type:
                    text_buffer.set_language(lang)
        text_buffer.set_highlight_syntax(True)

        # "- 2" accounts for the border width
        self.set_size_request(
            int(Gdk.Screen.width() * 0.5) - 2,
            int((Gdk.Screen.height()-style.GRID_CELL_SIZE) * 0.5) - 2)
        self._view.set_buffer(text_buffer)
        self._view.set_editable(True)
        self._view.set_cursor_visible(True)
        self._view.set_wrap_mode(Gtk.WrapMode.CHAR)
        self._view.set_insert_spaces_instead_of_tabs(True)
        self._view.set_tab_width(4)
        self._view.set_can_focus(True)
        self._view.modify_font(Pango.FontDescription('Monospace 14'))

        if text is not None:
            self.set(text)
Exemplo n.º 6
0
	def __init__(self,ebeveyn, title = "Talimat Editör"):
		Gtk.Window.__init__(self)
		self.ebeveyn = ebeveyn
		self.degistimi = False
		self.acilan_dosya = ""
		self.kaydirma = Gtk.ScrolledWindow()
		self.kaydirma.set_hexpand(True)
		self.kaydirma.set_vexpand(True)
		self.editor = GtkSource.View()
		self.editor.set_show_line_numbers(1)
		self.editor.set_indent_on_tab(1)
		self.editor.set_tab_width(4)
		self.editor.set_show_line_marks(1)
		self.kaydirma.add(self.editor)
		self.pack_start(self.kaydirma, expand = True, fill = True, padding = 5)
		self.textbuff = GtkSource.Buffer()
		self.textbuff.connect("changed",self.yazi_degisti)
		self.editor.set_buffer(self.textbuff)
		self.lm = GtkSource.LanguageManager()
		self.textbuff.set_language(self.lm.get_language('ini'))

		self.keywords = """
				GtkSourceView
				Completion
			"""
		self.set_auto_completation()
Exemplo n.º 7
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.º 8
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.º 9
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.º 10
0
    def create_source_view(self):
        font_desc = Pango.FontDescription('monospace 11')

        if GtkSource:
            lang_mgr = GtkSource.LanguageManager()
            lang = lang_mgr.get_language('python')

            buffer = GtkSource.Buffer()
            buffer.set_language(lang)
            buffer.set_highlight_syntax(True)

            view = GtkSource.View()
            view.set_buffer(buffer)
            view.set_show_line_numbers(True)

            scrolled_window = self.create_scrolled_window()
            scrolled_window.add(view)

        else:
            scrolled_window, buffer = self.create_text_view()
            view = scrolled_window.get_child()

        view.modify_font(font_desc)
        view.set_wrap_mode(Gtk.WrapMode.NONE)
        return scrolled_window, buffer
Exemplo n.º 11
0
 def __init__(self, main_app):
     """Create the source view window and init its properties"""
     self.main = main_app
     self.model = main_app.model
     self.clipboard = Gtk.Clipboard()
     control_viewport = self.main.builder.get_object('control_view')
     manager = GtkSource.LanguageManager()
     lang_python = manager.get_language('python')
     self.buffer = GtkSource.Buffer(language=lang_python)
     self.buffer.props.highlight_syntax = True
     self.control_view = GtkSource.View(buffer=self.buffer)
     self.buffer.place_cursor(self.buffer.get_start_iter())
     self.control_view.connect('button-press-event',
                               self.on_control_view_clicked)
     self.buffer.connect('changed', self.on_buffer_changed)
     self.buffer.connect('notify::can-undo',
                         lambda o, p: self.main.update_undo_redo_menuitem())
     self.buffer.connect('notify::can-redo',
                         lambda o, p: self.main.update_undo_redo_menuitem())
     self.tag_error = self.buffer.create_tag("error", background="red")
     debug_textview = self.main.builder.get_object('trace_textview')
     self.debug_buffer = LogBuffer(sys.stdout)
     sys.stdout = self.debug_buffer
     debug_textview.set_buffer(self.debug_buffer)
     self.control_view.show()
     #hide trace window by default
     #self.main.builder.get_object('hboxdebug').hide()
     control_viewport.add(self.control_view)
Exemplo n.º 12
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.º 13
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.º 14
0
    def __init__(self, core, textviews):
        super(ReprTextView, self).__init__(False, 1)

        #################################################################
        # Right Textview
        #################################################################

        self.uicore = core
        self.textviews = textviews

        # Use GtkSourceView to add eye candy :P
        # create buffer
        lm = GtkSource.LanguageManager()
        # Add ui dir to language paths
        paths = lm.get_search_path()
        paths.append(os.path.dirname(__file__) + os.sep + 'data' + os.sep)
        lm.set_search_path(paths)
        self.buffer = GtkSource.Buffer()
        self.buffer.create_tag("green-background",
                               background="green",
                               foreground="black")
        self.buffer.set_data('languages-manager', lm)
        self.view = GtkSource.View(self.buffer)

        # FIXME options must be user selectable (statusbar)
        self.view.set_editable(False)
        self.view.set_highlight_current_line(True)
        # posible values: Gtk.WrapMode.NONE, Gtk.WrapMode.CHAR, Gtk.WrapMode.WORD...
        self.view.set_wrap_mode(Gtk.WrapMode.WORD)

        # setup view
        font_desc = Pango.FontDescription('monospace 9')
        if font_desc:
            self.view.modify_font(font_desc)

        self.buffer.set_highlight_syntax(False)
        manager = self.buffer.get_data('languages-manager')
        language = manager.get_language('asm')
        self.buffer.set_language(language)

        self.mgr = GtkSource.StyleSchemeManager.get_default()

        # Scrolled Window
        self.repr_scrolled_window = Gtk.ScrolledWindow()
        self.repr_scrolled_window.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        self.repr_scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                             Gtk.PolicyType.AUTOMATIC)
        self.repr_scrolled_window.show()
        # Add Textview to Scrolled Window
        self.repr_scrolled_window.add(self.view)
        self.pack_start(self.repr_scrolled_window, expand=True, fill=True)

        # Create the search widget
        Searchable.__init__(self, self.view, small=True)

        # Used for code navidation on _search function
        self.match_start = None
        self.match_end = None
        self.search_string = ''
Exemplo n.º 15
0
    def add_tab(self, label=None, buffer_text=None, path=None):
        text_buffer = GtkSource.Buffer()

        lang_manager = GtkSource.LanguageManager.get_default()
        if hasattr(lang_manager, 'list_languages'):
            langs = lang_manager.list_languages()
        else:
            lang_ids = lang_manager.get_language_ids()
            langs = [lang_manager.get_language(lang_id)
                     for lang_id in lang_ids]
        for lang in langs:
            for m in lang.get_mime_types():
                if m == 'text/x-python':
                    text_buffer.set_language(lang)

        if hasattr(text_buffer, 'set_highlight'):
            text_buffer.set_highlight(True)
        else:
            text_buffer.set_highlight_syntax(True)
        if buffer_text:
            text_buffer.set_text(buffer_text)
            text_buffer.set_modified(False)

        text_view = GtkSource.View()
        text_view.set_buffer(text_buffer)
        text_view.set_size_request(0, int(Gdk.Screen.height() * 0.5))
        text_view.set_editable(True)
        text_view.set_cursor_visible(True)
        text_view.set_show_line_numbers(True)
        text_view.set_wrap_mode(Gtk.WrapMode.CHAR)
        text_view.set_insert_spaces_instead_of_tabs(True)
        text_view.set_tab_width(2)
        text_view.set_auto_indent(True)
        text_view.modify_font(
            Pango.FontDescription('Monospace ' +
                                  str(font_zoom(style.FONT_SIZE))))

        codesw = Gtk.ScrolledWindow()
        codesw.set_policy(Gtk.PolicyType.AUTOMATIC,
                          Gtk.PolicyType.AUTOMATIC)
        codesw.add(text_view)
        text_view.show()
        text_view.set_can_focus(True)
        text_view.grab_focus()

        tabdex = self.get_n_pages() + 1
        if label:
            self.tablabel = TabLabel(codesw, label, path, self)
        else:
            self.tablabel = TabLabel(codesw,
                                     _('New Source File %d' % tabdex),
                                     path, self)
        self.tablabel.connect('tab-close', self._tab_closed_cb)
        self.connect('key-press-event', self._key_press_cb)

        codesw.show_all()

        index = self.append_page(codesw, self.tablabel)
        self.props.page = index  # Set new page as active tab
Exemplo n.º 16
0
    def __init__(self):
        super().__init__()

        self.document = None

        self.buffer = GtkSource.Buffer()
        self.manager = GtkSource.LanguageManager()
        self.language = self.manager.get_language("markdown")
        self.buffer.set_language(self.language)
        self.buffer.create_tag('match', background="#66ff00")

        self.view = GtkSource.View()
        self.view.set_buffer(self.buffer)
        self.view.set_wrap_mode(Gtk.WrapMode.WORD)
        self.view.set_auto_indent(True)
        self.view.set_smart_home_end(True)
        self.view.set_insert_spaces_instead_of_tabs(True)
        self.view.set_tab_width(4)

        # self.view.set_pixels_above_lines(4)
        # self.view.set_pixels_below_lines(4)
        self.view.set_left_margin(8)
        self.view.set_right_margin(8)
        self.view.get_style_context().add_class('norka-editor')

        self.view.connect('key-release-event', self.on_key_release_event)

        self.scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
        self.scrolled.add(self.view)

        # SearchBar
        self.search_bar = SearchBar()
        self.search_revealer = Gtk.Revealer()
        self.search_revealer.add(self.search_bar)
        self.search_bar.connect('find-changed', self.do_next_match)
        self.search_bar.connect('find-next', self.do_next_match)
        self.search_bar.connect('find-prev', self.do_previous_match)
        self.search_bar.connect('stop-search', self.do_stop_search)

        content_grid = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
        content_grid.pack_start(self.search_revealer, False, True, 0)
        content_grid.pack_start(self.scrolled, True, True, 0)
        content_grid.show_all()

        self.overlay = Gtk.Overlay()
        self.overlay.add(content_grid)
        self.stats_overlay = Granite.WidgetsOverlayBar.new(self.overlay)

        self.stats_handler = StatsHandler(overlay_bar=self.stats_overlay, buffer=self.buffer)
        self.stats_handler.update_default_stat()

        self.add(self.overlay)

        self.font_desc = Pango.FontDescription()
        self.spellchecker = GtkSpell.Checker()

        self.search_settings = GtkSource.SearchSettings(wrap_around=True)
        self.search_context = GtkSource.SearchContext(buffer=self.buffer, settings=self.search_settings)
        self.search_iter = None
Exemplo n.º 17
0
    def __init__(self, conn_obj):
        Gtk.VBox.__init__(self, False, 0)

        self.conn_obj = conn_obj

        self._updates = UpdatesHandler()

        toolbar = Gtk.Toolbar()
        self.execute_btn = gtkutil.tool_button(Gtk.STOCK_EXECUTE,
                                               messages.BTN_EXECUTE,
                                               self._on_execute)
        toolbar.insert(self.execute_btn, -1)

        self.pack_start(toolbar, False, False, 0)

        self.paned = Gtk.Paned()
        self.paned.set_orientation(Gtk.Orientation.VERTICAL)
        self.pack_start(self.paned, True, True, 0)
        self.code_view = GtkSource.View()

        lang_manager = GtkSource.LanguageManager.get_default()

        lang = lang_manager.get_language("python")

        self.buffer = GtkSource.Buffer.new_with_language(lang)
        self.code_view.set_buffer(self.buffer)
        self.code_view.set_show_line_numbers(True)
        font_desc = Pango.FontDescription("monospace 10")
        self.code_view.modify_font(font_desc)
        self.paned.set_position(150)
        self.results = ResultsView()

        code_scroll = Gtk.ScrolledWindow()
        code_scroll.add(self.code_view)

        self.paned.add1(code_scroll)
        self.log = Gtk.TextView()

        log_scroll = Gtk.ScrolledWindow()
        log_scroll.add(self.log)

        self.results.add_toolbar_items(self.build_results_actions())

        self.results_tab = Gtk.Notebook()
        self.results_tab.append_page(self.results,
                                     Gtk.Label(messages.TAB_RESULTS))
        self.results_tab.append_page(log_scroll,
                                     Gtk.Label(messages.TAB_OUTPUT))
        self.paned.add2(self.results_tab)

        self.results.connect("update-request", self._on_update_field)
        self.results.connect("selection-changed", self._on_selection_changed)
        self.results.connect("notify-status", self._on_results_status)
        self._update_results_actions()

        self.status_bar = Gtk.Statusbar()
        self.pack_start(self.status_bar, False, False, 0)
        self.status_ctx = self.status_bar.get_context_id("")
Exemplo n.º 18
0
    def _init_view(self):
        self.buffer.object_attrib.connect('changed', self.on_attrib_changed)

        self.view = GtkSource.View()
        self.view.set_buffer(self.buffer)
        self.view.modify_font(Pango.FontDescription('monospace'))
        self.view.set_auto_indent(True)
        self.view.set_smart_home_end(True)
        self.view.set_highlight_current_line(True)
        self.view.set_right_margin_position(80)
        self.view.set_show_right_margin(True)
        self.view.set_tab_width(4)
        self.view.set_show_line_numbers(
            self.buffer.object_attrib['linenumbers'])
        self.view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)

        self.WRAP_MODE = {
            WRAP_NONE: Gtk.WrapMode.NONE,
            WRAP_WORD_CHAR: Gtk.WrapMode.WORD_CHAR,
            WRAP_CHAR: Gtk.WrapMode.CHAR,
            WRAP_WORD: Gtk.WrapMode.WORD,
        }

        # simple toolbar
        #~ bar = Gtk.HBox() # FIXME: use Gtk.Toolbar stuff
        #~ lang_selector = Gtk.ComboBoxText()
        #~ lang_selector.append_text('(None)')
        #~ for l in lang_names: lang_selector.append_text(l)
        #~ try:
        #~ lang_selector.set_active(lang_ids.index(self._attrib['lang'])+1)
        #~ self.set_language(self._attrib['lang'] or None, False)
        #~ except (ValueError, KeyError):
        #~ lang_selector.set_active(0)
        #~ self.set_language(None, False)
        #~ lang_selector.connect('changed', self.on_lang_changed)
        #~ bar.pack_start(lang_selector, False, False)

        #~ line_numbers = Gtk.ToggleButton('Line numbers')
        #~ try:
        #~ line_numbers.set_active(self._attrib['linenumbers']=='true')
        #~ self.show_line_numbers(self._attrib['linenumbers'], False)
        #~ except (ValueError, KeyError):
        #~ line_numbers.set_active(True)
        #~ self.show_line_numbers(True, False)
        #~ line_numbers.connect('toggled', self.on_line_numbers_toggled)
        #~ bar.pack_start(line_numbers, False, False)
        #~ self.add_header(bar)

        # TODO: other toolbar options
        # TODO: autohide toolbar if textbuffer is not active

        win = ScrolledWindow(self.view, Gtk.PolicyType.AUTOMATIC,
                             Gtk.PolicyType.NEVER, Gtk.ShadowType.NONE)
        self.add(win)

        self.view.connect('populate-popup', self.on_populate_popup)
Exemplo n.º 19
0
    def get_a_child(self, child_name):

        textview = GtkSource.View(
            editable=True, buffer=self.buffer, margin=5, expand=True
        )
        child_dict = {}
        child_dict["child_name"] = child_name
        child_dict["child"] = textview
        child_dict["header_child"] = None
        child_dict["icon"] = Gtk.Image.new_from_icon_name("text-x-generic-symbolic", 2)
        return child_dict
Exemplo n.º 20
0
 def __init__(self, buffer_model_id):
     self.buffer_id = buffer_model_id
     self.scroll = scroll = Gtk.ScrolledWindow()
     self.sourceview = sourceview = GtkSource.View()
     scroll.add(sourceview)
     self.buffer = buffer = GtkSource.Buffer()
     sourceview.set_buffer(buffer)
     # bg = Gdk.RGBA(0.8, 0.8, 0.8, 1)
     # gutter = self.sourceview.get_gutter(Gtk.TextWindowType.LEFT)
     # TODO: set gutter background color
     fontdesc = Pango.FontDescription("monospace")
     sourceview.modify_font(fontdesc)
     self.set_language()
Exemplo n.º 21
0
    def mk_reader_page(self):
        scrolledwindow = Gtk.ScrolledWindow()
        scrolledwindow.set_hexpand(True)
        scrolledwindow.set_vexpand(True)

        source = GtkSource.View()
        source.set_editable(False)
        source.set_cursor_visible(False)
        source.set_show_line_numbers(True)
        self.textbuffer = source.get_buffer()

        scrolledwindow.add(source)
        return scrolledwindow
Exemplo n.º 22
0
    def _create_source_view():
        """Create a suitable text view + buffer for showing a sh script."""
        LOGGER.info('Using GtkSourceView since we have it.')

        buffer_ = GtkSource.Buffer()
        buffer_.set_highlight_syntax(True)

        view = GtkSource.View()
        view.set_buffer(buffer_)
        view.set_show_line_numbers(True)
        view.set_show_line_marks(True)
        view.set_auto_indent(True)

        return view, buffer_
Exemplo n.º 23
0
    def build(self) -> None:
        super().build()
        self.add_configurator('file_group',
                              FileGroupSelector(FileGroupFilter.PAGE))

        self.text_view = GtkSource.View(visible=True,
                                        vexpand=False,
                                        editable=False,
                                        monospace=False,
                                        show_line_numbers=True,
                                        width_request=400)
        self.buffer = self.text_view.get_buffer()

        self.scroller.add(self.text_view)
Exemplo n.º 24
0
    def create_view(self):
        sourceview = GtkSource.View()
        sourceviewBuffer = sourceview.get_buffer()
        sourceviewBuffer.connect("changed", self.on_buffer_editor_change)
        self.add_sintaxis_sqlite_so_editor(sourceview.get_buffer())
        sourceview.set_show_line_numbers(True)
        sourceview.set_tab_width(4)
        sourceview.set_auto_indent(True)
        sourceview.set_insert_spaces_instead_of_tabs(True)
        sourceview.set_highlight_current_line(True)
        sourceview.set_indent_on_tab(True)

        self.set_tooltip_text(
            "untitled {0}".format(self.notebookEditor.get_n_pages() + 1))
        self.add(sourceview)
Exemplo n.º 25
0
def textbox(title='Text Box', label='Text', parent=None, text='', lang=''):
    """display a text edit dialog
    
    return the text , or None
    """
    dlg = Gtk.Dialog(title, parent, Gtk.DialogFlags.DESTROY_WITH_PARENT,
                     (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK,
                      Gtk.ResponseType.OK))
    dlg.set_default_size(500, 500)
    #lbl = Gtk.Label(label)
    #lbl.set_alignment(0, 0.5)
    #lbl.show()
    #dlg.vbox.pack_start(lbl,  False)
    gscw = Gtk.ScrolledWindow()
    gscw.set_shadow_type(Gtk.ShadowType.IN)
    #gscw.set_policy(Gtk.POLICY_NEVER, Gtk.PolicyType.AUTOMATIC)
    gscw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)

    if GtkSource:
        textview = GtkSource.View()
        lm = GtkSource.LanguageManager.get_default()
        buffer = GtkSource.Buffer()
        buffer.set_highlight_syntax(1)
        if lang:
            language = lm.get_language(lang)
            buffer.set_language(language)
            pass
        textview.set_buffer(buffer)
        pass
    else:
        textview = Gtk.TextView(buffer=None)
        buffer = textview.get_buffer()

    if text: buffer.set_text(text)

    #textview.show()
    gscw.add(textview)
    #gscw.show()
    dlg.vbox.pack_start(gscw, True, True, 0)
    dlg.show_all()
    resp = dlg.run()

    text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(),
                           True)
    dlg.destroy()
    if resp == Gtk.ResponseType.OK:
        return text
    return None
Exemplo n.º 26
0
    def create_textview(self, nombre, texto_template):
        """
        create_textview es el metodo encargado de crear las pestañas dentro
        del notebook general, y detro de esa pestaña, es el encargado de crear
        el GtkSourceView para poder escribir y tener resaltado de sintaxis.
        """
        self.archivo_py = None
        header = Gtk.HBox()
        scrolledwindow = Gtk.ScrolledWindow()
        scrolledwindow.set_hexpand(True)
        scrolledwindow.set_vexpand(True)

        title_label = Gtk.Label(nombre)
        lm = GtkSource.LanguageManager.get_default()
        self.textview = GtkSource.View()  # Gtk.TextView()
        self.textbuffer = self.textview.get_buffer()
        # agrego un texto con dentro del textview
        self.textbuffer.set_text(texto_template)  # aca puedo poner un template
        # Selecciono como código fuente a resaltar el lenguaje PYTHON
        self.textbuffer.set_language(lm.get_language("python"))
        # activo el resaltado de imagen
        self.textbuffer.set_highlight_syntax(True)
        # activo el numero de linea de código en el margen izquierdo
        self.textview.set_show_line_numbers(True)
        # cuando se apriete el tabulador o los Spaces, conservar la identación
        self.textview.set_auto_indent(True)
        # cuando se teclea TAB, lo remplaza por espacios
        # self.textview.set_insert_spaces_instead_of_tabs(True)
        # remplaza el TAB con 4 espacios
        # self.textview.set_tab_width(4)
        scrolledwindow.add(self.textview)
        self.textview.connect("key-press-event", self.textpress)
        self.textview.connect('button_press_event', self.boton_mouse)

        header.pack_start(title_label, expand=True, fill=True, padding=0)
        self.new_button(
            "media-playback-start",
            "ejecutar",
            header,
            self.execute,
            self.notebook,
            self.textbuffer,
        )
        self.new_button("window-close-symbolic", "cerrar", header,
                        self.close_cb, self.notebook, scrolledwindow)
        header.show_all()
        self.notebook.append_page(scrolledwindow, header)
Exemplo n.º 27
0
    def create_tab(path, buffer):
        hbox = Gtk.HBox(False, 0)
        label = Gtk.Label(path)
        hbox.pack_start(label, True, True, 0)
        close_image = Gtk.IconTheme.get_default().load_icon("exit", 16, 0)
        imgw = Gtk.Image()
        imgw.set_from_pixbuf(close_image)
        btn = Gtk.Button()
        btn.set_focus_on_click(False)
        btn.add(imgw)
        hbox.pack_start(btn, False, False, 0)
        hbox.show_all()

        sview = GtkSource.View()
        sview.set_buffer(buffer)

        # make settings
        sview.set_show_line_numbers(True)
        sview.set_auto_indent(True)
        sview.set_tab_width(4)
        sview.set_indent_width(4)
        sview.set_insert_spaces_instead_of_tabs(True)
        sview.set_right_margin_position(80)
        sview.set_show_right_margin(True)
        sview.modify_font(Pango.FontDescription('Dejavu Sans Mono'))

        #        try:
        #            bg_color = Gdk.RGBA()
        #            Gdk.RGBA.parse(bg_color, "#111111")
        #            sview.override_background_color(Gtk.StateType.NORMAL, bg_color)
        #            fg_color = Gdk.RGBA()
        #            Gdk.RGBA.parse(fg_color, "#DDDDDD")
        #            sview.override_color(Gtk.StateType.NORMAL, fg_color)
        #        except Exception as e:
        #            print(e)
        #            pass

        swindow = Gtk.ScrolledWindow()
        swindow.add(sview)
        notebook = app.builder.get_object("notebook1")
        pos = notebook.append_page(swindow, hbox)
        notebook.show_all()
        btn.connect("clicked", Handler.onCloseTab, path, buffer, swindow)
        buffer.connect("modified-changed", Handler.onModified, label, buffer)
        notebook.set_current_page(pos)
        return swindow
Exemplo n.º 28
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.º 29
0
    def __init__(self, file=None, **props):
        super().__init__(**dict(
            default_width=640, default_height=480, icon_name='eddy', **props))
        self.__file = file
        self.__saved = True
        self.__close_after_save = False

        grid = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL)
        self.add(grid)

        self.__menu_stack = MenuStack(self)
        grid.attach(self.__menu_stack, 0, self.__ROW_MENU, 1, 1)

        scroller = Gtk.ScrolledWindow(shadow_type=Gtk.ShadowType.IN,
                                      expand=True)

        self.__source_view = GtkSource.View(expand=True, monospace=True)
        scroller.add(self.__source_view)
        scroller.show_all()
        self.buffer.connect('mark-set', self.__on_mark_set)
        self.__on_cursor_position_changed(self.buffer.get_start_iter())

        if file is None:
            grid.attach(scroller, 0, self.__ROW_TEXT_VIEW, 1, 1)
            self.buffer.connect('changed', self.__on_buffer_changed)
        else:
            hgrid = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
            label = Gtk.Label(_('Loading…'))
            hgrid.add(label)
            cancel_button = Gtk.Button.new_from_stock(Gtk.STOCK_CANCEL)
            hgrid.add(cancel_button)
            grid.attach(hgrid, 0, self.__ROW_TEXT_VIEW, 1, 1)
            hgrid.show_all()

            cancellable = Gio.Cancellable()
            source_file = GtkSource.File(location=file)
            loader = GtkSource.FileLoader(buffer=self.buffer, file=source_file)
            # TODO: Show progress
            loader.load_async(
                GLib.PRIORITY_DEFAULT, cancellable, None, None,
                lambda loader, result: self.__finish_loading(
                    loader, result, grid, hgrid, scroller))
            cancel_button.connect('clicked', lambda b: cancellable.cancel())

        grid.show_all()
Exemplo n.º 30
0
    def get_log(self, output):
        """ bruter read function, (parser could be implemented?)"""

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

        textview = GtkSource.View()
        textbuffer = textview.get_buffer()
        textbuffer.set_text(output)

        textview.set_show_line_numbers(True)
        textview.set_editable(False)

        scrolledwindow.add(textview)
        textview.show()

        return scrolledwindow