Beispiel #1
0
 def __init__(self, parent=None):
     super().__init__(parent)
     config.set_register_stylesheet(self)
     self.enabled = False
     self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
     self.setTextVisible(False)
     self.hide()
def test_set_register_stylesheet(delete, stylesheet_param, update, qtbot,
                                 config_stub, caplog):
    config_stub.val.colors.hints.fg = 'magenta'
    stylesheet = "{{ conf.colors.hints.fg }}"

    with caplog.at_level(9):  # VDEBUG
        if stylesheet_param:
            obj = StyleObj()
            config.set_register_stylesheet(obj,
                                           stylesheet=stylesheet,
                                           update=update)
        else:
            obj = StyleObj(stylesheet)
            config.set_register_stylesheet(obj, update=update)

    assert caplog.messages[-1] == 'stylesheet for StyleObj: magenta'

    assert obj.rendered_stylesheet == 'magenta'

    if delete:
        with qtbot.waitSignal(obj.destroyed):
            obj.deleteLater()

    config_stub.val.colors.hints.fg = 'yellow'

    if delete or not update:
        expected = 'magenta'
    else:
        expected = 'yellow'

    assert obj.rendered_stylesheet == expected
Beispiel #3
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.setObjectName(self.__class__.__name__)
     config.set_register_stylesheet(self)
     self._hover_url = None
     self._normal_url = None
     self._normal_url_type = UrlType.normal
    def __init__(self, win_id: int, parent: QWidget = None) -> None:
        super().__init__(parent)
        self.pattern = None  # type: typing.Optional[str]
        self._win_id = win_id
        config.instance.changed.connect(self._on_config_changed)

        self._active = False

        self._delegate = completiondelegate.CompletionItemDelegate(self)
        self.setItemDelegate(self._delegate)
        self.setStyle(QStyleFactory.create('Fusion'))
        config.set_register_stylesheet(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.setHeaderHidden(True)
        self.setAlternatingRowColors(True)
        self.setIndentation(0)
        self.setItemsExpandable(False)
        self.setExpandsOnDoubleClick(False)
        self.setAnimated(False)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        # WORKAROUND
        # This is a workaround for weird race conditions with invalid
        # item indexes leading to segfaults in Qt.
        #
        # Some background: http://bugs.quassel-irc.org/issues/663
        # The proposed fix there was later reverted because it didn't help.
        self.setUniformRowHeights(True)
        self.hide()
Beispiel #5
0
    def __init__(self, *, win_id, tab_id, tab, private, parent=None):
        super().__init__(parent)
        if utils.is_mac:
            # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-42948
            # See https://github.com/glimpsebrowser/glimpsebrowser/issues/462
            self.setStyle(QStyleFactory.create('Fusion'))
        # FIXME:qtwebengine this is only used to set the zoom factor from
        # the QWebPage - we should get rid of it somehow (signals?)
        self.tab = tab
        self._tabdata = tab.data
        self.win_id = win_id
        self.scroll_pos = (-1, -1)
        self._old_scroll_pos = (-1, -1)
        self._tab_id = tab_id

        page = webpage.BrowserPage(win_id=self.win_id,
                                   tab_id=self._tab_id,
                                   tabdata=tab.data,
                                   private=private,
                                   parent=self)
        page.setVisibilityState(
            QWebPage.VisibilityStateVisible if self.isVisible(
            ) else QWebPage.VisibilityStateHidden)

        self.setPage(page)

        config.set_register_stylesheet(self)
Beispiel #6
0
 def __init__(self, win_id, parent=None):
     super().__init__(parent)
     self.setTextFormat(Qt.RichText)
     self._win_id = win_id
     self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
     self.hide()
     self._show_timer = usertypes.Timer(self, 'keyhint_show')
     self._show_timer.timeout.connect(self.show)
     self._show_timer.setSingleShot(True)
     config.set_register_stylesheet(self)
Beispiel #7
0
 def on_caret_selection_toggled(self, selection):
     """Update the statusbar when entering/leaving caret selection mode."""
     log.statusbar.debug("Setting caret selection {}".format(selection))
     if selection:
         self._set_mode_text("caret selection")
         self._color_flags.caret = ColorFlags.CaretMode.selection
     else:
         self._set_mode_text("caret")
         self._color_flags.caret = ColorFlags.CaretMode.on
     config.set_register_stylesheet(self, update=False)
Beispiel #8
0
 def _update_url(self):
     """Update the displayed URL if the url or the hover url changed."""
     if self._hover_url is not None:
         self.setText(self._hover_url)
         self._urltype = UrlType.hover
     elif self._normal_url is not None:
         self.setText(self._normal_url)
         self._urltype = self._normal_url_type
     else:
         self.setText('')
         self._urltype = UrlType.normal
     config.set_register_stylesheet(self, update=False)
Beispiel #9
0
    def __init__(self, win_id, parent=None):
        super().__init__(parent)
        self._layout = QVBoxLayout(self)
        self._layout.setContentsMargins(10, 10, 10, 10)
        self._win_id = win_id
        self._prompt = None

        self.setObjectName('PromptContainer')
        self.setAttribute(Qt.WA_StyledBackground, True)
        config.set_register_stylesheet(self)

        message.global_bridge.prompt_done.connect(self._on_prompt_done)
        prompt_queue.show_prompts.connect(self._on_show_prompts)
        message.global_bridge.mode_left.connect(self._on_global_mode_left)
Beispiel #10
0
 def __init__(self, win_id, parent=None):
     super().__init__(parent)
     self._win_id = win_id
     self.setStyle(TabBarStyle())
     self._set_font()
     config.instance.changed.connect(self._on_config_changed)
     self.vertical = False
     self._auto_hide_timer = QTimer()
     self._auto_hide_timer.setSingleShot(True)
     self._auto_hide_timer.timeout.connect(self.maybe_hide)
     self._on_show_switching_delay_changed()
     self.setAutoFillBackground(True)
     self.drag_in_progress = False
     config.set_register_stylesheet(self)
     QTimer.singleShot(0, self.maybe_hide)
Beispiel #11
0
    def __init__(self, *, win_id, private, parent=None):
        super().__init__(parent)
        objreg.register('statusbar', self, scope='window', window=win_id)
        self.setObjectName(self.__class__.__name__)
        self.setAttribute(Qt.WA_StyledBackground)
        config.set_register_stylesheet(self)

        self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)

        self._win_id = win_id
        self._color_flags = ColorFlags()
        self._color_flags.private = private

        self._hbox = QHBoxLayout(self)
        self._set_hbox_padding()
        self._hbox.setSpacing(5)

        self._stack = QStackedLayout()
        self._hbox.addLayout(self._stack)
        self._stack.setContentsMargins(0, 0, 0, 0)

        self.cmd = command.Command(private=private, win_id=win_id)
        self._stack.addWidget(self.cmd)
        objreg.register('status-command', self.cmd, scope='window',
                        window=win_id)

        self.txt = textwidget.Text()
        self._stack.addWidget(self.txt)

        self.cmd.show_cmd.connect(self._show_cmd_widget)
        self.cmd.hide_cmd.connect(self._hide_cmd_widget)
        self._hide_cmd_widget()

        self.url = url.UrlText()
        self.percentage = percentage.Percentage()
        self.backforward = backforward.Backforward()
        self.tabindex = tabindex.TabIndex()
        self.keystring = keystring.KeyString()
        self.prog = progress.Progress(self)
        self._draw_widgets()

        config.instance.changed.connect(self._on_config_changed)
        QTimer.singleShot(0, self.maybe_hide)
