コード例 #1
0
ファイル: spell.py プロジェクト: sbraz/gaupol
 def __init__(self, language):
     """Initialize a :class:`SpellChecker` instance."""
     glanguage = Gspell.language_lookup(language)
     if glanguage is None:
         raise aeidon.Error('Language "{}" not supported'.format(language))
     self.checker = Gspell.Checker(language=glanguage)
     self.language = language
     self.replacements = []
     self.read_replacements()
コード例 #2
0
ファイル: preferences.py プロジェクト: 72Zn/gajim
    def _on_use_speller(value, *args):
        if not value:
            return

        lang = app.settings.get('speller_language')
        gspell_lang = Gspell.language_lookup(lang)
        if gspell_lang is None:
            gspell_lang = Gspell.language_get_default()
        app.settings.set('speller_language', gspell_lang.get_code())
        for ctrl in get_app_window('Preferences').get_all_controls():
            if isinstance(ctrl, ChatControlBase):
                ctrl.set_speller()
コード例 #3
0
 def _apply_speller(self):
     if app.settings.get('use_speller') and app.is_installed('GSPELL'):
         lang = app.settings.get('speller_language')
         gspell_lang = Gspell.language_lookup(lang)
         if gspell_lang is None:
             gspell_lang = Gspell.language_get_default()
         spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(
             self._message_buffer)
         spell_buffer.set_spell_checker(Gspell.Checker.new(gspell_lang))
         spell_view = Gspell.TextView.get_from_gtk_text_view(
             self._ui.message_textview)
         spell_view.set_inline_spell_checking(True)
         spell_view.set_enable_language_menu(True)
コード例 #4
0
 def on_speller_checkbutton_toggled(self, widget):
     active = widget.get_active()
     app.config.set('use_speller', active)
     if not active:
         return
     lang = app.config.get('speller_language')
     gspell_lang = Gspell.language_lookup(lang)
     if gspell_lang is None:
         gspell_lang = Gspell.language_get_default()
     if gspell_lang is None:
         AspellDictError(lang)
         app.config.set('use_speller', False)
         widget.set_active(False)
     else:
         app.config.set('speller_language', gspell_lang.get_code())
         self.apply_speller()
コード例 #5
0
ファイル: spellchecker.py プロジェクト: sfeuga/Setzer
 def __init__(self, source_view):
     self.checker = Gspell.Checker()
     self.spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(
         source_view.get_buffer())
     self.spell_buffer.set_spell_checker(self.checker)
     self.spell_view = Gspell.TextView.get_from_gtk_text_view(source_view)
     self.spell_view.set_enable_language_menu(False)
     self.spell_navigator = Gspell.NavigatorTextView.new(source_view)
コード例 #6
0
    def setup(self):
        self.view = Gspell.LanguageChooserDialog()
        self.view.set_language_code(self.workspace.spellchecking_language_code)
        self.view.set_modal(True)
        self.view.set_transient_for(self.main_window)

        self.headerbar = Gtk.HeaderBar()
        self.headerbar.set_title(_('Spellchecking Language'))
        self.headerbar.show_all()
        action_area = self.view.get_action_area()
        cancel_button = action_area.get_children()[0]
        select_button = action_area.get_children()[1]
        action_area.remove(cancel_button)
        action_area.remove(select_button)
        self.headerbar.pack_start(cancel_button)
        self.headerbar.pack_end(select_button)
        select_button.get_style_context().add_class('suggested-action')
        action_area.hide()
        self.view.set_titlebar(self.headerbar)
コード例 #7
0
ファイル: app.py プロジェクト: slokhorst/gajim
def detect_dependencies():
    import gi

    # ZEROCONF
    try:
        import pybonjour  # pylint: disable=unused-import
        _dependencies['PYBONJOUR'] = True
    except Exception:
        pass

    try:
        gi.require_version('Avahi', '0.6')
        from gi.repository import Avahi  # pylint: disable=unused-import
        _dependencies['AVAHI'] = True
    except Exception:
        pass

    try:
        gi.require_version('Gst', '1.0')
        from gi.repository import Gst
        _dependencies['GST'] = True
    except Exception:
        pass

    try:
        gi.require_version('Farstream', '0.2')
        from gi.repository import Farstream
        _dependencies['FARSTREAM'] = True
    except Exception:
        pass

    try:
        if _dependencies['GST'] and _dependencies['FARSTREAM']:
            Gst.init(None)
            conference = Gst.ElementFactory.make('fsrtpconference', None)
            conference.new_session(Farstream.MediaType.AUDIO)
            _dependencies['AV'] = True
    except Exception as error:
        log('gajim').warning('AV dependency test failed: %s', error)

    # GEOCLUE
    try:
        gi.require_version('Geoclue', '2.0')
        from gi.repository import Geoclue  # pylint: disable=unused-import
        _dependencies['GEOCLUE'] = True
    except (ImportError, ValueError):
        pass

    # UPNP
    try:
        gi.require_version('GUPnPIgd', '1.0')
        from gi.repository import GUPnPIgd
        global gupnp_igd
        gupnp_igd = GUPnPIgd.SimpleIgd()
        _dependencies['UPNP'] = True
    except ValueError:
        pass

    # IDLE
    try:
        from gajim.common import idle
        if idle.Monitor.is_available():
            _dependencies['IDLE'] = True
    except Exception:
        pass

    # GSOUND
    try:
        gi.require_version('GSound', '1.0')
        from gi.repository import GLib
        from gi.repository import GSound
        global gsound_ctx
        gsound_ctx = GSound.Context()
        try:
            gsound_ctx.init()
            _dependencies['GSOUND'] = True
        except GLib.Error as error:
            log('gajim').warning('GSound init failed: %s', error)
    except (ImportError, ValueError):
        pass

    # GSPELL
    try:
        gi.require_version('Gspell', '1')
        from gi.repository import Gspell
        langs = Gspell.language_get_available()
        for lang in langs:
            log('gajim').info('%s (%s) dict available', lang.get_name(),
                              lang.get_code())
        if langs:
            _dependencies['GSPELL'] = True
    except (ImportError, ValueError):
        pass

    # Print results
    for dep, val in _dependencies.items():
        log('gajim').info('%-13s %s', dep, val)

    log('gajim').info('Used language: %s', LANG)
