Python PyQt5.QtCore.QTextStream() Examples

The following are 30 code examples for showing how to use PyQt5.QtCore.QTextStream(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .

Example 1
Project: persepolis   Author: persepolisdm   File: persepolis.py    License: GNU General Public License v3.0 6 votes vote down vote up
def setPersepolisColorScheme(self, color_scheme):
        self.persepolis_color_scheme = color_scheme
        if color_scheme == 'Dark Fusion':
            dark_fusion = DarkFusionPalette()
            self.setPalette(dark_fusion)
            file = QFile(":/dark_style.qss")
            file.open(QFile.ReadOnly | QFile.Text)
            stream = QTextStream(file)
            self.setStyleSheet(stream.readAll())

        elif color_scheme == 'Light Fusion':
            dark_fusion = LightFusionPalette()
            self.setPalette(dark_fusion)
            file = QFile(":/light_style.qss")
            file.open(QFile.ReadOnly | QFile.Text)
            stream = QTextStream(file)
            self.setStyleSheet(stream.readAll())


# create  terminal arguments 
Example 2
Project: persepolis   Author: persepolisdm   File: about.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, persepolis_setting):
        super().__init__(persepolis_setting)

        self.persepolis_setting = persepolis_setting

        # setting window size and position
        size = self.persepolis_setting.value(
            'AboutWindow/size', QSize(545, 375))
        position = self.persepolis_setting.value(
            'AboutWindow/position', QPoint(300, 300))

        # read translators.txt files.
        # this file contains all translators.
        f = QFile(':/translators.txt')

        f.open(QIODevice.ReadOnly | QFile.Text)
        f_text = QTextStream(f).readAll()
        f.close()

        self.translators_textEdit.insertPlainText(f_text)



        self.resize(size)
        self.move(position) 
Example 3
Project: vorta   Author: borgbase   File: qt_single_application.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, id, *argv):

        super().__init__(*argv)
        self._id = id

        # Is there another instance running?
        self._outSocket = QLocalSocket()
        self._outSocket.connectToServer(self._id)
        self._isRunning = self._outSocket.waitForConnected()

        if self._isRunning:
            # Yes, there is.
            self._outStream = QTextStream(self._outSocket)
            self._outStream.setCodec('UTF-8')
        else:
            # No, there isn't.
            self._outSocket = None
            self._outStream = None
            self._inSocket = None
            self._inStream = None
            self._server = QLocalServer()
            self._server.removeServer(self._id)
            self._server.listen(self._id)
            self._server.newConnection.connect(self._onNewConnection) 
Example 4
Project: Dwarf   Author: iGio90   File: utils.py    License: GNU General Public License v3.0 6 votes vote down vote up
def set_theme(theme, prefs=None):
    if theme:
        theme = theme.replace(os.pardir, '').replace('.', '')
        theme = theme.join(theme.split()).lower()
        theme_style = resource_path('assets' + os.sep + theme + '_style.qss')
        if not os.path.exists(theme_style):
            theme_style = ':/assets/' + theme + '_style.qss'

        if prefs is not None:
            prefs.put('dwarf_ui_theme', theme)

        try:
            _app = QApplication.instance()
            style_s = QFile(theme_style)
            style_s.open(QFile.ReadOnly)
            style_content = QTextStream(style_s).readAll()
            _app.setStyleSheet(_app.styleSheet() + '\n' + style_content)
        except Exception as e:
            pass
            # err = self.dwarf.spawn(dwarf_args.package, dwarf_args.script) 
Example 5
Project: vnpy_crypto   Author: birforce   File: __init__.py    License: MIT License 5 votes vote down vote up
def load_stylesheet_pyqt5():
    """
    Load the stylesheet for use in a pyqt5 application.

    :param pyside: True to load the pyside rc file, False to load the PyQt rc file

    :return the stylesheet string
    """
    warnings.warn(
        "load_stylesheet_pyqt5() will be deprecated in version 3,"
        "set QtPy environment variable to specify the Qt binding and "
        "use load_stylesheet()",
        PendingDeprecationWarning
    )
    # Smart import of the rc file
    import qdarkstyle.pyqt5_style_rc

    # Load the stylesheet content from resources
    from PyQt5.QtCore import QFile, QTextStream

    f = QFile(":qdarkstyle/style.qss")
    if not f.exists():
        _logger().error("Unable to load stylesheet, file not found in "
                        "resources")
        return ""
    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet 
