def wait(self, timeout=5.0): assert self._T is None, self._T self._T = self.startTimer(timeout * 1000) try: self._args = None QCoreApplication.instance().exec_() if self._args is not None: return self._args else: raise TimeoutError() finally: self.close()
def __init__(self, text_edit, hide_timer_on=False, as_tooltip=False): """ Create a call tip manager that is attached to the specified Qt text edit widget. """ assert isinstance(text_edit, (QTextEdit, QPlainTextEdit)) super(CallTipWidget, self).__init__(None, Qt.ToolTip) self.app = QCoreApplication.instance() self.as_tooltip = as_tooltip self.hide_timer_on = hide_timer_on self.tip = None self._hide_timer = QBasicTimer() self._text_edit = text_edit # Setup if sys.platform == 'darwin': # This keeps the hints below other applications self.setWindowFlags(Qt.SplashScreen) else: self.setWindowFlags(Qt.ToolTip | Qt.FramelessWindowHint) self.setTextInteractionFlags(Qt.TextSelectableByMouse) self.setFont(text_edit.document().defaultFont()) self.setForegroundRole(QPalette.ToolTipText) self.setBackgroundRole(QPalette.ToolTipBase) self.setPalette(QToolTip.palette()) self.setAlignment(Qt.AlignLeft) self.setIndent(1) self.setFrameStyle(QFrame.NoFrame) self.setMargin(1 + self.style().pixelMetric( QStyle.PM_ToolTipLabelFrameWidth, None, self))
def __init__(self): self._reads = {} self._writes = {} self._notifiers = {} self._timer = QTimer() self._timer.setSingleShot(True) self._timer.timeout.connect(self.iterate_qt) if QCoreApplication.instance() is None: # Application Object has not been started yet self.qApp = QCoreApplication([]) self._ownApp = True else: self.qApp = QCoreApplication.instance() self._ownApp = False self._blockApp = None posixbase.PosixReactorBase.__init__(self)
def test_paste_channel(botchannels): from qtpy.QtCore import QCoreApplication app = QCoreApplication.instance() qtbot, widget = botchannels qtbot.mouseClick(widget.button_add, Qt.LeftButton) app.clipboard().setText('Metropolis') count = widget.list.count() item = widget.list.item(count - 1) qtbot.keyClick(item.text_channel, Qt.Key_V, modifier=Qt.ControlModifier) assert item.text_channel.text() == 'Metropolis'
def _doit(factory): try: app = QApplication([]) except RuntimeError: app = QCoreApplication.instance() main_window = factory() if getattr(sys, '_called_from_test', False) and is_windows_platform(): QTimer.singleShot(500, app, Slot('quit()')) main_window.show() app.exec_()
def set_application_icon(self): """ """ app = QCoreApplication.instance() app_icon = QIcon() app_icon.addFile(images.ANACONDA_ICON_16_PATH, QSize(16, 16)) app_icon.addFile(images.ANACONDA_ICON_24_PATH, QSize(24, 24)) app_icon.addFile(images.ANACONDA_ICON_32_PATH, QSize(32, 32)) app_icon.addFile(images.ANACONDA_ICON_48_PATH, QSize(48, 48)) app_icon.addFile(images.ANACONDA_ICON_256_PATH, QSize(256, 256)) app.setWindowIcon(app_icon)
def revert(self): """ Takes the data stored in the models and displays them in the widgets. """ # make sure it is called from main thread if (not QThread.currentThread() == QCoreApplication.instance( ).thread()): QTimer.singleShot(0, self.revert) return for key in self._mappings: self._on_model_notification(key)
def submit(self): """ Submits the current values stored in the widgets to the models. """ # make sure it is called from main thread if (not QThread.currentThread() == QCoreApplication.instance( ).thread()): QTimer.singleShot(0, self.submit) return submit_policy = self._submit_policy self.submit_policy = SUBMIT_POLICY_AUTO try: for key in self._mappings: self._on_widget_property_notification(key) finally: self.submit_policy = submit_policy
def test_menu_copy(botchannels): from qtpy.QtCore import QCoreApplication app = QCoreApplication.instance() qtbot, widget = botchannels item = widget.list.item(0) def _triggered(): with qtbot.waitSignal( signal=item.text_channel.sig_copied, timeout=2000, raising=True ): qtbot.keyClick(item.text_channel.menu, Qt.Key_Down) qtbot.keyClick(item.text_channel.menu, Qt.Key_Return) assert app.clipboard().text() == 'chdoig' timer = QTimer() timer.timeout.connect(_triggered) timer.setInterval(2000) timer.start() qtbot.mouseClick(item.text_channel, Qt.RightButton)
def __init__(self, parent=None, as_tooltip=False): """ Shows tooltips that can be styled with the different themes. """ super(ToolTipWidget, self).__init__(None, Qt.ToolTip) # Variables self.completion_doc = None self._url = '' self.app = QCoreApplication.instance() self.as_tooltip = as_tooltip self.tip = None self._timer_hide = QTimer() self._text_edit = parent # Setup # This keeps the hints below other applications if sys.platform == 'darwin': self.setWindowFlags(Qt.SplashScreen) else: self.setWindowFlags(Qt.ToolTip | Qt.FramelessWindowHint) self._timer_hide.setInterval(500) self.setTextInteractionFlags(Qt.TextSelectableByMouse) self.setTextInteractionFlags(Qt.TextBrowserInteraction) self.setOpenExternalLinks(False) self.setForegroundRole(QPalette.ToolTipText) self.setBackgroundRole(QPalette.ToolTipBase) self.setPalette(QToolTip.palette()) self.setAlignment(Qt.AlignLeft) self.setIndent(1) self.setFrameStyle(QFrame.NoFrame) style = self.style() delta_margin = style.pixelMetric(QStyle.PM_ToolTipLabelFrameWidth, None, self) self.setMargin(1 + delta_margin) # Signals self.linkHovered.connect(self._update_hover_html_link_style) self._timer_hide.timeout.connect(self.hide) QApplication.instance().applicationStateChanged.connect( self._should_hide)
def __init__(self, text_edit, hide_timer_on=False): """ Create a call tip manager that is attached to the specified Qt text edit widget. """ assert isinstance(text_edit, (QTextEdit, QPlainTextEdit)) super(CallTipWidget, self).__init__(None, Qt.ToolTip) self.app = QCoreApplication.instance() self.hide_timer_on = hide_timer_on self._hide_timer = QBasicTimer() self._text_edit = text_edit self.setFont(text_edit.document().defaultFont()) self.setForegroundRole(QPalette.ToolTipText) self.setBackgroundRole(QPalette.ToolTipBase) self.setPalette(QToolTip.palette()) self.setAlignment(Qt.AlignLeft) self.setIndent(1) self.setFrameStyle(QFrame.NoFrame) self.setMargin(1 + self.style().pixelMetric(QStyle.PM_ToolTipLabelFrameWidth, None, self))
def __init__(self, parent=None, as_tooltip=False): """ Shows tooltips that can be styled with the different themes. """ super(ToolTipWidget, self).__init__(parent, Qt.ToolTip) # Variables self.app = QCoreApplication.instance() self.as_tooltip = as_tooltip self.tip = None # Setup self.setForegroundRole(QPalette.ToolTipText) self.setBackgroundRole(QPalette.ToolTipBase) self.setPalette(QToolTip.palette()) self.setAlignment(Qt.AlignLeft) self.setIndent(1) self.setFrameStyle(QFrame.NoFrame) style = self.style() delta_margin = style.pixelMetric(QStyle.PM_ToolTipLabelFrameWidth, None, self) self.setMargin(1 + delta_margin)
def __init__(self, text_edit, hide_timer_on=False): """ Create a call tip manager that is attached to the specified Qt text edit widget. """ assert isinstance(text_edit, (QTextEdit, QPlainTextEdit)) super(CallTipWidget, self).__init__(None, Qt.ToolTip) self.app = QCoreApplication.instance() self.hide_timer_on = hide_timer_on self._hide_timer = QBasicTimer() self._text_edit = text_edit self.setFont(text_edit.document().defaultFont()) self.setForegroundRole(QPalette.ToolTipText) self.setBackgroundRole(QPalette.ToolTipBase) self.setPalette(QToolTip.palette()) self.setAlignment(Qt.AlignLeft) self.setIndent(1) self.setFrameStyle(QFrame.NoFrame) self.setMargin(1 + self.style().pixelMetric( QStyle.PM_ToolTipLabelFrameWidth, None, self))
def _init_pyqt(self, exp): global app, font_database # Add the Qt plugin folders to the library path, if they exists. Where # these folders are depends on the version of Qt4, but these are two # possible locations. qt_plugin_path = os.path.join(os.path.dirname(sys.executable), 'Library', 'plugins') if os.path.isdir(qt_plugin_path): QCoreApplication.addLibraryPath( safe_decode(qt_plugin_path, enc=misc.filesystem_encoding())) qt_plugin_path = os.path.join(os.path.dirname(sys.executable), 'Library', 'lib', 'qt4', 'plugins') if os.path.isdir(qt_plugin_path): QCoreApplication.addLibraryPath( safe_decode(qt_plugin_path, enc=misc.filesystem_encoding())) # If no instance of QApplication exists, a segmentation fault seems to always # occur. So we create one. if QCoreApplication.instance() is None: app = QApplication([]) # Register the fonts bundled with OpenSesame if font_database is None: font_database = QFontDatabase() for font in FONTS: try: path = exp.resource(font + u'.ttf') except: warnings.warn(u'Font %s not found' % font) continue font_id = font_database.addApplicationFont(path) if font_id < 0: warnings.warn(u'Failed to load font %s' % font) continue font_families = font_database.applicationFontFamilies(font_id) if not font_families: warnings.warn(u'Font %s contains no families' % font) continue font_substitutions.append((font_families[0], font))
def __init__(self, protocol, obj, widgets=[], refresh=1.0): """ :param protocol: custom local protocol only valid for input widgets and their children :type protocol: str :param obj: object to use for this plugin :type obj: object :param widgets: widgets to connect to obj :type widgets: list of QWidget :param refresh: default seconds to wait before checking new values refresh=0 means no auto-refresh by default :type refresh: float or int """ super(LocalPlugin, self).__init__() app = QCoreApplication.instance() standard_protocol = app.plugins.keys() if protocol in standard_protocol: err = "Protocol {} invalid, same as a standard protocol" raise Exception(err.format(protocol)) self.base_protocol = protocol self.protocol = protocol + "://" self.connection_class = connection_class_factory(obj, refresh) self.add_widgets(widgets)
def quit(): QCoreApplication.instance().quit()
def _init_ui(self): self.setIcon(QIcon(':heart.svg')) self.setToolTip(QCoreApplication.instance().applicationName()) self._menu.addAction(self.tr("Quit")).triggered.connect(self.parent.close) self.setContextMenu(self._menu)
def slot(self, *args): _log.debug('signalled %s', args) self._args = args QCoreApplication.instance().quit() self.close()
def timerEvent(self, evt): _log.error('Test timeout') QCoreApplication.instance().quit() self.close()
def get_standard_icon(sp: QStyle.StandardPixmap): style = QCoreApplication.instance().style() return style.standardIcon(sp)