コード例 #8
0
ファイル: single_message.py プロジェクト: bj-h/gajim
    def __init__(self,
                 account,
                 to='',
                 action='',
                 from_whom='',
                 subject='',
                 message='',
                 resource='',
                 session=None,
                 form_node=None):
        Gtk.ApplicationWindow.__init__(self)
        self.set_application(app.app)
        self.set_title(_('Send Single Message'))
        self.set_name('SendSingleMessageWindow')
        self.account = account
        self.action = action

        self.subject = subject
        self.message = message
        self.to = to
        self.from_whom = from_whom
        self.resource = resource
        self.session = session

        self._ui = get_builder('single_message_window.ui')
        self.message_tv_buffer = self._ui.message_textview.get_buffer()
        self.conversation_textview = ConversationTextview(
            account, used_in_history_window=True)
        self.conversation_textview.tv.show()
        self.conversation_textview.tv.set_left_margin(6)
        self.conversation_textview.tv.set_right_margin(6)
        self.conversation_textview.tv.set_top_margin(6)
        self.conversation_textview.tv.set_bottom_margin(6)
        self.conversation_tv_buffer = self.conversation_textview.tv.get_buffer(
        )
        self._ui.conversation_scrolledwindow.add(self.conversation_textview.tv)

        self.form_widget = None
        parent_box = self._ui.conversation_scrolledwindow.get_parent()
        if form_node:
            self.form_widget = DataFormWidget(form_node)
            self.form_widget.show_all()
            self._ui.conversation_scrolledwindow.hide()
            self._ui.message_label_received.hide()
            parent_box.add(self.form_widget)
            parent_box.child_set_property(self.form_widget, 'top-attach', 2)
            parent_box.child_set_property(self.form_widget, 'left-attach', 0)
            parent_box.child_set_property(self.form_widget, 'width', 2)
            self.action = 'form'

        self.message_tv_buffer.connect('changed', self.update_char_counter)
        if isinstance(to, list):
            jid = ', '.join([i[0].get_full_jid() for i in to])
            self._ui.to_entry.set_text(jid)
        else:
            self._ui.to_entry.set_text(to)

        if app.config.get('use_speller') and app.is_installed(
                'GSPELL') and action == 'send':
            lang = app.config.get('speller_language')
            gspell_lang = Gspell.language_lookup(lang)
            if gspell_lang is None:
                AspellDictError(lang)
            else:
                spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(
                    self._ui.message_textview.get_buffer())
                spell_buffer.set_spell_checker(Gspell.Checker.new(gspell_lang))
                spell_view = Gspell.TextView.get_from_gtk_text_view(
                    self._ui.message_textview)
                spell_view.set_inline_spell_checking(True)
                spell_view.set_enable_language_menu(True)

        self.prepare_widgets_for(self.action)

        # set_text(None) raises TypeError exception
        if self.subject is None:
            self.subject = _('(No subject)')
        self._ui.subject_entry.set_text(self.subject)
        self._ui.subject_from_entry_label.set_text(self.subject)

        if to == '':
            liststore = get_completion_liststore(self._ui.to_entry)
            self.completion_dict = helpers.get_contact_dict_for_account(
                account)
            keys = sorted(self.completion_dict.keys())
            for jid in keys:
                contact = self.completion_dict[jid]
                status_icon = get_icon_name(contact.show)
                liststore.append((status_icon, jid))
        else:
            self.completion_dict = {}

        self._ui.to_entry.connect('changed', self.on_to_entry_changed)
        self._ui.connect_signals(self)

        # get window position and size from config
        resize_window(self._ui.single_message_window,
                      app.config.get('single-msg-width'),
                      app.config.get('single-msg-height'))
        move_window(self._ui.single_message_window,
                    app.config.get('single-msg-x-position'),
                    app.config.get('single-msg-y-position'))

        self._ui.single_message_window.show_all()