Example 6
Project: PyQt5_stylesheets   Author: RedFalsh   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def load_stylesheet(pyside=True):
    """
    Loads the stylesheet. Takes care of importing the rc module.

    :param pyside: True to load the pyside rc file, False to load the PyQt rc file

    :return the stylesheet string
    """
    # Smart import of the rc file
    if pyside:
        import qdarkstyle.pyside_style_rc
    else:
        import qdarkstyle.pyqt_style_rc

    # Load the stylesheet content from resources
    if not pyside:
        from PyQt4.QtCore import QFile, QTextStream
    else:
        from PySide.QtCore import QFile, QTextStream

    f = QFile(":qdarkstyle/style.qss")
    if not f.exists():
        _logger().error("Unable to load stylesheet, file not found in "
                        "resources")
        return ""
    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet 
Example 7
Project: QMusic   Author: dragondjf   File: dsingleapplication.py    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
def __init__(self, id, *argv):

        super(QSingleApplication, self).__init__(*argv)
        self._id = id
        self._activationWindow = None
        self._activateOnMessage = False
        self._server = None

        # Is there another instance running?
        self._outSocket = QLocalSocket()
        self._outSocket.connectToServer(self._id)
        self._outSocket.error.connect(self.handleError)
        self._isRunning = self._outSocket.waitForConnected()

        if self._isRunning:
            # Yes, there is.
            self._outStream = QTextStream(self._outSocket)
            self._outStream.setCodec('UTF-8')
        else:
            # No, there isn't.
            self._outSocket = None
            self._outStream = None
            self._inSocket = None
            self._inStream = None
            self._server = QLocalServer()
            self._server.listen(self._id)
            self._server.newConnection.connect(self._onNewConnection)
            self.aboutToQuit.connect(self.removeServer) 
Example 8
Project: QMusic   Author: dragondjf   File: dsingleapplication.py    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
def _onNewConnection(self):
        if self._inSocket:
            self._inSocket.readyRead.disconnect(self._onReadyRead)
        self._inSocket = self._server.nextPendingConnection()
        if not self._inSocket:
            return
        self._inStream = QTextStream(self._inSocket)
        self._inStream.setCodec('UTF-8')
        self._inSocket.readyRead.connect(self._onReadyRead)
        if self._activateOnMessage:
            self.activateWindow() 
Example 9
Project: TradeSim   Author: quantOS-org   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def load_stylesheet_pyqt5():
    """
    Loads the stylesheet for use in a pyqt5 application.

    :param pyside: True to load the pyside rc file, False to load the PyQt rc file

    :return the stylesheet string
    """
    # Smart import of the rc file
    import qdarkstyle.pyqt5_style_rc

    # Load the stylesheet content from resources
    from PyQt5.QtCore import QFile, QTextStream

    f = QFile(":qdarkstyle/style.qss")
    if not f.exists():
        _logger().error("Unable to load stylesheet, file not found in "
                        "resources")
        return ""
    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet 
Example 10
Project: vorta   Author: borgbase   File: qt_single_application.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _onNewConnection(self):
        if self._inSocket:
            self._inSocket.readyRead.disconnect(self._onReadyRead)
        self._inSocket = self._server.nextPendingConnection()
        if not self._inSocket:
            return
        self._inStream = QTextStream(self._inSocket)
        self._inStream.setCodec('UTF-8')
        self._inSocket.readyRead.connect(self._onReadyRead) 
