Exemple #1
0
    def present(self, newNotification):
        if self.notification:
            self.notification.close()
            sip.delete(self.notification)
            self.notification = None

        self.notification = newNotification

        self.m_title.setText(f"<b>{self.notification.title()}</b>")
        self.m_message.setText(self.notification.message())
        self.m_icon.setPixmap(
            QPixmap.fromImage(self.notification.icon()).scaledToHeight(
                self.m_icon.height()))

        self.show()
        self.notification.show()

        self.notification.closed.connect(self.onClosed)
        QTimer.singleShot(
            10000, lambda: self.onClosed()
            if self.notification is not None else None)

        # position our popup in the right corner of its parent widget
        self.move(self.parentWidget().mapToGlobal(
            self.parentWidget().rect().bottomRight() -
            QPoint(self.width() + 10,
                   self.height() + 10)))
Exemple #2
0
def main():
    import sys

    QCoreApplication.setOrganizationName("QtExamples")
    QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    # QtWebEngine::initialize()

    if QT_NO_WIDGETS:
        app = QApplication(sys.argv)
    else:
        app = QGuiApplication(sys.argv)

    engine = QQmlApplicationEngine()
    server = Server(engine)

    engine.load(QUrl("qrc:/main.qml"))
    QTimer.singleShot(0, server.run)

    proxy = QNetworkProxy()
    proxy.setType(QNetworkProxy.HttpProxy)
    proxy.setHostName("localhost")
    proxy.setPort(5555)
    QNetworkProxy.setApplicationProxy(proxy)

    sys.exit(app.exec_())
Exemple #3
0
 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_()
Exemple #4
0
 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_()
Exemple #5
0
    def mouseReleaseEvent(self, event):
        button = event.button()
        self.setDown(False)
        if not self._double_click_enabled:
            self.mouse_single_click_action(button)
            return

        if self._last_click == self.SINGLE_CLICK:
            QTimer.singleShot(self._double_click_interval,
                              lambda: self.mouse_single_click_action(button))
        else:
            self.mouseDoubleClickAction(event.button())
Exemple #6
0
    def __init__(self, parent: QWidget = None):
        super().__init__(parent)

        self.setWindowFlags(self.windowFlags()
                            & ~Qt.WindowContextHelpButtonHint)

        self.server = QLocalServer(self)

        if not self.server.listen("fortune"):
            QMessageBox.critical(
                self,
                self.tr("Local Fortune Server"),
                self.tr("Unable to start the server: %s." %
                        (self.server.errorString())),
            )
            QTimer.singleShot(0, self.close)
            return

        statusLabel = QLabel()
        statusLabel.setWordWrap(True)
        statusLabel.setText(
            self.
            tr("The server is running.\nRun the Local Fortune Client example now."
               ))

        self.fortunes = (
            self.tr(
                "You've been leading a dog's life. Stay off the furniture."),
            self.tr("You've got to think about tomorrow."),
            self.tr("You will be surprised by a loud noise."),
            self.tr("You will feel hungry again in another hour."),
            self.tr("You might have mail."),
            self.tr("You cannot kill time without injuring eternity."),
            self.tr(
                "Computers are not intelligent. They only think they are."),
        )

        quitButton = QPushButton(self.tr("Quit"))
        quitButton.setAutoDefault(False)
        quitButton.clicked.connect(self.close)
        self.server.newConnection.connect(self.sendFortune)

        buttonLayout = QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(quitButton)
        buttonLayout.addStretch(1)

        mainLayout = QVBoxLayout(self)
        mainLayout.addWidget(statusLabel)
        mainLayout.addLayout(buttonLayout)

        self.setWindowTitle(QGuiApplication.applicationDisplayName())
