Пример #1
0
    def contextMenuEvent(self, event):
        context_menu = QMenu(self)
        exit_action = context_menu.addAction("Quit")
        action = context_menu.exec_(self.mapToGlobal(event.pos()))

        if action == exit_action:
            QApplication.instance().quit()
Пример #2
0
 def store_passwd(ok, during_shutdown):
     if ok == 'never':
         exclude = gprefs.get('never-store-password-for', {})
         exclude[key] = True
         password_exclusions.set(key, True)
     elif ok and not during_shutdown:
         QApplication.instance().store_password(
             url, username, password)
Пример #3
0
    def contextMenuEvent(self, event):

        cmenu = QMenu(self)

        newAct = cmenu.addAction("New")
        openAct = cmenu.addAction("Open")
        quitAct = cmenu.addAction("Quit")
        action = cmenu.exec(self.mapToGlobal(event.pos()))

        if action == quitAct:
            QApplication.instance().quit()
Пример #4
0
 def send_text_using_keys(self, text):
     if self.host_widget is not None and not sip.isdeleted(
             self.host_widget):
         self.host_widget.setFocus(Qt.FocusReason.OtherFocusReason)
         with QApplication.instance().key_filter.disable_filtering:
             for ch in text:
                 key = getattr(Qt, f'Key_{ch.upper()}', Qt.Key.Key_A)
                 QApplication.sendEvent(
                     self.host_widget,
                     QKeyEvent(QEvent.Type.KeyPress, key,
                               Qt.KeyboardModifier(0), ch))
             # Ensure key events are delivered before any other processing
             while QApplication.instance().processEvents():
                 pass
Пример #5
0
 def mousePressEvent(self, ev):
     if ev.button() == Qt.MouseButton.LeftButton:
         from .actions import show_downloads
         app = QApplication.instance()
         w = app.activeWindow()
         if hasattr(w, 'get_tab_for_load'):
             show_downloads(w)
Пример #6
0
    def __init_ui(self):
        self.log.debug("Initializing UI")
        self.setWindowTitle("Revenant")
        # TODO: Update this with some sort of connection string when connected
        self.status_bar.showMessage("Not Connected")

        self.__add_output_window()
        self.__add_input_field()

        exit_action = QAction(QIcon("exit.png"), "&Exit", self)
        exit_action.setShortcut("Ctrl-Q")
        exit_action.setStatusTip("Exit")
        exit_action.triggered.connect(QApplication.instance().quit)

        view_status_bar = QAction("Status Bar", self, checkable=True)
        view_status_bar.setStatusTip("Show the status bar")
        view_status_bar.setChecked(True)
        view_status_bar.triggered.connect(self.toggle_menu)

        menubar = self.menuBar()
        file_menu = menubar.addMenu("&File")
        file_menu.addAction(exit_action)
        view_menu = menubar.addMenu("View")
        view_menu.addAction(view_status_bar)

        self.show()
Пример #7
0
 def focusInEvent(self, ev):
     # Needed because in Qt 5.11 the no focus focus policy is broken
     app = QApplication.instance()
     window = app.activeWindow()
     if hasattr(window, 'current_tab'):
         ct = window.current_tab
         if ct is not None:
             ct.setFocus(Qt.FocusReason.OtherFocusReason)
Пример #8
0
 def __call__(self, cmd, rest, window):
     from PyQt6.QtWidgets import QApplication
     from .passwd.db import password_db
     from .passwd.gui import PasswordManager
     app = QApplication.instance()
     if app.ask_for_master_password(window):
         d = PasswordManager(password_db, parent=window)
         d.exec()
Пример #9
0
 def get_login_credentials(self, url):
     # return {'password': '******', 'autologin': False, 'username': '******', 'notes': None}
     if not QApplication.instance().ask_for_master_password(self):
         return
     if password_db.join():
         key = key_from_url(url)
         accounts = password_db.get_accounts(key)
         if accounts:
             return accounts[0]
Пример #10
0
 def __call__(self, cmd, rest, window):
     from PyQt6.QtWidgets import QApplication
     if not rest.strip():
         rest = os.path.join(tempfile.gettempdir(), 'unnamed.vise-session')
     with open(rest, 'wb') as f:
         session_data = QApplication.instance().serialize_state()
         f.write(pickle.dumps(session_data, pickle.HIGHEST_PROTOCOL))
     window.show_status_message(
         _('Exported session to: %s') % rest, 5, 'success')
Пример #11
0
 def has_active_downloads(self, val):
     val = bool(val)
     changed = val != self._has_active_downloads
     self._has_active_downloads = val
     if changed:
         app = QApplication.instance()
         for w in app.windows:
             di = w.downloads_indicator
             (di.start if val else di.stop)()
Пример #12
0
    def initUI(self):

        qbtn = QPushButton('Quit', self)
        qbtn.clicked.connect(QApplication.instance().quit)
        qbtn.resize(qbtn.sizeHint())
        qbtn.move(50, 50)

        self.setGeometry(300, 300, 350, 250)
        self.setWindowTitle('Quit button')
        self.show()
