Beispiel #1
0
    def __init__(self, config):
        super().__init__()
        self.config = config
        self.webPage = QTWSWebPage(self.config)
        self.setPage(self.webPage)
        QTWSPluginManager.instance().each(
            lambda plugin: plugin.web_engine_setup(self))

        if self.config.menu_disabled:
            self.setContextMenuPolicy(Qt.NoContextMenu)
        else:
            self.setContextMenuPolicy(Qt.CustomContextMenu)
            self.customContextMenuRequested.connect(self.__show_menu)

        self.__create_actions()

        self.urlChanged.connect(self.__url_changed)

        self.settings().setAttribute(
            QWebEngineSettings.FullScreenSupportEnabled, True)
        self.settings().setAttribute(
            QWebEngineSettings.JavascriptCanOpenWindows, True)
        self.settings().setAttribute(QWebEngineSettings.ScrollAnimatorEnabled,
                                     True)
        self.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True)

        self.profile = QWebEngineProfile.defaultProfile()
        self.profile.setCachePath(self.profile.cachePath() + "/" +
                                  self.config.name)
        self.profile.setPersistentStoragePath(
            self.profile.persistentStoragePath() + "/" + self.config.name)
        self.profile.setHttpCacheMaximumSize(self.config.cache_mb * 1024 *
                                             1024)
        QTWSPluginManager.instance().each(
            lambda plugin: plugin.web_profile_setup(self.profile))
Beispiel #2
0
    def __init__(self,
                 app_id,
                 config_filename: str,
                 url: str = None,
                 profile: str = None):
        super().__init__()

        self.config = QTWSConfig(config_filename, app_id)
        self.app_settings = QSettings(self.config.name, "Save State", self)

        self._profile_id = profile

        QTWSPluginManager.instance().load_plugins(self.config)
        self.__init_ui(url)
        self.__init_web_view()
        self.__read_settings()
        self.__init_shortcuts()

        self.enter_event_handler = EnterEventHandler()
        self.setMouseTracking(True)
        self.installEventFilter(self.enter_event_handler)
        self.default_flags = self.windowFlags()

        QTWSPluginManager.instance().each(
            lambda plugin: plugin.window_setup(self))
Beispiel #3
0
    def __init_shortcuts(self):
        self.__keyF11 = QShortcut(self)
        self.__keyF11.setKey(Qt.Key_F11)
        self.__keyF11.activated.connect(self.__action_full_screen)

        self.__keyCtrlQ = QShortcut(self)
        self.__keyCtrlQ.setKey(Qt.CTRL + Qt.Key_Q)
        self.__keyCtrlQ.activated.connect(self.__action_quit)

        self.__keyCtrlH = QShortcut(self)
        self.__keyCtrlH.setKey(Qt.CTRL + Qt.Key_H)
        self.__keyCtrlH.activated.connect(self.__action_home)

        self.__keyCtrlR = QShortcut(self)
        self.__keyCtrlR.setKey(Qt.CTRL + Qt.Key_R)
        self.__keyCtrlR.activated.connect(self.__action_reload)

        self.__keyF5 = QShortcut(self)
        self.__keyF5.setKey(Qt.Key_F5)
        self.__keyF5.activated.connect(self.__action_reload)

        self.__keyAltLeft = QShortcut(self)
        self.__keyAltLeft.setKey(Qt.ALT + Qt.Key_Left)
        self.__keyAltLeft.activated.connect(self.__action_back)

        QTWSPluginManager.instance().each(
            lambda plugin: plugin.register_shortcuts(self))
Beispiel #4
0
    def __show_menu(self, position: QPoint):
        self.menu = QMenu()

        if not self.page().history().canGoBack():
            self.__actionBack.setEnabled(False)
        self.menu.addAction(self.__actionBack)
        self.menu.addAction(self.__actionReload)
        self.menu.addAction(self.__actionHome)
        self.menu.addAction(self.__actionShare)
        self.menu.addAction(self.__actionOpenBrowser)

        if len(self.__customActions) > 0:
            self.menu.addSeparator()

        for action in self.__customActions:
            if action == '-':
                self.menu.addSeparator()
            else:
                self.menu.addAction(action)

        self.menu.addSeparator()

        for plugin in QTWSPluginManager.instance().plugins:
            plugin.add_menu_items(self.menu)
            self.menu.addSeparator()

        self.menu.addAction(self.__actionQuit)

        # Handles all the custom actions using the
        # URL stored in the action's data field
        self.menu.triggered.connect(self.__menu_click)
        self.menu.popup(self.mapToGlobal(position))
Beispiel #5
0
    def __init__(self, config: QTWSConfig, window, profile_name: str = None):
        super().__init__()
        self.config = config
        self.window = window

        if profile_name is None or profile_name.lower() == 'default':
            self.profile = QWebEngineProfile.defaultProfile()
        else:
            self.profile = QWebEngineProfile(profile_name)

        maxCache = self.config.cache_mb * 1024 * 1024
        self.profile.setHttpCacheMaximumSize(maxCache)

        self.profile.downloadRequested.connect(
            lambda item: self.__download(item))

        QTWSPluginManager.instance().each(
            lambda plugin: plugin.web_profile_setup(self.profile))

        self.webPage = QTWSWebPage(self.config, self.profile)
        self.setPage(self.webPage)
        self.permission_manager = QTWSPermissionManager(self.webPage)

        QTWSPluginManager.instance().each(
            lambda plugin: plugin.web_engine_setup(self))

        if self.config.menu_disabled:
            self.setContextMenuPolicy(Qt.NoContextMenu)
        else:
            self.setContextMenuPolicy(Qt.CustomContextMenu)
            self.customContextMenuRequested.connect(self.__show_menu)

        self.__create_actions()

        self.urlChanged.connect(self.__url_changed)

        self.settings().setAttribute(
            QWebEngineSettings.FullScreenSupportEnabled, True)
        self.settings().setAttribute(
            QWebEngineSettings.JavascriptCanOpenWindows, True)
        self.settings().setAttribute(QWebEngineSettings.ScrollAnimatorEnabled,
                                     True)
        self.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True)

        self.download_windows = []
Beispiel #6
0
    def __init__(self,
                 app_id,
                 config_filename: str,
                 url: str,
                 app_chooser: AppChooser = None):
        super().__init__()

        self.config = QTWSConfig(config_filename, app_id)
        self.app_chooser = app_chooser
        self.app_settings = QSettings(self.config.name, "Save State", self)

        QTWSPluginManager.instance().load_plugins(self.config)
        self.__init_ui(url)
        self.__init_web_view()
        self.__read_settings()
        self.__init_shortcuts()

        QTWSPluginManager.instance().each(
            lambda plugin: plugin.window_setup(self))
Beispiel #7
0
    def __check_whitelisted(self, url: QUrl):
        for plugin in QTWSPluginManager.instance().plugins:
            if plugin.is_url_whitelisted(url):
                return True

        return False
Beispiel #8
0
 def __url_changed(self, status):
     QTWSPluginManager.instance().each(
         lambda plugin: plugin.on_page_loaded(self.url()))
Beispiel #9
0
    def closeEvent(self, event: QCloseEvent):
        self.__write_settings()

        QTWSPluginManager.instance().each(
            lambda plugin: plugin.close_event(self, event))