Example 11
Project: vidcutter   Author: ozmartian   File: changelog.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None):
        super(Changelog, self).__init__(parent, Qt.Dialog | Qt.WindowCloseButtonHint)
        self.parent = parent
        self.setWindowTitle('{} changelog'.format(qApp.applicationName()))
        changelog = QFile(':/CHANGELOG')
        changelog.open(QFile.ReadOnly | QFile.Text)
        content = QTextStream(changelog).readAll()
        label = QLabel(content, self)
        label.setWordWrap(True)
        label.setTextFormat(Qt.PlainText)
        buttons = QDialogButtonBox(QDialogButtonBox.Close, self)
        buttons.rejected.connect(self.close)
        scrollarea = QScrollArea(self)
        scrollarea.setStyleSheet('QScrollArea { background:transparent; }')
        scrollarea.setWidgetResizable(True)
        scrollarea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        scrollarea.setFrameShape(QScrollArea.NoFrame)
        scrollarea.setWidget(label)
        if sys.platform in {'win32', 'darwin'}:
            scrollarea.setStyle(QStyleFactory.create('Fusion'))
        # noinspection PyUnresolvedReferences
        if parent.parent.stylename == 'fusion' or sys.platform in {'win32', 'darwin'}:
            self.setStyleSheet('''
            QScrollArea {{
                background-color: transparent;
                margin-bottom: 10px;
                border: none;
                border-right: 1px solid {};
            }}'''.format('#4D5355' if parent.theme == 'dark' else '#C0C2C3'))
        else:
            self.setStyleSheet('''
            QScrollArea {{
                background-color: transparent;
                margin-bottom: 10px;
                border: none;
            }}''')
        layout = QVBoxLayout()
        layout.addWidget(scrollarea)
        layout.addWidget(buttons)
        self.setLayout(layout)
        self.setMinimumSize(self.sizeHint()) 
Example 12
Project: vidcutter   Author: ozmartian   File: videostyle.py    License: GNU General Public License v3.0 5 votes vote down vote up
def loadQSS(theme) -> None:
        filename = ':/styles/{}.qss'.format(theme)
        if QFileInfo(filename).exists():
            qssfile = QFile(filename)
            qssfile.open(QFile.ReadOnly | QFile.Text)
            content = QTextStream(qssfile).readAll()
            qApp.setStyleSheet(content) 
Example 13
Project: vidcutter   Author: ozmartian   File: singleapplication.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, appid, *argv):
        super(SingleApplication, self).__init__(*argv)
        self._appid = appid
        self._activationWindow = None
        self._activateOnMessage = False
        self._outSocket = QLocalSocket()
        self._outSocket.connectToServer(self._appid)
        self._isRunning = self._outSocket.waitForConnected()
        self._outStream = None
        self._inSocket = None
        self._inStream = None
        self._server = None
        self.settings = QSettings(SingleApplication.getSettingsPath(), QSettings.IniFormat)
        self.singleInstance = self.settings.value('singleInstance', 'on', type=str) in {'on', 'true'}
        if self._isRunning and self.singleInstance:
            self._outStream = QTextStream(self._outSocket)
            for a in argv[0][1:]:
                a = os.path.join(os.getcwd(), a)
                if os.path.isfile(a):
                    self.sendMessage(a)
                    break
            sys.exit(0)
        else:
            error = self._outSocket.error()
            if error == QLocalSocket.ConnectionRefusedError:
                self.close()
                QLocalServer.removeServer(self._appid)
            self._outSocket = None
            self._server = QLocalServer()
            self._server.listen(self._appid)
            self._server.newConnection.connect(self._onNewConnection) 
Example 14
Project: vidcutter   Author: ozmartian   File: singleapplication.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _onNewConnection(self):
        if self._inSocket:
            self._inSocket.readyRead.disconnect(self._onReadyRead)
        self._inSocket = self._server.nextPendingConnection()
        if not self._inSocket:
            return
        self._inStream = QTextStream(self._inSocket)
        self._inSocket.readyRead.connect(self._onReadyRead)
        if self._activateOnMessage:
            self.activateWindow() 
Example 15
Project: vidcutter   Author: ozmartian   File: about.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        super(LicenseTab, self).__init__(parent)
        self.setObjectName('license')
        licensefile = QFile(':/license.html')
        licensefile.open(QFile.ReadOnly | QFile.Text)
        content = QTextStream(licensefile).readAll()
        self.setText(content)
        if sys.platform in {'win32', 'darwin'}:
            self.setStyle(QStyleFactory.create('Fusion')) 
Example 16
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savetext(self, fileName):
        textout = self.codebox.text()
        file = QtCore.QFile(fileName)
        if file.open(QtCore.QIODevice.WriteOnly):
            QtCore.QTextStream(file) << textout
        else:
            QtWidgets.QMessageBox.information(self.vindu,
                    'Unable to open file', file.errorString())
        os.chdir(str(self.path)) 