コード例 #9
0
ファイル: app.py プロジェクト: bj-h/gajim
def detect_dependencies():
    import gi

    # ZEROCONF
    try:
        import pybonjour  # pylint: disable=unused-import
        _dependencies['PYBONJOUR'] = True
    except Exception:
        pass

    try:
        gi.require_version('Avahi', '0.6')
        from gi.repository import Avahi  # pylint: disable=unused-import
        _dependencies['AVAHI'] = True
    except Exception:
        pass

    # FARSTREAM
    try:
        if os.name == 'nt':
            root_path = Path(sys.executable).parents[1]
            fs_plugin_path = str(root_path / 'lib' / 'farstream-0.2')
            gst_plugin_path = str(root_path / 'lib' / 'gstreamer-1.0')
            os.environ['FS_PLUGIN_PATH'] = fs_plugin_path
            os.environ['GST_PLUGIN_PATH'] = gst_plugin_path
        gi.require_version('Farstream', '0.2')
        from gi.repository import Farstream
        gi.require_version('Gst', '1.0')
        from gi.repository import Gst
        try:
            Gst.init(None)
            conference = Gst.ElementFactory.make('fsrtpconference', None)
            conference.new_session(Farstream.MediaType.AUDIO)
        except Exception as error:
            log('gajim').info(error)
        _dependencies['FARSTREAM'] = True
    except (ImportError, ValueError):
        pass

    # GEOCLUE
    try:
        gi.require_version('Geoclue', '2.0')
        from gi.repository import Geoclue  # pylint: disable=unused-import
        _dependencies['GEOCLUE'] = True
    except (ImportError, ValueError):
        pass

    # UPNP
    try:
        gi.require_version('GUPnPIgd', '1.0')
        from gi.repository import GUPnPIgd
        global gupnp_igd
        gupnp_igd = GUPnPIgd.SimpleIgd()
        _dependencies['UPNP'] = True
    except ValueError:
        pass

    # PYCURL
    try:
        import pycurl  # pylint: disable=unused-import
        _dependencies['PYCURL'] = True
    except ImportError:
        pass

    # IDLE
    try:
        from gajim.common import idle
        if idle.Monitor.is_available():
            _dependencies['IDLE'] = True
    except Exception:
        pass

    # GSPELL
    try:
        gi.require_version('Gspell', '1')
        from gi.repository import Gspell
        langs = Gspell.language_get_available()
        for lang in langs:
            log('gajim').info('%s (%s) dict available', lang.get_name(),
                              lang.get_code())
        if langs:
            _dependencies['GSPELL'] = True
    except (ImportError, ValueError):
        pass

    # Print results
    for dep, val in _dependencies.items():
        log('gajim').info('%-13s %s', dep, val)

    log('gajim').info('Used language: %s', LANG)
コード例 #10
0
ファイル: single_message.py プロジェクト: slokhorst/gajim
    def __init__(self, account, to='', action='', from_whom='', subject='',
                 message='', resource='', session=None):
        Gtk.ApplicationWindow.__init__(self)
        self.set_application(app.app)
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_show_menubar(False)
        self.set_title(_('Send Single Message'))
        self.set_name('SendSingleMessageWindow')
        self.account = account
        self._action = action

        self._subject = subject
        self._message = message
        self._to = to
        self._from_whom = from_whom
        self._resource = resource
        self._session = session

        self._ui = get_builder('single_message_window.ui')
        self._message_tv_buffer = self._ui.message_textview.get_buffer()
        self._conversation_textview = ConversationTextview(
            account, used_in_history_window=True)
        self._conversation_textview.tv.show()
        self._conversation_textview.tv.set_left_margin(6)
        self._conversation_textview.tv.set_right_margin(6)
        self._conversation_textview.tv.set_top_margin(6)
        self._conversation_textview.tv.set_bottom_margin(6)
        self._ui.conversation_scrolledwindow.add(
            self._conversation_textview.tv)

        self._message_tv_buffer.connect('changed', self._update_char_counter)
        if isinstance(to, list):
            jid = ', '.join([i[0].jid for i in to])
            self._ui.to_entry.set_text(jid)
        else:
            self._ui.to_entry.set_text(to)

        if (app.settings.get('use_speller') and
                app.is_installed('GSPELL') and
                action == 'send'):
            lang = app.settings.get('speller_language')
            gspell_lang = Gspell.language_lookup(lang)
            if gspell_lang is None:
                gspell_lang = Gspell.language_get_default()
            spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(
                self._ui.message_textview.get_buffer())
            spell_buffer.set_spell_checker(Gspell.Checker.new(gspell_lang))
            spell_view = Gspell.TextView.get_from_gtk_text_view(
                self._ui.message_textview)
            spell_view.set_inline_spell_checking(True)
            spell_view.set_enable_language_menu(True)

        self._prepare_widgets_for(self._action)

        # set_text(None) raises TypeError exception
        if self._subject is None:
            self._subject = _('(No subject)')
        self._ui.subject_entry.set_text(self._subject)
        self._ui.subject_from_entry_label.set_text(self._subject)

        if to == '':
            liststore = get_completion_liststore(self._ui.to_entry)
            self._completion_dict = helpers.get_contact_dict_for_account(
                account)
            keys = sorted(self._completion_dict.keys())
            for jid in keys:
                contact = self._completion_dict[jid]
                status_icon = get_icon_name(contact.show)
                liststore.append((status_icon, jid))
        else:
            self._completion_dict = {}

        self.add(self._ui.box)

        self.connect('delete-event', self._on_delete)
        self.connect('destroy', self._on_destroy)
        self.connect('key-press-event', self._on_key_press_event)

        self._ui.to_entry.connect('changed', self._on_to_entry_changed)
        self._ui.connect_signals(self)

        # get window position and size from config
        resize_window(self,
                      app.settings.get('single-msg-width'),
                      app.settings.get('single-msg-height'))
        move_window(self,
                    app.settings.get('single-msg-x-position'),
                    app.settings.get('single-msg-y-position'))

        self.show_all()