Beispiel #12
0
 def __init__(self, win_id, parent=None):
     super().__init__(parent)
     if not utils.is_mac:
         self.setStyle(QStyleFactory.create('Fusion'))
     config.set_register_stylesheet(self)
     self.setResizeMode(QListView.Adjust)
     self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
     self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
     self.setFocusPolicy(Qt.NoFocus)
     self.setFlow(QListView.LeftToRight)
     self.setSpacing(1)
     self._menu = None
     model = objreg.get('download-model', scope='window', window=win_id)
     model.rowsInserted.connect(functools.partial(update_geometry, self))
     model.rowsRemoved.connect(functools.partial(update_geometry, self))
     model.dataChanged.connect(functools.partial(update_geometry, self))
     self.setModel(model)
     self.setWrapping(True)
     self.setContextMenuPolicy(Qt.CustomContextMenu)
     self.customContextMenuRequested.connect(self.show_context_menu)
     self.clicked.connect(self.on_clicked)
 def __init__(self, level, text, replace, parent=None):
     super().__init__(text, parent)
     self.replace = replace
     self.setAttribute(Qt.WA_StyledBackground, True)
     stylesheet = """
         padding-top: 2px;
         padding-bottom: 2px;
     """
     if level == usertypes.MessageLevel.error:
         stylesheet += """
             background-color: {{ conf.colors.messages.error.bg }};
             color: {{ conf.colors.messages.error.fg }};
             font: {{ conf.fonts.messages.error }};
             border-bottom: 1px solid {{ conf.colors.messages.error.border }};
         """
     elif level == usertypes.MessageLevel.warning:
         stylesheet += """
             background-color: {{ conf.colors.messages.warning.bg }};
             color: {{ conf.colors.messages.warning.fg }};
             font: {{ conf.fonts.messages.warning }};
             border-bottom:
                 1px solid {{ conf.colors.messages.warning.border }};
         """
     elif level == usertypes.MessageLevel.info:
         stylesheet += """
             background-color: {{ conf.colors.messages.info.bg }};
             color: {{ conf.colors.messages.info.fg }};
             font: {{ conf.fonts.messages.info }};
             border-bottom: 1px solid {{ conf.colors.messages.info.border }}
         """
     else:  # pragma: no cover
         raise ValueError("Invalid level {!r}".format(level))
     # We don't bother with set_register_stylesheet here as it's short-lived
     # anyways.
     config.set_register_stylesheet(self,
                                    stylesheet=stylesheet,
                                    update=False)