Example 17
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savetexttemp(self, fileName):
        textout = self.TemptextEdit.text()
        file = QtCore.QFile(fileName)
        if file.open(QtCore.QIODevice.WriteOnly):
            QtCore.QTextStream(file) << textout
        else:
            QtWidgets.QMessageBox.information(self.tempwizardPage,
                    'Unable to open file', file.errorString())
        os.chdir(str(self.path)) 
Example 18
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savetextscript(self, fileName):
        textout = self.script_textEdit.text()
        file = QtCore.QFile(fileName)
        if file.open(QtCore.QIODevice.WriteOnly):
            QtCore.QTextStream(file) << textout
        else:
            QtWidgets.QMessageBox.information(self.wizardPage_3,
                    'Unable to open file', file.errorString())
        os.chdir(str(self.path)) 
Example 19
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savetext(self, fileName):
        textout = self.codebox.text()
        file = QtCore.QFile(fileName)
        if file.open(QtCore.QIODevice.WriteOnly):
            QtCore.QTextStream(file) << textout
        else:
            QtWidgets.QMessageBox.information(self.vindu,
                    'Unable to open file', file.errorString())
        os.chdir(str(self.path)) 
Example 20
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savetexttemp(self, fileName):
        textout = self.TemptextEdit.text()
        file = QtCore.QFile(fileName)
        if file.open(QtCore.QIODevice.WriteOnly):
            QtCore.QTextStream(file) << textout
        else:
            QtWidgets.QMessageBox.information(self.tempwizardPage,
                    'Unable to open file', file.errorString())
        os.chdir(str(self.path)) 
Example 21
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
def savetext(self, fileName):
        textout = self.codebox.text()
        file = QtCore.QFile(fileName)
        if file.open(QtCore.QIODevice.WriteOnly):
            QtCore.QTextStream(file) << textout
        else:
            QtWidgets.QMessageBox.information(self.vindu,
                    'Unable to open file', file.errorString())
        os.chdir(str(self.path)) 
Example 22
Project: artisan   Author: artisan-roaster-scope   File: qtsingleapplication.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _onNewConnection(self):
        if self._inSocket:
            self._inSocket.readyRead.disconnect(self._onReadyRead)
        self._inSocket = self._server.nextPendingConnection()
        if not self._inSocket:
            return
        self._inStream = QTextStream(self._inSocket)
        self._inStream.setCodec('UTF-8')
        self._inSocket.readyRead.connect(self._onReadyRead)
        if self._activateOnMessage and self._isRunning:
            self.activateWindow() 
Example 23
Project: lector   Author: zdenop   File: textwidget.py    License: GNU General Public License v2.0 5 votes vote down vote up
def openFile(self):
        if settings.get("file_dialog_dir"):
            self.curDir = '~/'
        else:
            self.curDir = settings.get("file_dialog_dir")
        fn = QFileDialog.getOpenFileName(self,
                self.tr("Open File..."), self.curDir,
                self.tr("HTML-Files (*.htm *.html);;All Files (*)"))
        QApplication.setOverrideCursor(Qt.WaitCursor)
        if fn:
            self.lastFolder = os.path.dirname(fn)
            if os.path.exists(fn):
                if os.path.isfile(fn):
                    f = QFile(fn)
                    if not f.open(QIODevice.ReadOnly |
                                  QIODevice.Text):
                        QtGui.QMessageBox.information(self.parent(),
                        self.tr("Error - Lector"),
                        self.tr("Can't open '%s.'" % fn))
                    else:
                        stream = QTextStream(f)
                        text = stream.readAll()
                        self.setText(text)
                else:
                    QMessageBox.information(self.parent(),
                    self.tr("Error - Lector"),
                    self.tr("'%s' is not a file." % fn))
        QApplication.restoreOverrideCursor() 
Example 24
Project: X64dbg_script_editor   Author: techbliss   File: Editor_x64dbg.py    License: The Unlicense 5 votes vote down vote up
def savetext(self, fileName):
        textout = self.codebox.text()
        file = QtCore.QFile(fileName)
        if file.open(QtCore.QIODevice.WriteOnly):
            QtCore.QTextStream(file) << textout
        else:
            QtWidgets.QMessageBox.information(self.vindu,
                    'Unable to open file', file.errorString())
        os.chdir(str(self.path)) 
