Пример #1
0
def ReadResourceTextFile(resFile):

    res = QResource(resFile)
    file = QFile(res.absoluteFilePath())
    file.open(QFile.ReadOnly | QFile.Text)
    textStream = QTextStream(file)
    data = textStream.readAll()
    file.close()

    return data
Пример #2
0
 def set_source(self, path):
     self.beginResetModel()
     self.ressource_root = path
     self.icons = sorted([
         name for name in QResource(self.ressource_root).children()
         if (QResource(self.ressource_root + "/" + name).isFile() and (
             self.extensions is None
             or os.path.splitext(name)[1].lower() in self.extensions))
     ])
     self.endResetModel()
Пример #3
0
    def build_resource_tree(self, parent_item, parent_key):
        for key in QResource(parent_key).children():
            full_key = f"{parent_key}/{key}"
            if QResource(full_key).isDir():

                item = QTreeWidgetItem([key, full_key])
                self.build_resource_tree(item, full_key)
                parent_item.addChild(item)
                if full_key == "/images/themes/default":
                    self.default_item = item
Пример #4
0
    def loadResources(self, clearPixmapCache=True):
        """Load resources for current theme"""
        # Need to clear pixmap cache otherwise some icons are not reloaded from new resource file
        if clearPixmapCache:
            QPixmapCache.clear()

        if not self.__registeredResource is None:
            QResource.unregisterResource(self.__registeredResource)

        palette = QApplication.palette()

        if palette.color(QPalette.Window).value() <= 128:
            self.__theme = UITheme.DARK_THEME
        else:
            self.__theme = UITheme.LIGHT_THEME

        self.__registeredResource = os.path.join(self.__rccPath, f'{self.__theme}theme_icons.rcc')

        if not QResource.registerResource(self.__registeredResource):
            self.__registeredResource = None
Пример #5
0
    def loadResources(self):
        """Load resources for current theme"""

        if not Krita.activeWindow() is None:
            # Need to clear pixmap cache otherwise some icons are not relaoded from new resource file
            QPixmapCache.clear()

            if not self.__registeredResource is None:
                QResource.unregisterResource(self.__registeredResource)

            palette = QApplication.palette()

            if palette.color(QPalette.Window).value() <= 128:
                self.__theme = BCTheme.DARK_THEME
            else:
                self.__theme = BCTheme.LIGHT_THEME

            self.__registeredResource = os.path.join(
                os.path.dirname(__file__), 'resources',
                f'{self.__theme}theme_icons.rcc')

            if not QResource.registerResource(self.__registeredResource):
                self.__registeredResource = None