Пример #13
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, self._m.index(1))
     painter.save()
     parent = self.parent() or QApplication.instance()
     style = parent.style()
     try:
         index.data(Qt.ItemDataRole.UserRole).draw_item(
             painter, style, option)
     finally:
         painter.restore()
Пример #14
0
 def icon_url_changed(self, url):
     dc = QApplication.instance().disk_cache.data(url)
     if dc is not None:
         with closing(dc):
             raw = dc.readAll()
             p = QPixmap()
             p.loadFromData(raw)
             if not p.isNull():
                 ic = QIcon()
                 ic.addPixmap(p)
                 self.set_data(DECORATION_ROLE, ic)
Пример #15
0
 def move_cursor_to_corner(self):
     '''
     Move cursor to bottom right corner of screen.
     '''
     screen = QApplication.instance().primaryScreen()
     try:
         QCursor().setPos(screen, screen.size().width(), screen.size().height())
     except:
         # Moves the cursor the primary screen to the global screen position (x, y).
         # Sometimes, setPos(QScreen, Int, Int) API don't exists.
         QCursor().setPos(screen.size().width(), screen.size().height())
Пример #16
0
    def __init__(self, url: str, home_url: str, icon: QIcon, ua: str):
        super().__init__()
        self.home_url = QUrl(home_url)
        self.web_view = QWebEngineView()
        self.page = MyWebPage(QApplication.instance().applicationName(), ua)

        self._setup_ui(icon)
        self._setup_events()
        self._setup_webview()
        self.page.setUrl(QUrl(url))
        self.web_view.show()
Пример #17
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.setCursor(Qt.CursorShape.PointingHandCursor)
     self.setToolTip(self.no_downloads_tooltip)
     pal = (parent or QApplication.instance()).palette()
     self.dark = pal.color(QPalette.ColorRole.Text)
     self.light = pal.color(QPalette.ColorRole.Base)
     self.update()
     self.setMinimumWidth(STATUS_BAR_HEIGHT - 4)
     self.setMinimumHeight(STATUS_BAR_HEIGHT - 4)
     self.running = False
Пример #18
0
    def paint_(self, painter, option, index):
        # NOTE not used yet, maybe draw an arrow on the cell?
        val = index.data(Qt.ItemDataRole.DisplayRole)
        style = QApplication.instance().style()

        opt = QStyleOptionComboBox()
        opt.text = str(val)
        opt.rect = option.rect
        style.drawComplexControl(QStyle.ComplexControl.CC_ComboBox, opt,
                                 painter)
        super().paint(painter, option, index)
Пример #19
0
def _paste_url(selection_start, selection_end, source_frame_id, node_id):
    window = QApplication.instance().activeWindow()

    def do_paste(text):
        text = text or ''
        text = text.partition(' ')[2].strip()
        t = getattr(window, 'current_tab', None)
        if t is not None:
            python_to_js(t, 'insert_text_in_saved_node', text, selection_start,
                         selection_end, source_frame_id, node_id)

    window.ask('copyurl ', do_paste)