Exemple #7
0
 def _doit(factory):
     # for windows these needs to be repeated due to multiprocessing (?)
     from Qt.QtWidgets import QApplication
     from Qt.QtCore import QCoreApplication
     try:
         app = QApplication([])
     except RuntimeError:
         app = QCoreApplication.instance()
     main_window = factory()
     if getattr(sys, '_called_from_test',
                False) and (is_windows_platform() or is_macos_platform()):
         QTimer.singleShot(1000, app.quit)
     main_window.show()
     app.exec_()
Exemple #8
0
    def readFortune(self):
        if self.blockSize == 0:
            # Relies on the fact that QDataStream serializes a quint32 into
            # sizeof(quint32) bytes
            if self.socket.bytesAvailable() < 4:  #  (int)sizeof(quint32))
                return
            self.blockSize = self._in.readUInt32()

        if self.socket.bytesAvailable() < self.blockSize or self._in.atEnd():
            return

        nextFortune = ""
        nextFortune = self._in.readQString()

        if nextFortune == self.currentFortune:
            QTimer.singleShot(0, self.requestNewFortune)
            return

        currentFortune = nextFortune
        self.statusLabel.setText(currentFortune)
        self.getFortuneButton.setEnabled(True)
Exemple #9
0
    def set_frameless_enabled(self, frameless=False):
        """
        Enables/Disables frameless mode or OS system default
        :param frameless: bool
        """

        from tpDcc.managers import tools

        tool_inst = tools.ToolsManager().get_tool_by_plugin_instance(
            self._window)
        if not tool_inst:
            return

        offset = QPoint()

        if self._window.docked():
            rect = self._window.rect()
            pos = self._window.mapToGlobal(QPoint(-10, -10))
            rect.setWidth(rect.width() + 21)
            self._window.close()
        else:
            rect = self.window().rect()
            pos = self.window().pos()
            offset = QPoint(3, 15)
            self.window().close()

        tool_inst._launch(launch_frameless=frameless)

        new_tool = tool_inst.latest_tool()

        QTimer.singleShot(
            0,
            lambda: new_tool.window().setGeometry(pos.x() + offset.x(),
                                                  pos.y() + offset.y(),
                                                  rect.width(), rect.height()))
        new_tool.framelessChanged.emit(frameless)
        QApplication.processEvents()

        return new_tool
Exemple #10
0
def defer(delay, fn, default_delay=1):
    """
    Append artificial delay to `func`
    This aids in keeping the GUI responsive, but complicates logic
    when producing tests. To combat this, the environment variable ensures
    that every operation is synchronous.
    :param delay: float, Delay multiplier; default 1, 0 means no delay
    :param fn: callable, Any callable
    :param default_delay: float
    """

    delay *= float(default_delay)
    if delay > 0:
        return QTimer.singleShot(delay, fn)
    else:
        return fn()
Exemple #11
0
 def hideEvent(self, event):
     self._remove_widget()
     QTimer.singleShot(0, self.hidden.emit)
Exemple #12
0
 def compute(self):
     if not self.process:
         self.process = True
         delay = self.delay.getData() * 1000.0
         QTimer.singleShot(delay, self.callAndReset)
Exemple #13
0
                                      for k, v in sorted(img.attrib.items())
                                      if k not in {"src", "source"})
                img.attrib.clear()
                img.attrib.update(new_attributes)

    html = ElementTree.tostring(root).decode()
    html = re.sub(r"\d{3}_DEL_XML_SUCKS_", "", html)
    with open(readme_path, "wb") as f:
        f.write(html.encode("utf-8"))


def walk_pykrita_dir():
    try:
        this_dir = os.path.dirname(sys.argv[0])
        pykrita_dir = os.path.join(this_dir, "..", "pykrita")
        for parent, folders, files in os.walk(pykrita_dir):
            for file in files:
                if file.lower() == "readme.md":
                    readme_path = os.path.join(parent, file)
                    embed_readme_images(readme_path)
        print("done!")
    finally:
        app = QApplication.instance()
        app.quit()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    _ = QTimer.singleShot(0, walk_pykrita_dir)
    sys.exit(app.exec_())