Пример #6
0
    def __init__(self, *args, **kwargs):
        super(ImageView, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        layout = QHBoxLayout(self)

        # 从文件加载图片
        layout.addWidget(QLabel(self, pixmap=QPixmap("Data/head.jpg")))

        # QResource 参考 http://doc.qt.io/qt-5/resources.html

        # 从资源文件中加载1  from py file
        # 转换命令pyrcc5 res.qrc -o res_rc.py
        # 这种方式是从通过pyrcc5转换res.qrc为res_rc.py文件,可以直接import加载
        # 此时可以通过路径:/images/head.jpg来访问
        layout.addWidget(QLabel(self, pixmap=QPixmap(":/images/head.jpg")))

        # 从二进制资源文件res.rcc中加载
        # 转换命令tools/rcc.exe -binary res2.qrc -o res.rcc
        # 这里把资源前缀修改下(/myfile),见res2.qrc文件
        # 此时需要注册
        QResource.registerResource("Data/res.rcc")
        # 注意前缀
        layout.addWidget(
            QLabel(self, pixmap=QPixmap(":/myfile/images/head.jpg")))

        # 从xpm数组中加载
        # 通过工具tools/Image2XPM.exe来转换
        # 这里把转换的xpm数组直接放到py文件中当做一个变量
        # 见xpmres.py中的image_head
        layout.addWidget(QLabel(self, pixmap=QPixmap(image_head)))

        # 加载gif图片
        movie = QMovie("Data/loading.gif")
        label = QLabel(self)
        label.setMovie(movie)
        layout.addWidget(label)
        movie.start()
Пример #7
0
    def __init__(self, args, **kwargs):

        super(GuiApplicationBase, self).__init__(args=args, **kwargs)
        # Fixme: Why ?
        self._logger.debug("QApplication " + str(sys.argv))
        QApplication.__init__(self, sys.argv)
        self._logger.debug('GuiApplicationBase ' + str(args) + ' ' + str(kwargs))

        self.setAttribute(Qt.AA_EnableHighDpiScaling)

        # from . import BabelRessource
        rcc_path = ConfigInstall.Path.join_share_directory('babel.rcc')
        self._logger.debug('Load ressource {}'.format(rcc_path))
        if not QResource.registerResource(str(rcc_path)):
            self._logger.debug('Failed to load ressource {}'.format(rcc_path))

        # self._display_splash_screen()

        self._main_window = None
        self._initialise_qml_engine()
        self._init_actions()
Пример #8
0
    def __init__(self, args, **kwargs):

        super(GuiApplicationBase, self).__init__(args=args, **kwargs)
        # Fixme: Why ?
        self._logger.debug("QApplication " + str(sys.argv))
        QApplication.__init__(self, sys.argv)
        self._logger.debug('GuiApplicationBase ' + str(args) + ' ' +
                           str(kwargs))

        self.setAttribute(Qt.AA_EnableHighDpiScaling)

        # from . import BabelRessource
        rcc_path = ConfigInstall.Path.join_share_directory('babel.rcc')
        self._logger.debug('Load ressource {}'.format(rcc_path))
        if not QResource.registerResource(str(rcc_path)):
            self._logger.debug('Failed to load ressource {}'.format(rcc_path))

        # self._display_splash_screen()

        self._main_window = None
        self._initialise_qml_engine()
        self._init_actions()
Пример #9
0
    def __init__(self):
        super(Widget, self).__init__(None)
        # Set pixmaps resource before Main Window initialized
        self._resource = os.path.join(ctx.consts.theme_dir, ctx.flags.theme,
                                      ctx.consts.pixmaps_resource_file)
        if os.path.exists(self._resource):
            resource = QResource()
            resource.registerResource(self._resource)
        else:
            raise yali.Error, _("General",
                                "Pixmaps resources file doesn't exists")

        self.ui = Ui_YaliMain()
        self.ui.setupUi(self)

        self.font = 10
        self.animation_type = None

        self.screens = None
        self.screens_content = None

        self.pds_helper = HelpWidget(self.ui.scrollAreaWidgetContents)

        # shortcut to open help
        self.help_shortcut = QShortcut(QKeySequence(Qt.Key_F1), self)

        # shortcut to open debug window
        # self.debugShortCut = QtWidgets.QShortcut(QtWidgets.QKeySequence(Qt.Key_F2),self)

        # something funny
        self.tetris_shortcut = QShortcut(QKeySequence(Qt.Key_F6), self)
        self.cursor_shortcut = QShortcut(QKeySequence(Qt.Key_F7), self)
        self.theme_shortcut = QShortcut(QKeySequence(Qt.Key_F8), self)

        # shortcut to open a console
        self.console_shortcut = QShortcut(QKeySequence(Qt.Key_F11), self)

        # set style
        self._style = os.path.join(ctx.consts.theme_dir, ctx.flags.theme,
                                   ctx.consts.style_file)
        if os.path.exists(self._style):
            self.updateStyle()
        else:
            raise yali.Error, _("General", "Style file doesn't exists")

        # set screens content
        release_file = os.path.join(ctx.consts.branding_dir,
                                    ctx.flags.branding,
                                    ctx.consts.release_file)
        if os.path.exists(release_file):
            self.screens_content = yali.util.parse_branding_screens(
                release_file)
        else:
            raise yali.Error, _("General", "Release file doesn't exists")

        # move one step at a time
        self.step_increment = 1

        # ToolButton Popup Menu
        self.menu = QMenu()
        self.shutdown = self.menu.addAction(
            QIcon(QPixmap(":/images/system-shutdown.png")),
            _("General", "Turn Off Computer"))
        self.reboot = self.menu.addAction(
            QIcon(QPixmap(":/images/system-reboot.png")),
            _("General", "Restart Computer"))
        self.restart = self.menu.addAction(
            QIcon(QPixmap(":/images/system-yali-reboot.png")),
            _("General", "Restart YALI"))
        # self.menu.setDefaultAction(self.shutdown)
        self.ui.system_menu.setMenu(self.menu)
        self.ui.system_menu.setDefaultAction(self.shutdown)

        # Main Slots
        self.help_shortcut.activated.connect(self.pds_helper.toggleHelp)
        # self.debugShortCut.activated.connect(self.toggleDebug)
        self.console_shortcut.activated.connect(self.toggleConsole)
        self.cursor_shortcut.activated.connect(self.toggleCursor)
        self.theme_shortcut.activated.connect(self.toggleTheme)
        self.tetris_shortcut.activated.connect(self.toggleTetris)
        self.ui.buttonNext.clicked.connect(self.slotNext)
        self.ui.buttonBack.clicked.connect(self.slotBack)
        self.ui.toggleHelp.clicked.connect(self.pds_helper.toggleHelp)
        if not ctx.flags.install_type == ctx.STEP_FIRST_BOOT:
            self.ui.releaseNotes.clicked.connect(self.showReleaseNotes)
        else:
            self.ui.releaseNotes.hide()
        self.menu.triggered[QAction].connect(self.slotMenu)

        self.cmb = _("General", "right")
        self.dont_ask_again = False
        self.terminal = None
        self.tetris = None

        self.ui.helpContentFrame.hide()

        self.effect = QGraphicsOpacityEffect(self)
        self.ui.mainStack.setGraphicsEffect(self.effect)
        self.effect.setOpacity(1.0)

        self.anime = QTimer(self)
        self.anime.timeout.connect(self.animate)
Пример #10
0
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 18 12:04:47 2019

@author: Amoh - Gyebi Ampofo
"""
from PyQt5.QtCore import QFile, QResource, QIODevice
QResource.registerResource("_qmlview_resource_.rcc")


class PhoneFrame():
    def __init__(self, filename):

        self.original_file = filename
        self.frame_qml = ":/qml/phone_replacement_qml.qml"
        self.wind_user_props = {
            'title': 'title: qsTr("Qmlview")',
            'color': 'color: "white"'
        }

    def parentised_handling(self):

        with open(self.original_file, 'r') as orig_file:
            orig_lines = orig_file.readlines()

        # Open with QFile
        replace_file = QFile(self.frame_qml)
        replace_file.open(QIODevice.ReadOnly)
        rep_data = replace_file.readAll()
        replace_data = str(rep_data, 'utf-8')
Пример #11
0
import sys
from PyQt5.QtGui import QGuiApplication, QIcon
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtCore import QResource
from chatbot import ChatBot, ChatBot2

app = QGuiApplication(sys.argv)
QResource.registerResource('main.rcc')
app.setWindowIcon(QIcon(":/resources/disc_logo.png"))
engine = QQmlApplicationEngine()
chatbb = ChatBot()
chatboo = ChatBot2()
engine.rootContext().setContextProperty('chatty', chatbb)
engine.rootContext().setContextProperty('chatt', chatboo)
engine.load(':/main.qml')
engine.quit.connect(app.quit)
sys.exit(app.exec_())
Пример #12
0
# -*- coding: utf-8 -*-
"""
@author: Amoh - Gyebi Godwin
# To You oh, LORD i commit myself
"""
import sys
import os
from PyQt5.QtCore import QCoreApplication, QResource
from PyQt5.QtGui import QGuiApplication, QIcon
from PyQt5.QtQml import QQmlApplicationEngine
from settings import Sets
from func import Switcher
from general import GeneralFunc
QResource.registerResource('peter.rcc')


def cleanUp():
    #setts.save_file()
    pass


os.environ["QT_QUICK_CONTROLS_STYLE"] = "Universal"
app = QGuiApplication(sys.argv)
app.setWindowIcon(QIcon(":/UI/images/Peter.png"))
setts = Sets()
gen_func = GeneralFunc()
switcher = Switcher()

engine = QQmlApplicationEngine()

engine.load(":/UI/qml/main.qml")
Пример #13
0
# This Python file uses the following encoding: utf-8
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtCore import QResource

code = ("Burning Coder")
app = QApplication([])
engine = QQmlApplicationEngine()
QResource.registerResource("library.rcc")
engine.load('qrc:///ui')
engine.rootContext().setContextProperty('code', code)
engine.quit.connect(app.quit)
sys.exit(app.exec_())
Пример #14
0
# -*- coding: utf-8 -*-
import sys
import os
from PyQt5.QtCore import QCoreApplication, QSettings, QResource
from PyQt5.QtGui import QGuiApplication, QIcon
from PyQt5.QtQml import QQmlApplicationEngine
from preview import Preview
QResource.registerResource("resource.rcc")
qApp = QGuiApplication(sys.argv)

QCoreApplication.setOrganizationName("Deuteronomy Works")
QCoreApplication.setApplicationName("Ninja-Preview")
settings = QSettings()

qApp.setWindowIcon(QIcon(":icons/logo.png"))

engine = QQmlApplicationEngine()

preview = Preview()

engine.rootContext().setContextProperty('preview', preview)

engine.load("qrc:///UI/main.qml")

engine.quit.connect(qApp.quit)

sys.exit(qApp.exec_())
Пример #15
0
    def __init__(self):
        """ constructor """
        super().__init__()

        QApplication.setStyle('Fusion')
        QResource.registerResource(PATH + '/resources/main.rcc')
        file = QFile(':/style.css')
        file.open(QFile.ReadOnly)
        qApp.setStyleSheet(file.readAll().data().decode())
        uic.loadUi(PATH + '/resources/main.ui', self)

        # setup statusBar
        self.label_info = QLabel(self.statusbar)
        self.label_info.setContentsMargins(0, 0, 10, 0)
        self.statusbar.addPermanentWidget(self.label_info)

        # setup QProcess
        self.__proc = QProcess()
        self.__proc.readyReadStandardOutput.connect(self._slot_stdout)
        self.__proc.readyReadStandardError.connect(self._slot_stderr)
        self.__proc.finished.connect(self._slot_complete)

        if ASSISTANT_BIN:
            self.__proc_assistant = QProcess(self)
            self.__proc_assistant.setProgram(ASSISTANT_BIN)
            self.__proc_assistant.setArguments(['-enableRemoteControl'])

        # defaults
        self.__last_chunk = ''
        self.__running = False
        self.__dbg_running = False
        self.__filename = None
        self.__saved_breakpoints = {}
        self.__encoding = 'UTF-8'
        self.setWindowTitle('unsaved[*] - qpdb')

        # compiled regular expressions
        self.__re_active = re.compile(r'^> (.*)\(([0-9]+)\)')
        self.__re_bp_add = re.compile(r'^Breakpoint ([0-9]+) at (.*):([0-9]+)')
        self.__re_bp_del = re.compile(
            r'^Deleted breakpoint ([0-9]+) at (.*):([0-9]+)')
        self.__re_stack = re.compile(r'^[ >] (.*)\(([0-9]+)\)([^(]+)\(\)')

        # some editor stuff
        self.__symbol_margin_num = 1
        self.__breakpoint_marker_num = 1
        self.__breakpoint_marker_mask = 2**self.__breakpoint_marker_num
        self.__active_line_marker_num = 2

        # setup components
        self._setup_actions()
        self._setup_toolbar()
        self._setup_lists()
        self._setup_console()
        self._setup_editor()
        self._setup_outline()

        # restore window state
        self.__state = QSettings('fx', 'qpdb')
        val = self.__state.value('MainWindow/Geometry')
        if val is not None:
            self.restoreGeometry(val)
        val = self.__state.value('MainWindow/State')
        if val is not None:
            self.restoreState(val)

        for i in range(1, len(sys.argv)):
            self._load_script(sys.argv[i])

        self.show()
Пример #16
0
import sys
from PyQt5.QtCore import QResource
from PyQt5.QtGui import QGuiApplication, QIcon
from PyQt5.QtQml import QQmlApplicationEngine
from func import Calculator

QResource.registerResource('resources.rcc')
app = QGuiApplication(sys.argv)
app.setWindowIcon(QIcon(':resources/images/disc_logo.png'))

calc = Calculator()

engine = QQmlApplicationEngine()
engine.rootContext().setContextProperty('Calculator', calc)
engine.load('qrc:///resources/qml/main.qml')
engine.quit.connect(app.quit)

sys.exit(app.exec_())
Пример #17
0
# -*- coding: utf-8 -*-
import sys
import os

from PyQt5.QtCore import QCoreApplication, QSettings, QResource
from PyQt5.QtGui import QGuiApplication, QIcon
from PyQt5.QtQml import QQmlApplicationEngine

from preview import Preview

QResource.registerResource("_ninjapreview_resource.rcc")

qApp = QGuiApplication(sys.argv)

QCoreApplication.setOrganizationName("Deuteronomy Works")
QCoreApplication.setApplicationName("Ninja-Preview")
settings = QSettings()

qApp.setWindowIcon(QIcon(":icons/logo.png"))

engine = QQmlApplicationEngine()

preview = Preview()

engine.load("qrc:///UI/main.qml")
engine.rootObjects()[0].setProperty('preview', preview)
engine.quit.connect(qApp.quit)

sys.exit(qApp.exec_())
Пример #18
0
from PyQt5.QtCore import QResource
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QLabel

__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: [email protected]"
__Copyright__ = "Copyright (c) 2017 Irony.\"[讽刺]"
__Version__ = "Version 1.0"


class ImageView(QLabel):
    def __init__(self, *args, **kwargs):
        super(ImageView, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        self.setPixmap(QPixmap(":/images/head.jpg"))


if __name__ == "__main__":
    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)
    # 从二进制资源文件res.data中加载
    # 转换命令cd tools
    # rcc.exe -binary ../res.qrc -o ../res.data
    # 此时需要注册
    QResource.registerResource("res.data")
    app.aboutToQuit.connect(lambda: QResource.unregisterResource("res.data"))
    w = ImageView()
    w.show()
    sys.exit(app.exec_())
Пример #19
0
    QWidget,
    QVBoxLayout,
    QPushButton,
    QTabWidget,
    QDialogButtonBox,
    QMenuBar,
    QAction,
    QProgressBar,
    QCheckBox,
    QLineEdit,
)

import genes, objectives, company
from PyQt5.QtCore import Qt, QResource

QResource.registerResource(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources.rrc"))


class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, *kwargs)

        self.setWindowTitle("GaudiCreate")
        self.setMinimumSize(900, 600)
        self.setMenuBar(MenuBar())

        wid = QWidget()
        self.setCentralWidget(wid)
        self.main_layout = QVBoxLayout()
        wid.setLayout(self.main_layout)