コード例 #11
0
    def __init__(self, transient_for, settings):
        super().__init__(transient_for=transient_for, modal=True)

        self.settings = settings
        self.set_default_size(340, 340)

        hints = Gdk.Geometry()
        hints.min_width = 340
        hints.min_height = 340
        self.set_geometry_hints(None, hints, Gdk.WindowHints.MIN_SIZE)

        self.set_border_width(5)
        self.set_deletable(False)
        self.set_title(_('Preferences'))

        langs_available: List[
            Gspell.Language] = Gspell.language_get_available()
        langs_available_model = Gtk.ListStore(str, str)
        for lang in langs_available:
            langs_available_model.append((lang.get_code(), lang.get_name()))

        self.toast = Granite.WidgetsToast(title=_("Toast"))

        indent_width = Gtk.SpinButton.new_with_range(1, 24, 1)
        indent_width.set_value(self.settings.get_int('indent-width'))
        indent_width.connect('value-changed', self.on_indent_width)

        self.sort_switch = Gtk.Switch(halign=Gtk.Align.START,
                                      valign=Gtk.Align.CENTER)
        self.sort_switch.set_state(self.settings.get_boolean('sort-desc'))
        self.sort_switch.connect("state-set", self.on_sort_desc)

        self.spellcheck_switch = Gtk.Switch(halign=Gtk.Align.START,
                                            valign=Gtk.Align.CENTER)
        self.spellcheck_switch.set_state(
            self.settings.get_boolean('spellcheck'))
        self.spellcheck_switch.connect("state-set", self.on_spellcheck)

        self.spellcheck_language_chooser = Gtk.ComboBox()
        self.spellcheck_language_chooser.set_model(langs_available_model)
        self.spellcheck_language_chooser.set_id_column(0)
        self.spellcheck_language_chooser.set_entry_text_column(1)
        renderer_text = Gtk.CellRendererText()
        self.spellcheck_language_chooser.pack_start(renderer_text, True)
        self.spellcheck_language_chooser.add_attribute(renderer_text, "text",
                                                       1)
        self.spellcheck_language_chooser.set_active_id(
            self.settings.get_string('spellcheck-language'))
        self.spellcheck_language_chooser.connect('changed',
                                                 self.on_spellcheck_language)

        self.autosave_switch = Gtk.Switch(halign=Gtk.Align.START,
                                          valign=Gtk.Align.CENTER)
        self.autosave_switch.set_state(self.settings.get_boolean('autosave'))
        self.autosave_switch.connect("state-set", self.on_autosave)

        self.autoindent_switch = Gtk.Switch(halign=Gtk.Align.START,
                                            valign=Gtk.Align.CENTER)
        self.autoindent_switch.set_state(
            self.settings.get_boolean('autoindent'))
        self.autoindent_switch.connect("state-set", self.on_autoindent)

        self.spaces_tabs_switch = Gtk.Switch(halign=Gtk.Align.START,
                                             valign=Gtk.Align.CENTER)
        self.spaces_tabs_switch.set_state(
            self.settings.get_boolean('spaces-instead-of-tabs'))
        self.spaces_tabs_switch.connect("state-set", self.on_spaces_tabs)

        general_grid = Gtk.Grid(column_spacing=8, row_spacing=8)

        general_grid.attach(Granite.HeaderLabel(_("General")), 0, 0, 3, 1)
        general_grid.attach(
            Gtk.Label(_("Save files when changed:"),
                      hexpand=True,
                      halign=Gtk.Align.END), 0, 1, 2, 1)
        general_grid.attach(self.autosave_switch, 2, 1, 1, 1)
        general_grid.attach(
            Gtk.Label(_("Sort documents backwards:"),
                      hexpand=True,
                      halign=Gtk.Align.END), 0, 2, 2, 1)
        general_grid.attach(self.sort_switch, 2, 2, 1, 1)
        general_grid.attach(
            Gtk.Label(_("Spell checking:"), hexpand=True,
                      halign=Gtk.Align.END), 0, 3, 2, 1)
        general_grid.attach(self.spellcheck_switch, 2, 3, 1, 1)
        general_grid.attach(
            Gtk.Label(_("Language:"), hexpand=True, halign=Gtk.Align.END), 0,
            4, 2, 1)
        general_grid.attach(self.spellcheck_language_chooser, 2, 4, 1, 1)

        general_grid.attach(Granite.HeaderLabel(_("Tabs")), 0, 5, 3, 1)
        general_grid.attach(
            Gtk.Label(_("Automatic indentation:"),
                      hexpand=True,
                      halign=Gtk.Align.END), 0, 6, 2, 1)
        general_grid.attach(self.autoindent_switch, 2, 6, 1, 1)
        general_grid.attach(
            Gtk.Label(_("Insert spaces instead of tabs:"),
                      hexpand=True,
                      halign=Gtk.Align.END), 0, 7, 2, 1)
        general_grid.attach(self.spaces_tabs_switch, 2, 7, 1, 1)
        general_grid.attach(
            Gtk.Label(_("Tab width:"), hexpand=True, halign=Gtk.Align.END), 0,
            8, 2, 1)
        general_grid.attach(indent_width, 2, 8, 2, 1)

        # Interface grid
        interface_grid = Gtk.Grid(column_spacing=8, row_spacing=8)
        scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True)

        self.dark_theme_switch = Gtk.Switch(halign=Gtk.Align.START,
                                            valign=Gtk.Align.CENTER)
        self.dark_theme_switch.set_state(
            self.settings.get_boolean('prefer-dark-theme'))
        self.dark_theme_switch.connect("state-set", self.on_dark_theme)

        style_chooser = GtkSource.StyleSchemeChooserWidget(hexpand=True,
                                                           vexpand=True)
        style_chooser.connect('notify::style-scheme', self.on_scheme_changed)
        scrolled.add(style_chooser)

        scheme = GtkSource.StyleSchemeManager.get_default().get_scheme(
            self.settings.get_string('stylescheme'))
        if not scheme:
            scheme = GtkSource.StyleSchemeManager().get_scheme("classic")

        style_chooser.set_style_scheme(scheme)

        interface_grid.attach(Granite.HeaderLabel(_("Appearance")), 0, 0, 3, 1)
        interface_grid.attach(
            Gtk.Label(_("Prefer dark theme:"),
                      hexpand=True,
                      halign=Gtk.Align.END), 0, 1, 2, 1)
        interface_grid.attach(self.dark_theme_switch, 2, 1, 1, 1)
        interface_grid.attach(Granite.HeaderLabel(_("Styles")), 0, 2, 3, 1)
        interface_grid.attach(scrolled, 0, 3, 3, 1)

        # Export grid
        export_grid = Gtk.Grid(column_spacing=8, row_spacing=8)

        self.render_medium(export_grid)
        self.render_writeas(export_grid)

        # Main Stack
        main_stack = Gtk.Stack(margin=6, margin_bottom=18, margin_top=8)
        main_stack.add_titled(general_grid, "behavior", _("Behavior"))
        main_stack.add_titled(interface_grid, "interface", _("Interface"))
        main_stack.add_titled(export_grid, "export", _("Export"))

        main_stackswitcher = Gtk.StackSwitcher(homogeneous=True)
        main_stackswitcher.set_stack(main_stack)
        main_stackswitcher.set_halign(Gtk.Align.CENTER)

        main_grid = Gtk.Grid()
        main_grid.attach(main_stackswitcher, 0, 0, 1, 1)
        main_grid.attach(main_stack, 0, 1, 1, 1)

        self.overlay = Gtk.Overlay()
        self.overlay.add(main_grid)
        self.overlay.add_overlay(self.toast)
        self.get_content_area().add(self.overlay)

        close_button = Gtk.Button(label=_("Close"))
        close_button.connect('clicked', self.on_close_activated)
        self.add_action_widget(close_button, 0)