Пример #20
0
    def initUI(self):

        exitAct = QAction(QIcon('exit24.png'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(QApplication.instance().quit)

        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(exitAct)

        self.setGeometry(300, 300, 350, 250)
        self.setWindowTitle('Toolbar')
        self.show()
Пример #21
0
 def download_created(self, download_item):
     self.items.append(download_item)
     download_item.receivedBytesChanged.connect(self.on_state_change)
     download_item.isFinishedChanged.connect(self.on_state_change)
     download_item.stateChanged.connect(self.on_state_change)
     download_item.last_tick = (monotonic(), 0)
     download_item.rates = [-1]
     for tab in self.itertabs():
         self.create_item(tab, download_item)
     self.has_active_downloads = True
     w = QApplication.instance().activeWindow()
     if hasattr(w, 'show_status_message'):
         w.show_status_message(_('Download of %s started!') % download_item.downloadFileName(), 2)
Пример #22
0
 def icon(self):
     if self._icon is None:
         self._icon = QIcon()
         url = places.favicon_url(self.place_id)
         if url is not None:
             f = QApplication.instance().disk_cache.data(QUrl(url))
             if f is not None:
                 with closing(f):
                     raw = f.readAll()
                 p = QPixmap()
                 p.loadFromData(raw)
                 if not p.isNull():
                     self._icon.addPixmap(p)
     return self._icon
Пример #23
0
    def on_login_form_submit(self, url, username, password):
        if not username or not password:
            return
        key = key_from_url(url)
        if password_exclusions.get(key, False):
            return
        if not QApplication.instance().ask_for_master_password(self):
            return
        if key not in password_db:

            def store_passwd(ok, during_shutdown):
                if ok == 'never':
                    exclude = gprefs.get('never-store-password-for', {})
                    exclude[key] = True
                    password_exclusions.set(key, True)
                elif ok and not during_shutdown:
                    QApplication.instance().store_password(
                        url, username, password)

            self.popup(
                _('Remember password for: {0}?').format(key), store_passwd,
                {_('Never'): 'never'})
        else:
            QApplication.instance().store_password(url, username, password)
Пример #24
0
def missing_icon():
    global _missing_icon
    if _missing_icon is None:
        p = QPixmap(ICON_SIZE, ICON_SIZE)
        p.fill(Qt.GlobalColor.transparent)
        painter = QPainter(p)
        pal = QApplication.instance().palette()
        painter.setPen(
            QPen(pal.color(QPalette.ColorRole.Text), 0, Qt.PenStyle.DashLine))
        margin = 3
        r = p.rect().adjusted(margin, margin, -margin, -margin)
        painter.drawRect(r)
        painter.end()
        _missing_icon = QIcon(p)
    return _missing_icon
Пример #25
0
    def initUI(self):

        exitAct = QAction(QIcon('exit.png'), '&Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.setStatusTip('Exit application')
        exitAct.triggered.connect(QApplication.instance().quit)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAct)

        self.setGeometry(300, 300, 350, 250)
        self.setWindowTitle('Simple menu')
        self.show()
Пример #26
0
 def delete_removed_tabs(self, tabs):
     # Delete tabs that have already been removed from the tab tree
     for tab in tabs:
         self.deleted_tabs_cache.append(tab.serialize_state())
         tab.break_cycles()
         try:
             self.tabs.remove(tab)
         except ValueError:
             pass
         self.stack.removeWidget(tab)
         tab.close()
         # As of Qt 5.11 closing many tabs without processing events between
         # closes causes Qt to crash
         num = 10
         app = QApplication.instance()
         while app.processEvents(
                 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents,
                 100) and num > 0:
             num -= 1
Пример #27
0
    def __init__(self):
        super().__init__()
        self.app = QApplication.instance()
        self.setWindowTitle(gbl.title)
        self.setMinimumSize(QSize(1000, 400))
        self.minesite_changed.connect(self.update_minesite_label)
        self.minesite_label = QLabel(
            self
        )  # permanent label for status bar so it isnt changed by statusTips
        self.minesite_label.setToolTip(
            'Global MineSite > Set with [Ctrl + Shift + M]')
        self.rows_label = QLabel(self)
        self.statusBar().addPermanentWidget(self.rows_label)
        self.statusBar().addPermanentWidget(self.minesite_label)

        # Settings
        s = QSettings('sms', 'smseventlog', self)

        screen_point = s.value('window position', False)
        screen_size = s.value('window size', False)

        # if screen size/left anchor pt values are not set or out of range, use default
        if not (screen_point and screen_size
                and gbl.check_screen_point(screen_point)):
            screen_point = QPoint(50, 50)
            screen_size = QSize(1200, 1000)

        # move/resize MainWindow to last position/size
        self.resize(screen_size)
        self.move(screen_point)
        self.settings = s

        self.menus = {}
        self.create_actions()

        self.tabs = TabWidget(self)
        self.setCentralWidget(self.tabs)
        self.update_minesite_label()

        self.threadpool = QThreadPool(self)
        log.debug('Mainwindow init finished.')
Пример #28
0
def download_requested(download_item):
    app = QApplication.instance()
    if not download_item.isSavePageDownload():
        fname = download_item.fname = download_item.downloadFileName() or 'file%d' % next(file_counter)
    else:
        fmt = misc_config('save_format', default='files')
        download_item.setSavePageFormat(
            QWebEngineDownloadRequest.SavePageFormat.MimeHtmlSaveFormat if fmt == 'mhtml' else QWebEngineDownloadRequest.SavePageFormat.CompleteHtmlSaveFormat)
        path = save_page_path_map.pop(download_item.url().toString(), None)
        if path:
            download_item.fname = os.path.basename(path)
            download_item.setDownloadFileName(download_item.fname)
        else:

            fname = download_item.downloadFileName()
            if fmt != 'mhtml' and fname.endswith('.mhtml'):
                fname = fname.rpartition('.')[0] + '.html'
            download_item.fname = fname
    download_item.setDownloadDirectory(get_download_dir())
    download_item.setDownloadFileName(download_item.fname)
    download_item.accept()
    app.downloads.download_created(download_item)
Пример #29
0
 def __call__(self, cmd, rest, window):
     if cmd == 'copyurl':
         QApplication.clipboard().setText(rest)
         window.save_url_in_places(parse_url(rest))
         return
     rest = rest.strip()
     if rest.startswith('http://') or rest.startswith(
             'https://') or rest.startswith('vise:') or rest.startswith(
                 'chrome://'):
         is_search = False
     else:
         is_search = rest.strip() and (' ' in rest
                                       or '.' not in rest.strip('.'))
     url = search_engine(rest) if is_search else parse_url(rest)
     if cmd in {'open', 'topen', 'tabopen'}:
         window.open_url(url,
                         in_current_tab=cmd == 'open',
                         switch_to_tab=True)
     else:
         window = QApplication.instance().new_window(
             is_private=cmd.startswith('p'))
         window.show()
         window.open_url(url, in_current_tab=True)
Пример #30
0
 def create_downloads(*args):
     di = FakeDownloadItem()
     app = QApplication.instance()
     app.downloads.download_created(di)
     app.downloads.download_created(FakeDownloadItem(size=100 * 1024))