Esempio n. 1
0
    def do_startup(self):
        Gtk.Application.do_startup(self)
        Handy.init()

        self._style_manager = Handy.StyleManager.get_default()
        if settings.get_int('theme') == 0:
            self._style_manager.set_color_scheme(Handy.ColorScheme.FORCE_LIGHT)
        elif settings.get_int('theme') == 1:
            self._style_manager.set_color_scheme(Handy.ColorScheme.FORCE_DARK)
        elif settings.get_int('theme') == 2:
            self._style_manager.set_color_scheme(Handy.ColorScheme.FORCE_LIGHT)
        elif settings.get_int('theme') == 3:
            self._style_manager.set_color_scheme(
                Handy.ColorScheme.PREFER_LIGHT)

        action = Gio.SimpleAction.new('prefs', None)
        action.connect('activate', self._prefs_cb)
        self.add_action(action)
        self.set_accels_for_action('app.prefs', ('<Ctrl>E', ))

        action = Gio.SimpleAction.new('theme_system', None)
        action.connect('activate', self._theme_system)
        self.add_action(action)

        action = Gio.SimpleAction.new('theme_light', None)
        action.connect('activate', self._theme_light)
        self.add_action(action)

        action = Gio.SimpleAction.new('theme_sepia', None)
        action.connect('activate', self._theme_sepia)
        self.add_action(action)

        action = Gio.SimpleAction.new('theme_dark', None)
        action.connect('activate', self._theme_dark)
        self.add_action(action)

        action = Gio.SimpleAction.new('shortcuts', None)
        action.connect('activate', self._shortcuts_cb)
        self.add_action(action)
        self.set_accels_for_action('app.shortcuts', ('<Ctrl>question', ))

        action = Gio.SimpleAction.new('about', None)
        action.connect('activate', self._about_cb)
        self.add_action(action)

        action = Gio.SimpleAction.new('quit', None)
        action.connect('activate', self._quit_cb)
        self.add_action(action)
        self.set_accels_for_action('app.quit', ('<Ctrl>Q', ))
Esempio n. 2
0
    def __init__(self, window):
        super().__init__()

        self._window = window

        gfile = Gio.File.new_for_uri(
            'resource:///com/github/hugolabe/Wike/ui/menu.css')
        css_provider = Gtk.CssProvider()
        css_provider.load_from_file(gfile)
        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), css_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_USER)

        theme = settings.get_int('theme')
        if theme == 0:
            self.light_button.set_active(True)
        elif theme == 1:
            self.dark_button.set_active(True)
        elif theme == 2:
            self.sepia_button.set_active(True)
        else:
            self.system_button.set_active(True)

        self.system_button.connect('toggled', self._system_button_toggled_cb)
        self.light_button.connect('toggled', self._light_button_toggled_cb)
        self.sepia_button.connect('toggled', self._sepia_button_toggled_cb)
        self.dark_button.connect('toggled', self._dark_button_toggled_cb)
Esempio n. 3
0
    def __init__(self):
        user_content = WebKit2.UserContentManager()
        super().__init__(user_content_manager=user_content)

        web_settings = self.get_settings()
        web_settings.set_default_font_size(settings.get_int('font-size'))
        settings.connect('changed::font-size',
                         self._settings_font_size_changed_cb, web_settings)

        self._set_style()
Esempio n. 4
0
    def __init__(self):
        super().__init__(settings=view_settings.web_settings,
                         user_content_manager=view_settings.user_content)

        theme = settings.get_int('theme')
        if theme == 1:
            self.set_background_color(Gdk.RGBA(0.1, 0.1, 0.1, 1))
        elif theme == 2:
            self.set_background_color(Gdk.RGBA(0.976, 0.953, 0.914, 1))
        elif theme == 3:
            if view_settings.style_manager.get_dark():
                self.set_background_color(Gdk.RGBA(0.1, 0.1, 0.1, 1))
            else:
                self.set_background_color(Gdk.RGBA(1, 1, 1, 1))
        else:
            self.set_background_color(Gdk.RGBA(1, 1, 1, 1))
Esempio n. 5
0
    def __init__(self):
        self.web_settings.set_default_font_size(settings.get_int('font-size'))

        gfile = Gio.File.new_for_uri(
            'resource:///com/github/hugolabe/Wike/styles/view.min.css')
        try:
            gfile_contents = gfile.load_contents(None)
        except:
            print('Can\'t load view css file from resources')
            self._css_view = ''
        else:
            self._css_view = gfile_contents[1].decode('utf-8')

        gfile = Gio.File.new_for_uri(
            'resource:///com/github/hugolabe/Wike/styles/dark.min.css')
        try:
            gfile_contents = gfile.load_contents(None)
        except:
            print('Can\'t load dark css file from resources')
            self._css_dark = ''
        else:
            self._css_dark = gfile_contents[1].decode('utf-8')

        gfile = Gio.File.new_for_uri(
            'resource:///com/github/hugolabe/Wike/styles/sepia.min.css')
        try:
            gfile_contents = gfile.load_contents(None)
        except:
            print('Can\'t load sepia css file from resources')
            self._css_sepia = ''
        else:
            self._css_sepia = gfile_contents[1].decode('utf-8')

        self.set_style()

        settings.connect('changed::font-size',
                         self._settings_font_size_changed_cb)
        settings.connect('changed::custom-font',
                         self._settings_custom_font_changed_cb)
        settings.connect('changed::font-family',
                         self._settings_custom_font_changed_cb)
        settings.connect('changed::preview-popups',
                         self._settings_preview_popups_changed_cb)
        settings.connect('changed::theme', self._settings_theme_changed_cb)
        self.style_manager.connect('notify::dark',
                                   self._system_theme_changed_cb)
