def scroll_to_op(cls, b: GtkSource.Buffer, view: GtkSource.View, ssb_filename: str, opcode_addr: int, is_for_macro_call: bool): m = cls._get_opcode_mark(b, ssb_filename, opcode_addr, is_for_macro_call) if m is not None: view.scroll_to_mark(m, 0.1, False, 0.1, 0.1) b.place_cursor(b.get_iter_at_mark(m))
def __init__(self, preferences, action_name=None): super(SourceView, self).__init__() if action_name: self.action_name = action_name self.set_hexpand(True) self.set_vexpand(True) self.text_buffer = Buffer.new_with_language( LANGS['.%s' % preferences.parser]) self.text_buffer.connect("changed", self.inc_changes) self.source_view = View.new_with_buffer(self.text_buffer) self.spellchecker = Checker() self.spellchecker.connect("language-changed", self.language_changed) self.source_view.override_font( FontDescription.from_string('Monospace')) # self.source_view.set_monospace(True) since 3.16 self.add(self.source_view) editor_pref = preferences.editor self.set_period_save(editor_pref.period_save) self.set_check_spelling(editor_pref.check_spelling, editor_pref.spell_lang) self.set_spaces_instead_of_tabs(editor_pref.spaces_instead_of_tabs) self.source_view.set_tab_width(editor_pref.tab_width) self.source_view.set_auto_indent(editor_pref.auto_indent) self.source_view.set_show_line_numbers(editor_pref.line_numbers) self.source_view.set_show_right_margin(editor_pref.right_margin) self.source_view.set_highlight_current_line(editor_pref.current_line) self.set_text_wrapping(editor_pref.text_wrapping) self.set_white_chars(editor_pref.white_chars)
def on_key_release_event(self, text_view: GtkSource.View, event: Gdk.EventKey) -> None: """Handle release event and iterate markdown list markup :param text_view: widget emitted the event :param event: key release event :return: """ buffer = text_view.get_buffer() if event.keyval == Gdk.KEY_Return: buffer.begin_user_action() curr_iter = buffer.get_iter_at_mark(buffer.get_insert()) curr_line = curr_iter.get_line() if curr_line > 0: # Get prev line text prev_line = curr_line - 1 prev_iter = buffer.get_iter_at_line(prev_line) prev_line_text = buffer.get_text(prev_iter, curr_iter, False) # Check if prev line starts from markdown list chars match = re.search(r"^(\s){,4}([0-9]*.|-|\*|\+)\s+", prev_line_text) if match: sign = match.group(2) if re.match(r'^[0-9]+.', sign): # ordered list should increment number sign = str(int(sign[:-1]) + 1) + '.' buffer.insert_at_cursor(sign + ' ') buffer.end_user_action()
def __init__(self, view: GtkSource.View, context: AbstractDebuggerControlContext): self.view = view self.buffer: GtkSource.Buffer = view.get_buffer() self.buffer.connect('notify::cursor-position', self.on_buffer_notify_cursor_position) self.buffer.connect('changed', self.on_buffer_notify_cursor_position) self.context = context
def __init__(self, view: GtkSource.View, mapname: str, scene_name: str, scene_type: str, context: AbstractDebuggerControlContext): self.view = view self.buffer: GtkSource.Buffer = view.get_buffer() self.is_ssbs = False self.mapname = mapname self.scene_name = scene_name self.scene_type = scene_type self.context = context self._active_widget: Optional[Gtk.Button] = None self._active_pos: Optional[Tuple[int, int]] = None
def __init__( self, bus: cyrusbus.bus.Bus, source_view: GtkSource.View, ): self.log = logging.getLogger('{m}.{c}'.format( m=self.__class__.__module__, c=self.__class__.__name__)) self.bus = bus self.source_view = source_view self.source_buffer = source_view.get_buffer() # type: GtkSource.Buffer self.current_note_id = None self.clear() self._on_buffer_changed_handler_id = self.source_buffer.connect( 'changed', self.on_buffer_changed) self.bus.subscribe(APPLICATION_TOPIC, self.on_application_event)
def __init__(self, win, preferences, action_name=None): super(SourceView, self).__init__() if action_name: self.action_name = action_name self.set_hexpand(True) self.set_vexpand(True) self.text_buffer = Buffer.new_with_language(LANGS['.%s' % preferences.parser]) self.text_buffer.connect("changed", self.inc_changes) # TODO: will work when FileSaver and FileLoader will be used # self.text_buffer.set_implicit_trailing_newline(False) self.source_view = View.new_with_buffer(self.text_buffer) adj = self.get_vadjustment() adj.connect("value-changed", self.on_scroll_changed) self.spellchecker = Checker() self.spellchecker.connect("language-changed", self.on_language_changed) self.source_view.override_font( FontDescription.from_string('Monospace')) # self.source_view.set_monospace(True) since 3.16 self.add(self.source_view) editor_pref = preferences.editor self.set_period_save(editor_pref.period_save) self.set_check_spelling(editor_pref.check_spelling, editor_pref.spell_lang) self.set_spaces_instead_of_tabs(editor_pref.spaces_instead_of_tabs) self.source_view.set_tab_width(editor_pref.tab_width) self.source_view.set_auto_indent(editor_pref.auto_indent) self.source_view.set_show_line_numbers(editor_pref.line_numbers) self.source_view.set_show_right_margin(editor_pref.right_margin) self.source_view.set_highlight_current_line(editor_pref.current_line) self.set_text_wrapping(editor_pref.text_wrapping) self.set_white_chars(editor_pref.white_chars) self.search_settings = SearchSettings(wrap_around=True) self.search_context = SearchContext.new(self.text_buffer, self.search_settings) self.search_mark = None self.__win = win timeout_add(200, self.check_in_thread)
def on_sourceview_line_mark_activated(self, widget: GtkSource.View, textiter: Gtk.TextIter, event: Gdk.Event): marks = widget.get_buffer().get_source_marks_at_iter(textiter) # Only allow editing one view. if self._explorerscript_active and widget == self._ssb_script_view: return if not self._explorerscript_active and widget == self._explorerscript_view: return # No mark? Add! if len(marks) < 1: self.add_breakpoint(textiter.get_line() + 1, widget) else: # Mark? Remove breakpoint! for mark in marks: self.remove_breakpoint(mark) return True
def __init__(self, view: GtkSource.View, opcodes: List[Pmd2ScriptOpCode], mapname: str, scene_name: str, scene_type: str, context: AbstractDebuggerControlContext, is_ssbs=False): self.view = view self.buffer: GtkSource.Buffer = view.get_buffer() self.opcodes = opcodes self.buffer.connect('notify::cursor-position', self.on_buffer_notify_cursor_position) self.position_mark_calltip = None if not is_ssbs and mapname is not None and scene_name is not None and scene_type is not None: self.position_mark_calltip = PositionMarkEditorCalltip( view, mapname, scene_name, scene_type, context) self._active_widget: Optional[GtkSource.CompletionInfo] = None self._active_op: Optional[Pmd2ScriptOpCode] = None self._active_arg: Optional[int] = None
def on_key_release_event(self, text_view: GtkSource.View, event: Gdk.EventKey) -> None: """Handle release event and iterate Markdown list markup :param text_view: widget emitted the event :param event: key release event :return: """ buffer: Gtk.TextBuffer = text_view.get_buffer() if event.keyval == Gdk.KEY_Return and event.get_state() != Gdk.ModifierType.SHIFT_MASK: buffer.begin_user_action() curr_iter = buffer.get_iter_at_mark(buffer.get_insert()) curr_line = curr_iter.get_line() if curr_line > 0: # Get prev line text prev_line = curr_line - 1 prev_iter = buffer.get_iter_at_line(prev_line) prev_line_text = buffer.get_text(prev_iter, curr_iter, False) # Check if prev line starts from markdown list chars match = re.search(r"^(\s){,4}([0-9]\.|-|\*|\+)\s(.*)$", prev_line_text) if match: if match.group(3): sign = match.group(2) if re.match(r'^[0-9]+.', sign): # ordered list should increment number sign = str(int(sign[:-1]) + 1) + '.' buffer.insert_at_cursor(sign + ' ') else: # If user don't wanna insert new list item then go back and delete prev empty li sign - `-` mark: Gtk.TextMark = buffer.get_insert() curr_iter: Gtk.TextIter = buffer.get_iter_at_mark(mark) curr_iter.backward_line() end_iter = curr_iter.copy() end_iter.forward_to_line_end() buffer.delete(curr_iter, end_iter) buffer.place_cursor(curr_iter) buffer.end_user_action()
def cert_declarations(data, arg): action = certificate(data, arg) box = Gtk.Frame(name="frame_x509") if arg == 14: view = View() view.set_auto_indent(True) view.set_show_line_numbers(True) view.set_wrap_mode(Gtk.WrapMode.WORD) view.set_monospace(True) view.get_buffer().set_text(action) view.set_can_focus(False) box.add(view) return box label = Gtk.Label(name="label_x509") label.set_selectable(True) label.set_can_focus(False) label.set_alignment(0.0, 0.0) label.set_markup(action) box.add(label) return box
def add_breakpoint(self, line_number: int, view: GtkSource.View): buffer: Gtk.TextBuffer = view.get_buffer() for ssb_filename, opcode_offset in EditorTextMarkUtil.get_opcodes_in_line( buffer, line_number - 1): self.file_context.breakpoint_manager.add(ssb_filename, opcode_offset)