Example 25
Project: BreezeStyleSheets   Author: Alexhuszagh   File: dark.py    License: MIT License 4 votes vote down vote up
def main():
    """
    Application entry point
    """
    logging.basicConfig(level=logging.DEBUG)
    # create the application and the main window
    app = QtWidgets.QApplication(sys.argv)
    #app.setStyle(QtWidgets.QStyleFactory.create("fusion"))
    window = QtWidgets.QMainWindow()

    # setup ui
    ui = example.Ui_MainWindow()
    ui.setupUi(window)
    ui.bt_delay_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    ui.bt_instant_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    ui.bt_menu_button_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    window.setWindowTitle("BreezeDark example")

    # tabify dock widgets to show bug #6
    window.tabifyDockWidget(ui.dockWidget1, ui.dockWidget2)

    # setup stylesheet
    file = QFile(":/dark.qss")
    file.open(QFile.ReadOnly | QFile.Text)
    stream = QTextStream(file)
    app.setStyleSheet(stream.readAll())

    # auto quit after 2s when testing on travis-ci
    if "--travis" in sys.argv:
        QtCore.QTimer.singleShot(2000, app.exit)

    # run
    window.show()
    app.exec_() 
Example 26
Project: BreezeStyleSheets   Author: Alexhuszagh   File: light.py    License: MIT License 4 votes vote down vote up
def main():
    """
    Application entry point
    """
    logging.basicConfig(level=logging.DEBUG)
    # create the application and the main window
    app = QtWidgets.QApplication(sys.argv)
    #app.setStyle(QtWidgets.QStyleFactory.create("fusion"))
    window = QtWidgets.QMainWindow()

    # setup ui
    ui = example.Ui_MainWindow()
    ui.setupUi(window)
    ui.bt_delay_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    ui.bt_instant_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    ui.bt_menu_button_popup.addActions([
        ui.actionAction,
        ui.actionAction_C
    ])
    window.setWindowTitle("Breeze example")

    # tabify dock widgets to show bug #6
    window.tabifyDockWidget(ui.dockWidget1, ui.dockWidget2)

    # setup stylesheet
    file = QFile(":/light.qss")
    file.open(QFile.ReadOnly | QFile.Text)
    stream = QTextStream(file)
    app.setStyleSheet(stream.readAll())

    # auto quit after 2s when testing on travis-ci
    if "--travis" in sys.argv:
        QtCore.QTimer.singleShot(2000, app.exit)

    # run
    window.show()
    app.exec_() 
Example 27
Project: vnpy_crypto   Author: birforce   File: __init__.py    License: MIT License 4 votes vote down vote up
def load_stylesheet(pyside=True):
    """
    Load the stylesheet. Takes care of importing the rc module.

    :param pyside: True to load the pyside rc file, False to load the PyQt rc file

    :return the stylesheet string
    """
    warnings.warn(
        "load_stylesheet() will not receive pyside parameter in version 3. "
        "Set QtPy environment variable to specify the Qt binding insteady.",
        FutureWarning
    )
    # Smart import of the rc file
    if pyside:
        import qdarkstyle.pyside_style_rc
    else:
        import qdarkstyle.pyqt_style_rc

    # Load the stylesheet content from resources
    if not pyside:
        from PyQt4.QtCore import QFile, QTextStream
    else:
        from PySide.QtCore import QFile, QTextStream

    f = QFile(":qdarkstyle/style.qss")
    if not f.exists():
        _logger().error("Unable to load stylesheet, file not found in "
                        "resources")
        return ""
    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet 