コード例 #12
0
def detect_dependencies():
    import gi

    # ZEROCONF
    try:
        if os.name == 'nt':
            import pybonjour
            _dependencies['PYBONJOUR'] = True
        else:
            import dbus
            _dependencies['PYTHON-DBUS'] = True
    except Exception:
        pass

    # python-gnupg
    try:
        import gnupg
        '''
        We need https://pypi.python.org/pypi/python-gnupg
        but https://pypi.python.org/pypi/gnupg shares the same package name.
        It cannot be used as a drop-in replacement.
        We test with a version check if python-gnupg is installed as it is
        on a much lower version number than gnupg
        Also we need at least python-gnupg 0.3.8
        '''
        v_gnupg = gnupg.__version__
        if V(v_gnupg) < V('0.3.8') or V(v_gnupg) > V('1.0.0'):
            log('gajim').info('Gajim needs python-gnupg >= 0.3.8')
            raise ImportError
        _dependencies['PYGPG'] = True
    except ImportError:
        pass

    # GPG BINARY
    import subprocess

    def test_gpg(binary='gpg'):
        if os.name == 'nt':
            gpg_cmd = binary + ' -h >nul 2>&1'
        else:
            gpg_cmd = binary + ' -h >/dev/null 2>&1'
        if subprocess.call(gpg_cmd, shell=True):
            return False
        return True

    if test_gpg(binary='gpg2'):
        _dependencies['GPG_BINARY'] = 'gpg2'
    elif test_gpg(binary='gpg'):
        _dependencies['GPG_BINARY'] = 'gpg'

    # FARSTREAM
    try:
        if os.name == 'nt':
            os.environ['FS_PLUGIN_PATH'] = 'gtk\\lib\\farstream-0.1'
            os.environ['GST_PLUGIN_PATH'] = 'gtk\\lib\\gstreamer-0.10'
        gi.require_version('Farstream', '0.2')
        from gi.repository import Farstream
        gi.require_version('Gst', '1.0')
        from gi.repository import Gst
        try:
            Gst.init(None)
            conference = Gst.ElementFactory.make('fsrtpconference', None)
            session = conference.new_session(Farstream.MediaType.AUDIO)
        except Exception as error:
            log('gajim').info(error)
        _dependencies['FARSTREAM'] = True
    except (ImportError, ValueError):
        pass

    # GEOCLUE
    try:
        gi.require_version('Geoclue', '2.0')
        from gi.repository import Geoclue
        _dependencies['GEOCLUE'] = True
    except (ImportError, ValueError):
        pass

    # UPNP
    try:
        gi.require_version('GUPnPIgd', '1.0')
        from gi.repository import GUPnPIgd
        gupnp_igd = GUPnPIgd.SimpleIgd()
        _dependencies['UPNP'] = True
    except ValueError:
        pass

    # PYCURL
    try:
        import pycurl
        _dependencies['PYCURL'] = True
    except ImportError:
        pass

    # IDLE
    try:
        from gajim.common import idle
        if idle.Monitor.is_available():
            _dependencies['IDLE'] = True
    except Exception:
        pass

    # GSPELL
    try:
        gi.require_version('Gspell', '1')
        from gi.repository import Gspell
        langs = Gspell.language_get_available()
        for lang in langs:
            log('gajim').info('%s (%s) dict available',
                              lang.get_name(), lang.get_code())
        if langs:
            _dependencies['GSPELL'] = True
    except (ImportError, ValueError):
        pass

    # Print results
    for dep, val in _dependencies.items():
        log('gajim').info('%-13s %s', dep, val)