Esempio n. 6
0
    def set_style(self):
        data_manager = web_context.get_website_data_manager()
        data_manager.clear(WebKit2.WebsiteDataTypes.MEMORY_CACHE, 0, None,
                           None, None)
        self.user_content.remove_all_style_sheets()

        style_view = WebKit2.UserStyleSheet(
            self._css_view, WebKit2.UserContentInjectedFrames.ALL_FRAMES,
            WebKit2.UserStyleLevel.USER, None, None)
        self.user_content.add_style_sheet(style_view)

        theme = settings.get_int('theme')
        if theme == 1:
            style_dark = WebKit2.UserStyleSheet(
                self._css_dark, WebKit2.UserContentInjectedFrames.ALL_FRAMES,
                WebKit2.UserStyleLevel.USER, None, None)
            self.user_content.add_style_sheet(style_dark)
        elif theme == 2:
            style_sepia = WebKit2.UserStyleSheet(
                self._css_sepia, WebKit2.UserContentInjectedFrames.ALL_FRAMES,
                WebKit2.UserStyleLevel.USER, None, None)
            self.user_content.add_style_sheet(style_sepia)
        elif theme == 3:
            if self.style_manager.get_dark():
                style_dark = WebKit2.UserStyleSheet(
                    self._css_dark,
                    WebKit2.UserContentInjectedFrames.ALL_FRAMES,
                    WebKit2.UserStyleLevel.USER, None, None)
                self.user_content.add_style_sheet(style_dark)

        if settings.get_boolean('custom-font'):
            css_font = 'body,h1,h2{font-family:"' + settings.get_string(
                'font-family') + '"!important}'
            style_font = WebKit2.UserStyleSheet(
                css_font, WebKit2.UserContentInjectedFrames.ALL_FRAMES,
                WebKit2.UserStyleLevel.USER, None, None)
            self.user_content.add_style_sheet(style_font)

        if not settings.get_boolean('preview-popups'):
            css_previews = '.mwe-popups{display:none!important}'
            style_previews = WebKit2.UserStyleSheet(
                css_previews, WebKit2.UserContentInjectedFrames.ALL_FRAMES,
                WebKit2.UserStyleLevel.USER, None, None)
            self.user_content.add_style_sheet(style_previews)
Esempio n. 7
0
 def _settings_font_size_changed_cb(self, settings, key, web_settings):
     web_settings.set_default_font_size(settings.get_int('font-size'))
Esempio n. 8
0
    def __init__(self, app):
        super().__init__(title='Wike', application=app)

        self.set_default_size(settings.get_int('window-width'),
                              settings.get_int('window-height'))
        if settings.get_boolean('window-max'): self.maximize()

        self.box.pack_end(wikiview, True, True, 0)

        self.headerbar = HeaderBar()
        self.set_titlebar(self.headerbar)

        actions = [('prev_page', self._prev_page_cb, ('<Alt>Left', )),
                   ('next_page', self._next_page_cb, ('<Alt>Right', )),
                   ('show_search', self._show_search_cb, ('F2', )),
                   ('show_bookmarks', self._show_bookmarks_cb, ('<Ctrl>B', )),
                   ('add_bookmark', self._add_bookmark_cb, ('<Ctrl>D', )),
                   ('show_langlinks', self._show_langlinks_cb, ('<Ctrl>L', )),
                   ('show_toc', self._show_toc_cb, ('<Ctrl>T', )),
                   ('main_page', self._main_page_cb, ('<Alt>Home', )),
                   ('random_article', self._random_article_cb, None),
                   ('show_historic', self._show_historic_cb, ('<Ctrl>H', )),
                   ('reload_page', self._reload_page_cb, ('F5', )),
                   ('search_text', self._search_text_cb, ('<Ctrl>F', )),
                   ('open_browser', self._open_browser_cb, None),
                   ('copy_url', self._copy_url_cb, ('<Ctrl>U', ))]

        for action, callback, accel in actions:
            simple_action = Gio.SimpleAction.new(action, None)
            simple_action.connect('activate', callback)
            self.add_action(simple_action)
            if accel: app.set_accels_for_action('win.' + action, accel)

        find_controller = wikiview.get_find_controller()
        nav_list = wikiview.get_back_forward_list()
        self.search_bar.connect_entry(self.textsearch_entry)

        wikiview.connect('load-wiki', self._wikiview_load_wiki_cb)
        wikiview.connect('load-changed', self._wikiview_load_changed_cb)
        wikiview.connect('load-failed', self._wikiview_load_failed_cb)
        wikiview.connect('add-bookmark', self._wikiview_add_bookmark_cb)
        self.textsearch_entry.connect('changed',
                                      self._textsearch_entry_changed_cb,
                                      find_controller)
        self.textsearch_entry.connect('activate',
                                      self._textsearch_entry_activate_cb,
                                      find_controller)
        self.textsearch_prev_button.connect(
            'clicked', self._textsearch_prev_button_clicked_cb,
            find_controller)
        self.textsearch_next_button.connect(
            'clicked', self._textsearch_next_button_clicked_cb,
            find_controller)
        find_controller.connect('found-text', self._find_controller_found_cb)
        find_controller.connect('failed-to-find-text',
                                self._find_controller_not_found_cb)
        find_controller.connect('counted-matches',
                                self._find_controller_matches_cb)
        nav_list.connect('changed', self._nav_list_changed_cb)
        self.notification_close_button.connect('clicked',
                                               self._hide_notification_cb)

        if settings.get_string('on-start-load') == 'main':
            wikiview.load_main()
        elif settings.get_string('on-start-load') == 'random':
            wikiview.load_random()
        else:
            if settings.get_string('last-uri'):
                wikiview.load_wiki(settings.get_string('last-uri'))
            else:
                wikiview.load_main()