Example 28
Project: PyQt5_stylesheets   Author: RedFalsh   File: __init__.py    License: Apache License 2.0 4 votes vote down vote up
def load_stylesheet_pyqt5(**kwargs):
    """
    Loads the stylesheet for use in a pyqt5 application.

    :param pyside: True to load the pyside rc file, False to load the PyQt rc file

    :return the stylesheet string
    """
    # Smart import of the rc file

    if kwargs["style"] == "style_Dark":
        import PyQt5_stylesheets.pyqt5_style_Dark_rc
    if kwargs["style"] == "style_DarkOrange":
        import PyQt5_stylesheets.pyqt5_style_DarkOrange_rc
    if kwargs["style"] == "style_Classic":
        import PyQt5_stylesheets.pyqt5_style_Classic_rc

    if kwargs["style"] == "style_navy":
        import PyQt5_stylesheets.pyqt5_style_navy_rc

    if kwargs["style"] == "style_gray":
        import PyQt5_stylesheets.pyqt5_style_gray_rc

    if kwargs["style"] == "style_blue":
        import PyQt5_stylesheets.pyqt5_style_blue_rc

    if kwargs["style"] == "style_black":
        import PyQt5_stylesheets.pyqt5_style_black_rc
    # Load the stylesheet content from resources
    from PyQt5.QtCore import QFile, QTextStream

    f = QFile(":PyQt5_stylesheets/%s.qss"%kwargs["style"])
    if not f.exists():
        f = QFile(":PyQt5_stylesheets/%s.css"%kwargs["style"])
    if not f.exists():
        _logger().error("Unable to load stylesheet, file not found in "
                        "resources")
        return ""
    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet 
Example 29
Project: TradeSim   Author: quantOS-org   File: __init__.py    License: Apache License 2.0 4 votes vote down vote up
def load_stylesheet(pyside=True):
    """
    Loads the stylesheet. Takes care of importing the rc module.

    :param pyside: True to load the pyside rc file, False to load the PyQt rc file

    :return the stylesheet string
    """
    # Smart import of the rc file
    if pyside:
        import qdarkstyle.pyside_style_rc
    else:
        import qdarkstyle.pyqt_style_rc

    # Load the stylesheet content from resources
    if not pyside:
        # PyQt 4/5 compatibility
        try:
            from PyQt4.QtCore import QFile, QTextStream
        except ImportError:
            from PyQt5.QtCore import QFile, QTextStream
    else:
        from PySide.QtCore import QFile, QTextStream

    f = QFile(":qdarkstyle/style.qss")
    if not f.exists():
        _logger().error("Unable to load stylesheet, file not found in "
                        "resources")
        return ""
    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet 
Example 30
Project: artisan   Author: artisan-roaster-scope   File: qtsingleapplication.py    License: GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, _id,_viewer_id, *argv):
    
        if sys.platform.startswith("darwin") and mp.current_process().name == "WebLCDs":
            import AppKit
            info = AppKit.NSBundle.mainBundle().infoDictionary()  # @UndefinedVariable
            info["LSBackgroundOnly"] = "1"

        super(QtSingleApplication, self).__init__(*argv)
        
        self._id = _id
        self._viewer_id = _viewer_id
        self._activationWindow = None
        self._activateOnMessage = False

        self._outSocket = None
        self._isRunning = False        
        self._server = None
        
        # we exclude the WebLCDs parallel process from participating any Artisan inter-app communication
        if mp.current_process().name != "WebLCDs":
            # Is there another instance running?
            self._outSocket = QLocalSocket()
            self._outSocket.connectToServer(self._id)
            self._isRunning = self._outSocket.waitForConnected(-1)
            if self._isRunning:
                # Yes, there is.
                self._outStream = QTextStream(self._outSocket)
                self._outStream.setCodec('UTF-8')
                # Is there another viewer running?
                self._outSocketViewer = QLocalSocket()
                self._outSocketViewer.connectToServer(self._viewer_id)
                self._isRunningViewer = self._outSocketViewer.waitForConnected(-1)
                if self._isRunningViewer:
                    self._outStreamViewer = QTextStream(self._outSocketViewer)
                    self._outStreamViewer.setCodec('UTF-8')
                else:
                    # app is running, we announce us as viewer app
                    # First we remove existing servers of that name that might not have been properly closed as the server died
                    QLocalServer.removeServer(self._viewer_id) 
                    self._outSocketViewer = None
                    self._outStreamViewer = None
                    self._inSocket = None
                    self._inStream = None
                    self._server = QLocalServer()
                    self._server.listen(self._viewer_id)
                    self._server.newConnection.connect(self._onNewConnection)
            else:
                self._isRunningViewer = False
                # No, there isn't.
                # First we remove existing servers of that name that might not have been properly closed as the server died
                QLocalServer.removeServer(self._id) 
                self._outSocket = None
                self._outStream = None
                self._inSocket = None
                self._inStream = None
                self._server = QLocalServer()
                self._server.listen(self._id)
                self._server.newConnection.connect(self._onNewConnection)