コード例 #13
0
    HAVE_PYCURL = False

try:
    from gajim.common import sleepy
    if sleepy.SUPPORTED:
        HAVE_IDLE = True
except Exception:
    glog.info(_('Unable to load idle module'))
    HAVE_IDLE = False

HAVE_SPELL = False
try:
    spell_log = logging.getLogger('gajim.speller')
    gi.require_version('Gspell', '1')
    from gi.repository import Gspell
    langs = Gspell.language_get_available()
    for lang in langs:
        spell_log.info('%s (%s) dict available', lang.get_name(),
                       lang.get_code())
    if langs:
        HAVE_SPELL = True
    else:
        spell_log.info('No dicts available')
except (ImportError, ValueError):
    pass

gajim_identity = {'type': 'pc', 'category': 'client', 'name': 'Gajim'}
gajim_common_features = [
    nbxmpp.NS_BYTESTREAM, nbxmpp.NS_SI, nbxmpp.NS_FILE, nbxmpp.NS_MUC,
    nbxmpp.NS_MUC_USER, nbxmpp.NS_MUC_ADMIN, nbxmpp.NS_MUC_OWNER,
    nbxmpp.NS_MUC_CONFIG, nbxmpp.NS_COMMANDS, nbxmpp.NS_DISCO_INFO, 'ipv6',
コード例 #14
0
    def __init__(self, storage: Storage, settings: Settings):
        super().__init__()

        self.document = None
        self.storage = storage
        self.settings = settings

        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 = 920
        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)
        self.view.connect('move-cursor', self.on_view_move_cursor)

        # 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)

        # Initialize stats calculations and connect `destroy` event
        self.stats_handler = StatsHandler(buffer=self.buffer)
        self.stats_overlay.connect('destroy', lambda x: self.stats_handler.on_destroy(self))
        self.stats_handler.connect('update-document-stats', self.update_stats)
        self.stats = self.stats_handler.stats

        self.add(self.overlay)

        # SpellChecker
        self.font_desc = Pango.FontDescription()
        self.spellchecker = Gspell.Checker()
        self.spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(self.view.get_buffer())
        self.spell_buffer.set_spell_checker(self.spellchecker)
        spell_language = Gspell.Language.lookup(self.settings.get_string('spellcheck-language'))
        if spell_language:
            self.spellchecker.set_language(spell_language)

        self.spell_view = Gspell.TextView.get_from_gtk_text_view(self.view)
        self.spell_view.set_enable_language_menu(False)

        self.search_settings = GtkSource.SearchSettings(wrap_around=True)
        self.search_context = GtkSource.SearchContext(buffer=self.buffer,
                                                      settings=self.search_settings)
        self.search_iter = None