Esempio n. 9
0
    def __init__(self, app, launch_uri):
        super().__init__(title='Wike', application=app)

        # Set default window icon name for XFCE, LXQt, MATE
        self.set_default_icon_name('com.github.hugolabe.Wike')

        self.set_default_size(settings.get_int('window-width'),
                              settings.get_int('window-height'))
        if settings.get_boolean('window-max'):
            self.maximize()

        self.page = PageBox(self)
        tabpage = self.tabview.append(self.page)

        self.headerbar = HeaderBar(self)
        self.window_box.pack_start(self.headerbar, False, True, 0)

        actions = [('prev_page', self._prev_page_cb, ('<Alt>Left', )),
                   ('next_page', self._next_page_cb, ('<Alt>Right', )),
                   ('new_tab', self._new_tab_cb, ('<Ctrl>N', )),
                   ('close_tab', self._close_tab_cb, ('<Ctrl>W', )),
                   ('next_tab', self._next_tab_cb, ('<Ctrl>Tab', )),
                   ('prev_tab', self._prev_tab_cb, ('<Shift><Ctrl>Tab', )),
                   ('show_search', self._show_search_cb, (
                       'F2',
                       '<Ctrl>K',
                   )), ('show_menu', self._show_menu_cb, ('F10', )),
                   ('show_bookmarks', self._show_bookmarks_cb, ('<Ctrl>B', )),
                   ('add_bookmark', self._add_bookmark_cb, ('<Ctrl>D', )),
                   ('show_langlinks', self._show_langlinks_cb, ('<Ctrl>L', )),
                   ('show_toc', self._show_toc_cb, ('<Ctrl>T', )),
                   ('main_page', self._main_page_cb, ('<Alt>Home', )),
                   ('random_article', self._random_article_cb, None),
                   ('show_historic', self._show_historic_cb, ('<Ctrl>H', )),
                   ('reload_page', self._reload_page_cb, (
                       'F5',
                       '<Ctrl>R',
                   )), ('search_text', self._search_text_cb, ('<Ctrl>F', )),
                   ('open_browser', self._open_browser_cb, None),
                   ('copy_url', self._copy_url_cb, ('<Ctrl>U', ))]

        for action, callback, accel in actions:
            simple_action = Gio.SimpleAction.new(action, None)
            simple_action.connect('activate', callback)
            self.add_action(simple_action)
            if accel:
                app.set_accels_for_action('win.' + action, accel)

        self.handler_selpage = self.tabview.connect(
            'notify::selected-page', self._tabview_selected_page_cb)
        self.tabview.connect('close-page', self._tabview_close_page_cb)
        self.notification_close_button.connect('clicked',
                                               self._hide_notification_cb)

        if launch_uri == 'notfound':
            self.page.wikiview.load_message(launch_uri, None)
        else:
            if launch_uri != '':
                self.page.wikiview.load_wiki(launch_uri)
            else:
                if settings.get_int('on-start-load') == 0:
                    self.page.wikiview.load_main()
                elif settings.get_int('on-start-load') == 1:
                    self.page.wikiview.load_random()
                else:
                    if settings.get_string('last-uri'):
                        self.page.wikiview.load_wiki(
                            settings.get_string('last-uri'))
                    else:
                        self.page.wikiview.load_main()