Beispiel #14
0
    def set_mode_active(self, mode, val):
        """Setter for self.{insert,command,caret}_active.

        Re-set the stylesheet after setting the value, so everything gets
        updated by Qt properly.
        """
        if mode == usertypes.KeyMode.insert:
            log.statusbar.debug("Setting insert flag to {}".format(val))
            self._color_flags.insert = val
        if mode == usertypes.KeyMode.passthrough:
            log.statusbar.debug("Setting passthrough flag to {}".format(val))
            self._color_flags.passthrough = val
        if mode == usertypes.KeyMode.command:
            log.statusbar.debug("Setting command flag to {}".format(val))
            self._color_flags.command = val
        elif mode in [usertypes.KeyMode.prompt, usertypes.KeyMode.yesno]:
            log.statusbar.debug("Setting prompt flag to {}".format(val))
            self._color_flags.prompt = val
        elif mode == usertypes.KeyMode.caret:
            if not val:
                # Turning on is handled in on_current_caret_selection_toggled
                log.statusbar.debug("Setting caret mode off")
                self._color_flags.caret = ColorFlags.CaretMode.off
        config.set_register_stylesheet(self, update=False)
Beispiel #15
0
    def __init__(self, *, private, geometry=None, parent=None):
        """Create a new main window.

        Args:
            geometry: The geometry to load, as a bytes-object (or None).
            private: Whether the window is in private browsing mode.
            parent: The parent the window should get.
        """
        super().__init__(parent)
        # Late import to avoid a circular dependency
        # - browsertab -> hints -> webelem -> mainwindow -> bar -> browsertab
        from glimpsebrowser.mainwindow import tabbedbrowser
        from glimpsebrowser.mainwindow.statusbar import bar

        self.setAttribute(Qt.WA_DeleteOnClose)
        self._commandrunner = None
        self._overlays = []
        self.win_id = next(win_id_gen)
        self.registry = objreg.ObjectRegistry()
        objreg.window_registry[self.win_id] = self
        objreg.register('main-window',
                        self,
                        scope='window',
                        window=self.win_id)
        tab_registry = objreg.ObjectRegistry()
        objreg.register('tab-registry',
                        tab_registry,
                        scope='window',
                        window=self.win_id)

        message_bridge = message.MessageBridge(self)
        objreg.register('message-bridge',
                        message_bridge,
                        scope='window',
                        window=self.win_id)

        self.setWindowTitle('glimpsebrowser')
        self._vbox = QVBoxLayout(self)
        self._vbox.setContentsMargins(0, 0, 0, 0)
        self._vbox.setSpacing(0)

        self._init_downloadmanager()
        self._downloadview = downloadview.DownloadView(self.win_id)

        if config.val.content.private_browsing:
            # This setting always trumps what's passed in.
            private = True
        else:
            private = bool(private)
        self._private = private
        self.tabbed_browser = tabbedbrowser.TabbedBrowser(win_id=self.win_id,
                                                          private=private,
                                                          parent=self)
        objreg.register('tabbed-browser',
                        self.tabbed_browser,
                        scope='window',
                        window=self.win_id)
        self._init_command_dispatcher()

        # We need to set an explicit parent for StatusBar because it does some
        # show/hide magic immediately which would mean it'd show up as a
        # window.
        self.status = bar.StatusBar(win_id=self.win_id,
                                    private=private,
                                    parent=self)

        self._add_widgets()
        self._downloadview.show()

        self._init_completion()

        log.init.debug("Initializing modes...")
        modeman.init(self.win_id, self)

        self._commandrunner = runners.CommandRunner(self.win_id,
                                                    partial_match=True)

        self._keyhint = keyhintwidget.KeyHintView(self.win_id, self)
        self._add_overlay(self._keyhint, self._keyhint.update_geometry)

        self._prompt_container = prompt.PromptContainer(self.win_id, self)
        self._add_overlay(self._prompt_container,
                          self._prompt_container.update_geometry,
                          centered=True,
                          padding=10)
        objreg.register('prompt-container',
                        self._prompt_container,
                        scope='window',
                        window=self.win_id)
        self._prompt_container.hide()

        self._messageview = messageview.MessageView(parent=self)
        self._add_overlay(self._messageview, self._messageview.update_geometry)

        self._init_geometry(geometry)
        self._connect_signals()

        # When we're here the statusbar might not even really exist yet, so
        # resizing will fail. Therefore, we use singleShot QTimers to make sure
        # we defer this until everything else is initialized.
        QTimer.singleShot(0, self._connect_overlay_signals)
        config.instance.changed.connect(self._on_config_changed)

        objreg.get("app").new_window.emit(self)
        self._set_decoration(config.val.window.hide_decoration)

        self.state_before_fullscreen = self.windowState()
        config.set_register_stylesheet(self)