コード例 #15
0
    def __init__(self, account, to='', action='', from_whom='', subject='',
            message='', resource='', session=None, form_node=None):
        self.instances.append(self)
        self.account = account
        self.action = action

        self.subject = subject
        self.message = message
        self.to = to
        self.from_whom = from_whom
        self.resource = resource
        self.session = session

        self.xml = get_builder('single_message_window.ui')
        self.window = self.xml.get_object('single_message_window')
        self.count_chars_label = self.xml.get_object('count_chars_label')
        self.from_label = self.xml.get_object('from_label')
        self.from_entry = self.xml.get_object('from_entry')
        self.to_label = self.xml.get_object('to_label')
        self.to_entry = self.xml.get_object('to_entry')
        self.subject_entry = self.xml.get_object('subject_entry')
        self.message_scrolledwindow = self.xml.get_object(
                'message_scrolledwindow')
        self.message_textview = self.xml.get_object('message_textview')
        self.message_tv_buffer = self.message_textview.get_buffer()
        self.conversation_scrolledwindow = self.xml.get_object(
                'conversation_scrolledwindow')
        self.conversation_textview = ConversationTextview(
            account, used_in_history_window=True)
        self.conversation_textview.tv.show()
        self.conversation_tv_buffer = self.conversation_textview.tv.get_buffer()
        self.xml.get_object('conversation_scrolledwindow').add(
                self.conversation_textview.tv)

        self.form_widget = None
        parent_box = self.xml.get_object('conversation_scrolledwindow').\
                           get_parent()
        if form_node:
            dataform = dataforms.ExtendForm(node=form_node)
            dataform.type_ = 'submit'
            self.form_widget = DataFormWidget(dataform)
            self.form_widget.show_all()
            parent_box.add(self.form_widget)
            parent_box.child_set_property(self.form_widget, 'position',
                parent_box.child_get_property(self.xml.get_object(
                'conversation_scrolledwindow'), 'position'))
            self.action = 'form'

        self.send_button = self.xml.get_object('send_button')
        self.reply_button = self.xml.get_object('reply_button')
        self.send_and_close_button = self.xml.get_object('send_and_close_button')
        self.cancel_button = self.xml.get_object('cancel_button')
        self.close_button = self.xml.get_object('close_button')
        self.message_tv_buffer.connect('changed', self.update_char_counter)
        if isinstance(to, list):
            jid = ', '.join( [i[0].get_full_jid() for i in to])
            self.to_entry.set_text(jid)
            self.to_entry.set_sensitive(False)
        else:
            self.to_entry.set_text(to)

        if app.config.get('use_speller') and app.is_installed('GSPELL') and action == 'send':
            lang = app.config.get('speller_language')
            gspell_lang = Gspell.language_lookup(lang)
            if gspell_lang is None:
                AspellDictError(lang)
            else:
                spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(
                    self.message_textview.get_buffer())
                spell_buffer.set_spell_checker(Gspell.Checker.new(gspell_lang))
                spell_view = Gspell.TextView.get_from_gtk_text_view(
                    self.message_textview)
                spell_view.set_inline_spell_checking(True)
                spell_view.set_enable_language_menu(True)

        self.prepare_widgets_for(self.action)

        # set_text(None) raises TypeError exception
        if self.subject is None:
            self.subject = ''
        self.subject_entry.set_text(self.subject)


        if to == '':
            liststore = get_completion_liststore(self.to_entry)
            self.completion_dict = helpers.get_contact_dict_for_account(account)
            keys = sorted(self.completion_dict.keys())
            for jid in keys:
                contact = self.completion_dict[jid]
                status_icon = get_iconset_name_for(contact.show)
                liststore.append((status_icon, jid))
        else:
            self.completion_dict = {}
        self.xml.connect_signals(self)

        # get window position and size from config
        resize_window(self.window,
            app.config.get('single-msg-width'),
            app.config.get('single-msg-height'))
        move_window(self.window,
            app.config.get('single-msg-x-position'),
            app.config.get('single-msg-y-position'))

        self.window.show_all()
