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)
def prepare_text_view(text_view): """Set spell-check, line-length margin and font properties.""" if (gaupol.util.gtkspell_available() and gaupol.conf.spell_check.inline): from gi.repository import GtkSpell language = gaupol.conf.spell_check.language with aeidon.util.silent(Exception): checker = GtkSpell.Checker() checker.set_language(language) checker.attach(text_view) connect = gaupol.conf.editor.connect def update_margin(section, value, text_view): if gaupol.conf.editor.show_lengths_edit: return gaupol.ruler.connect_text_view(text_view) return gaupol.ruler.disconnect_text_view(text_view) connect("notify::show_lengths_edit", update_margin, text_view) update_margin(None, None, text_view) def update_font(section, value, text_view): set_widget_font(text_view, get_font()) connect("notify::use_custom_font", update_font, text_view) connect("notify::custom_font", update_font, text_view) update_font(None, None, text_view) def update_spacing(section, value, text_view): if gaupol.conf.editor.show_lengths_cell: return text_view.set_pixels_above_lines(2) return text_view.set_pixels_above_lines(0) connect("notify::show_lengths_cell", update_spacing, text_view) update_spacing(None, None, text_view)
def display(self, record, field): super(TextBox, self).display(record, field) value = field and field.get(record) if not value: value = '' self.set_buffer(value, self.textview) if (GtkSpell and self.textview.get_editable() and self.attrs.get('spell') and CONFIG['client.spellcheck']): checker = GtkSpell.Checker.get_from_text_view(self.textview) if self.record: language = self.record.expr_eval(self.attrs['spell']) if not checker: checker = GtkSpell.Checker() checker.attach(self.textview) if checker.get_language() != language: try: checker.set_language(language) except Exception: logger.debug( 'Could not set spell checker to "%s"', language) checker.detach() elif checker: checker.detach()
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
def initialize(self): self.checker = GtkSpell.Checker() self.checker.set_language(self.config.get('language', 'en_US')) window = self.application.main_window mailer_tab = window.tabs['mailer'] edit_tab = mailer_tab.tabs['edit'] self.checker.attach(edit_tab.textview) return True
def add_checker_to_widget(textview): "adds a spell checker to a textview" try: import gi gi.require_version('GtkSpell', '3.0') from gi.repository import GtkSpell except ValueError as e: print(e), "please install gir1.2-gtkspell" return spell = GtkSpell.Checker() spell.set_language("en_US") spell.attach(textview)
def _on_map(self, listbox): """ Populate languages @param listbox as Gtk.ListBox """ self.__switch.set_active(El().settings.get_value("enable-spell-check")) if not listbox.get_children(): checker = GtkSpell.Checker() for language in checker.get_language_list(): name = checker.decode_language_code(language) row = LanguageRow(self.__uri, name, language) row.show() listbox.add(row)
def __init__(self, save_file_name=None, auto_save=False, parent=None): self._parent = parent textview.Widget.__init__(self) actions.CAGandUIManager.__init__(self) self.view.set_cursor_visible(True) self.view.set_editable(True) self.spell_checker = GtkSpell.Checker() self.spell_checker.attach(self.view) self.spell_checker.set_language(locale.getdefaultlocale()[0]) # Set up file stuff self._save_interval = 1000 # milliseconds self._save_file_name = save_file_name self._save_file_digest = None self.save_toggle_action.set_active(auto_save) self._update_action_sensitivities() self.set_initial_contents()
def __init__(self): super().__init__() self.document = None self.view = Editor() self.scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True) self.scrolled.get_style_context().add_class('scrolled-editor') 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
def __init__(self, widget=None, value="", spellcheck=True): if widget is None: self.view = Gtk.TextView() else: self.view = widget self.buffer = Gtk.TextBuffer() self.view.set_buffer(self.buffer) self.buffer.set_text(value) if HAS_GTKSPELL and spellcheck: try: checker = GtkSpell.Checker() try: checker.set_language(getlocale(LC_MESSAGES)[0]) except: checker = None # Language not available. if checker: checker.attach(self.view) except Exception as e: log.exception(e)
def enable(self): if not self._checker: self._checker = gtkspell.Checker() self._checker.set_language(self._lang) self._checker.attach(self._textview)
def __init__(self, name, record, prints, template=None): super().__init__() self.record = record self.dialog = Gtk.Dialog(transient_for=self.parent, destroy_with_parent=True) Main().add_window(self.dialog) self.dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self.dialog.set_icon(TRYTON_ICON) self.dialog.set_default_size(*self.default_size()) self.dialog.connect('response', self.response) self.dialog.set_title(_('E-mail %s') % name) grid = Gtk.Grid(column_spacing=3, row_spacing=3, border_width=3) self.dialog.vbox.pack_start(grid, expand=True, fill=True, padding=0) label = Gtk.Label(set_underline(_("To:")), use_underline=True, halign=Gtk.Align.END) grid.attach(label, 0, 0, 1, 1) self.to = EmailEntry(hexpand=True, activates_default=True) widget_class(self.to, 'required', True) label.set_mnemonic_widget(self.to) grid.attach(self.to, 1, 0, 1, 1) label = Gtk.Label(set_underline(_("Cc:")), use_underline=True, halign=Gtk.Align.END) grid.attach(label, 0, 1, 1, 1) self.cc = EmailEntry(hexpand=True, activates_default=True) label.set_mnemonic_widget(self.cc) grid.attach(self.cc, 1, 1, 1, 1) label = Gtk.Label(set_underline(_("Bcc:")), use_underline=True, halign=Gtk.Align.END) grid.attach(label, 0, 2, 1, 1) self.bcc = EmailEntry(hexpand=True, activates_default=True) label.set_mnemonic_widget(self.bcc) grid.attach(self.bcc, 1, 2, 1, 1) label = Gtk.Label(set_underline(_("Subject:")), use_underline=True, halign=Gtk.Align.END) grid.attach(label, 0, 3, 1, 1) self.subject = Gtk.Entry(hexpand=True, activates_default=True) label.set_mnemonic_widget(self.subject) grid.attach(self.subject, 1, 3, 1, 1) self.body = Gtk.TextView() body_frame = Gtk.Frame() label = Gtk.Label(set_underline(_("Body")), use_underline=True, halign=Gtk.Align.END) label.set_mnemonic_widget(self.body) body_frame.set_label_widget(label) grid.attach(body_frame, 0, 4, 2, 1) body_box = Gtk.VBox(hexpand=True, vexpand=True) body_frame.add(body_box) register_format(self.body) body_toolbar = add_toolbar(self.body) body_box.pack_start(body_toolbar, expand=False, fill=True, padding=0) body_box.pack_start(self.body, expand=True, fill=True, padding=0) if GtkSpell and CONFIG['client.spellcheck']: checker = GtkSpell.Checker() checker.attach(self.body) language = os.environ.get('LANGUAGE', 'en') try: checker.set_language(language) except Exception: logger.error('Could not set spell checker for "%s"', language) checker.detach() attachments_box = Gtk.HBox() grid.attach(attachments_box, 0, 5, 2, 1) print_frame = Gtk.Frame(shadow_type=Gtk.ShadowType.NONE) print_frame.set_label(_("Reports")) attachments_box.pack_start(print_frame, expand=True, fill=True, padding=0) print_box = Gtk.VBox() print_frame.add(print_box) print_flowbox = Gtk.FlowBox(selection_mode=Gtk.SelectionMode.NONE) print_box.pack_start(print_flowbox, expand=False, fill=False, padding=0) self.print_actions = {} for print_ in prints: print_check = Gtk.CheckButton.new_with_mnemonic( set_underline(print_['name'])) self.print_actions[print_['id']] = print_check print_flowbox.add(print_check) attachment_frame = Gtk.Frame(shadow_type=Gtk.ShadowType.NONE) attachment_frame.set_label(_("Attachments")) attachments_box.pack_start(attachment_frame, expand=True, fill=True, padding=0) try: attachments = RPCExecute('model', 'ir.attachment', 'search_read', [ ('resource', '=', '%s,%s' % (record.model_name, record.id)), [ 'OR', ('data', '!=', None), ('file_id', '!=', None), ], ], 0, None, None, ['rec_name'], context=record.get_context()) except RPCException: logger.error('Could not fetch attachment for "%s"', record) attachments = [] scrolledwindow = Gtk.ScrolledWindow() if len(attachments) > 2: scrolledwindow.set_size_request(-1, 100) attachment_frame.add(scrolledwindow) scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.attachments = TreeViewControl() self.attachments.set_headers_visible(False) scrolledwindow.add(self.attachments) self.attachments.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.attachments.append_column( Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=0)) model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_INT) for attachment in attachments: model.append((attachment['rec_name'], attachment['id'])) self.attachments.set_model(model) self.attachments.set_search_column(0) file_frame = Gtk.Frame(shadow_type=Gtk.ShadowType.NONE) file_frame.set_label(_("Files")) attachments_box.pack_start(file_frame, expand=True, fill=True, padding=0) self.files = Gtk.VBox(spacing=6) file_frame.add(self.files) self._add_file_button() button_cancel = self.dialog.add_button(set_underline(_("Cancel")), Gtk.ResponseType.CANCEL) button_cancel.set_image( IconFactory.get_image('tryton-cancel', Gtk.IconSize.BUTTON)) button_send = self.dialog.add_button(set_underline(_("Send")), Gtk.ResponseType.OK) button_send.set_image( IconFactory.get_image('tryton-send', Gtk.IconSize.BUTTON)) self.dialog.set_default_response(Gtk.ResponseType.OK) self._fill_with(template) self.dialog.show_all() self.register()
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.props.width_request = 800 self.view.set_halign(Gtk.Align.CENTER) # self.view.set_pixels_above_lines(2) # self.view.set_pixels_below_lines(2) # self.view.set_pixels_inside_wrap(4) self.view.set_top_margin(8) self.view.set_left_margin(8) self.view.set_right_margin(8) self.view.set_bottom_margin(8) self.view.set_monospace(True) self.view.get_style_context().add_class('norka-editor') self.view.connect('key-release-event', self.on_key_release_event) # Connect markup handler self.markup_formatter = MarkupFormatter(self.buffer) self.get_style_context().add_class('norka-editor-view') self.connect('insert-bold', self.on_insert_bold) self.connect('insert-italic', self.on_insert_italic) self.connect('insert-code', self.on_insert_code) self.connect('insert-code-block', self.on_insert_code_block) self.connect('insert-h1', self.on_toggle_header1) self.connect('insert-h2', self.on_toggle_header2) self.connect('insert-h3', self.on_toggle_header3) self.connect('insert-list', self.on_toggle_list) self.connect('insert-ordered-list', self.on_toggle_ordered_list) self.connect('insert-quote', self.on_toggle_quote) self.connect('insert-link', self.on_insert_link) self.connect('insert-image', self.on_insert_image) self.scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True) self.scrolled.get_style_context().add_class('scrolled-editor') 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