コード例 #16
0
ファイル: dialogs.py プロジェクト: bj-h/gajim
    def __init__(self, on_response, show=None, show_pep=True):
        countdown_time = app.config.get('change_status_window_timeout')
        TimeoutDialog.__init__(self, countdown_time)
        self.show = show
        self.pep_dict = {}
        self.show_pep = show_pep
        self.on_response = on_response
        self.xml = get_builder('change_status_message_dialog.ui')
        self.dialog = self.xml.get_object('change_status_message_dialog')
        self.dialog.set_transient_for(app.interface.roster.window)
        msg = None
        if show:
            uf_show = helpers.get_uf_show(show)
            self.title_text = _('%s Status Message') % uf_show
            msg = app.config.get_per('statusmsg', '_last_' + self.show,
                                     'message')
            self.pep_dict['activity'] = app.config.get_per(
                'statusmsg', '_last_' + self.show, 'activity')
            self.pep_dict['subactivity'] = app.config.get_per(
                'statusmsg', '_last_' + self.show, 'subactivity')
            self.pep_dict['activity_text'] = app.config.get_per(
                'statusmsg', '_last_' + self.show, 'activity_text')
            self.pep_dict['mood'] = app.config.get_per('statusmsg',
                                                       '_last_' + self.show,
                                                       'mood')
            self.pep_dict['mood_text'] = app.config.get_per(
                'statusmsg', '_last_' + self.show, 'mood_text')
        else:
            self.title_text = _('Status Message')
        self.dialog.set_title(self.title_text)

        message_textview = self.xml.get_object('message_textview')
        self.message_buffer = message_textview.get_buffer()

        if app.config.get('use_speller') and app.is_installed('GSPELL'):
            lang = app.config.get('speller_language')
            gspell_lang = Gspell.language_lookup(lang)
            if gspell_lang is None:
                AspellDictError(lang)
            else:
                spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(
                    self.message_buffer)
                spell_buffer.set_spell_checker(Gspell.Checker.new(gspell_lang))
                spell_view = Gspell.TextView.get_from_gtk_text_view(
                    message_textview)
                spell_view.set_inline_spell_checking(True)
                spell_view.set_enable_language_menu(True)

        self.message_buffer.connect('changed', self.on_message_buffer_changed)
        if not msg:
            msg = ''
        msg = helpers.from_one_line(msg)
        self.message_buffer.set_text(msg)

        # have an empty string selectable, so user can clear msg
        self.preset_messages_dict = {'': ['', '', '', '', '', '']}
        for msg_name in app.config.get_per('statusmsg'):
            if msg_name.startswith('_last_'):
                continue
            opts = []
            for opt in [
                    'message', 'activity', 'subactivity', 'activity_text',
                    'mood', 'mood_text'
            ]:
                opts.append(app.config.get_per('statusmsg', msg_name, opt))
            opts[0] = helpers.from_one_line(opts[0])
            self.preset_messages_dict[msg_name] = opts
        sorted_keys_list = helpers.get_sorted_keys(self.preset_messages_dict)

        self.message_liststore = Gtk.ListStore(str)  # msg_name
        self.message_combobox = self.xml.get_object('message_combobox')
        self.message_combobox.set_model(self.message_liststore)
        cellrenderertext = Gtk.CellRendererText()
        self.message_combobox.pack_start(cellrenderertext, True)
        self.message_combobox.add_attribute(cellrenderertext, 'text', 0)
        for msg_name in sorted_keys_list:
            self.message_liststore.append((msg_name, ))

        if show_pep:
            self.draw_activity()
            self.draw_mood()
        else:
            # remove acvtivity / mood lines
            self.xml.get_object('activity_label').set_no_show_all(True)
            self.xml.get_object('activity_button').set_no_show_all(True)
            self.xml.get_object('mood_label').set_no_show_all(True)
            self.xml.get_object('mood_button').set_no_show_all(True)
            self.xml.get_object('activity_label').hide()
            self.xml.get_object('activity_button').hide()
            self.xml.get_object('mood_label').hide()
            self.xml.get_object('mood_button').hide()

        self.xml.connect_signals(self)
        self.run_timeout()
        self.dialog.connect('response', self.on_dialog_response)
        self.dialog.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
        self.dialog.show_all()
コード例 #17
0
    def __init__(self):
        GtkSource.View.__init__(self)
        self.set_buffer(DraftSourceBuffer())

        self._spell_checker = Gspell.Checker()
        buffer = self.get_buffer()
        gspell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(buffer)
        gspell_buffer.set_spell_checker(self._spell_checker)
        gspell_view = Gspell.TextView.get_from_gtk_text_view(self)
        gspell_view.set_inline_spell_checking(True)

        # TODO: Disabling this for now. These elements should not be created
        #       for every SourceView. Make DraftEditor own them.
        # builder = Gtk.Builder()
        # builder.add_from_resource('/org/gnome/Draft/editor.ui')

        # self._link_editor = builder.get_object('link_editor')
        # self._url_entry = builder.get_object('url_entry')
        # self._title_entry = builder.get_object('title_entry')
        # self._img_editor = builder.get_object('img_editor')
        # self._img_url_entry = builder.get_object('img_url_entry')
        # self._img_title_entry = builder.get_object('img_title_entry')
        # self._browse_images_button = builder.get_object('browse_images_button')
        # self._hint_window = builder.get_object('hint_window')

        # self._link_editor.set_relative_to(self)
        # self._img_editor.set_relative_to(self)

        # screen = self._hint_window.get_screen()
        # visual = screen.get_rgba_visual()
        # if visual is not None and screen.is_composited():
        #     self._hint_window.set_visual(visual)
        # self._hint_window.set_app_paintable(True)

        self.connect('event', self._on_event)
        self.connect('key-press-event', self._on_key_press)
        self.connect('button-press-event', self._on_button_press)
        self.connect('focus-in-event', self._on_focus_in)
        self.connect('focus-out-event', self._on_focus_out)

        # self._link_editor.connect('closed', self._on_link_editor_closed)
        # self._img_editor.connect('closed', self._on_link_editor_closed)
        # self._browse_images_button.connect('clicked', self._on_browse_images)
        # self._hint_window.connect('draw', self._on_hint_window_draw)

        self.cached_char_height = 0
        self.cached_char_width = 0
        self.set_has_tooltip(True)

        # visual margins and offsets
        self.set_visible(True)
        self.set_pixels_above_lines(3)
        self.set_pixels_below_lines(3)
        self.set_pixels_inside_wrap(6)
        self.set_wrap_mode(Gtk.WrapMode.WORD)
        self.set_left_margin(DEFAULT_LEFT_MARGIN)
        self.set_right_margin(DEFAULT_RIGHT_MARGIN)
        self.set_top_margin(self._calculated_top_margin)
        self.set_bottom_margin(self._calculated_bottom_margin)

        # formatting specific options
        self.set_auto_indent(True)
        self.set_indent_on_tab(True)
        self.set_insert_spaces_instead_of_tabs(True)
        self.set_indent_width(2)
        self.set_smart_backspace(True)
        self.set_highlight_current_line(True)

        # Variables for scroll animation setup
        self._tick_id = 0
        self._source = 0.0
        self._target = 0.0
        self._start_time = None
        self._end_time = None