def init_ui(self, ui_path=None): if not ui_path: ui_path = "{0}/resource/qDesignerUI.ui".format( os.path.dirname(__file__)) # IF A DB OF ASSETS DOES NOT EXIST CREATE IT if not os.path.isfile("{0}/resource/dbAssets.txt".format( os.path.dirname(__file__))): self.assets_db.update_asset_db() # SETTING UP THE QCOMPLETER FOR FASTER INTERACTIONS db_file = open( "{0}/resource/dbAssets.txt".format(os.path.dirname(__file__)), "r") assets = db_file.readlines() # Cleaning the line stripping out the end line character for i in range(len(assets)): assets[i] = assets[i].rstrip('\n') self.asset_to_path = asset_entity.AssetEntity() self.completer = QCompleter() model = QtGui.QStringListModel() self.completer.setModel(model) model.setStringList(assets) f = QtCore.QFile(ui_path) f.open(QtCore.QFile.ReadOnly) loader = QtUiTools.QUiLoader() self.ui = loader.load(f, parentWidget=self) f.close()
def get_theme_vars(self, theme_path): file = QtCore.QFile(theme_path) file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text) # type: ignore stream = QtCore.QTextStream(file) theme_str = stream.readAll() matches = re.search('\{(.*)\}', theme_str, flags=re.DOTALL) # noqa W605 if matches is None: return match = matches[1] if match is None: return var_strings = match.replace('\n', '').replace(' ', '').split(';')[:-1] var_map = {} for str in var_strings: key, value = str.split(':') var_map[key] = value return var_map
def __init__(self, manager, parent=None): super().__init__(parent) self.manager = manager file = QtCore.QFile( os.path.join(os.path.dirname(__file__), "settings.ui")) file.open(QtCore.QFile.ReadOnly) self.ui = QtUiTools.QUiLoader().load(file, self) file.close() layout = QtWidgets.QVBoxLayout(self) layout.addWidget(self.ui) self.setMinimumSize(400, 250) self.setWindowTitle(i18n("Run Action Settings")) self.ui.label.setText(i18n("Available actions")) for action in self.manager.actions: item = QtWidgets.QListWidgetItem(self.ui.listWidget) item.setText(action.title) item.setIcon(action.icon) item.setData(QtCore.Qt.UserRole, action.id) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) item.setCheckState(QtCore.Qt.Unchecked if action.id in self. manager.disabledActions else QtCore.Qt.Checked) self.ui.listWidget.addItem(item) self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject)
def showFiles(self, files): for fn in files: file = QtCore.QFile(self.currentDir.absoluteFilePath(fn)) size = QtCore.QFileInfo(file).size() fileNameItem = QtWidgets.QTableWidgetItem(fn) fileNameItem.setFlags(fileNameItem.flags() ^ QtCore.Qt.ItemIsEditable) sizeItem = QtWidgets.QTableWidgetItem("%d KB" % (int( (size + 1023) / 1024))) sizeItem.setTextAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight) sizeItem.setFlags(sizeItem.flags() ^ QtCore.Qt.ItemIsEditable) # a check item to choose the spec files checkItem = QtWidgets.QTableWidgetItem() checkItem.setCheckState(QtCore.Qt.Checked) checkItem.setTextAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignHCenter) row = self.filesTable.rowCount() self.filesTable.insertRow(row) self.filesTable.setItem(row, 0, checkItem) self.filesTable.setItem(row, 1, fileNameItem) self.filesTable.setItem(row, 2, sizeItem) self.filesFoundLabel.setText( "%d file(s) found (Double click on a file to open it)" % len(files))
def __init__(self, parent=None): super(DragWidget, self).__init__(parent) dictionaryFile = QtCore.QFile(':/dictionary/words.txt') dictionaryFile.open(QtCore.QIODevice.ReadOnly) x = 5 y = 5 for word in QtCore.QTextStream(dictionaryFile).readAll().split(): wordLabel = DragLabel(word, self) wordLabel.move(x, y) wordLabel.show() x += wordLabel.width() + 2 if x >= 195: x = 5 y += wordLabel.height() + 2 newPalette = self.palette() newPalette.setColor(QtGui.QPalette.Window, QtCore.Qt.white) self.setPalette(newPalette) self.setAcceptDrops(True) self.setMinimumSize(400, max(200, y)) self.setWindowTitle("Draggable Text")
def set_stylesheet(self, app, filepath): file_qss = QtCore.QFile(filepath) if file_qss.exists(): file_qss.open(QtCore.QFile.ReadOnly) stylesheet = QtCore.QTextStream(file_qss).readAll() app.setStyleSheet(stylesheet) file_qss.close()
def loadUiWidget(self, uifilename): loader = QtUiTools.QUiLoader() uifile = QtCore.QFile(uifilename) uifile.open(QtCore.QFile.ReadOnly) ui = loader.load(uifile, self) uifile.close() return ui
def findDescriptionAndImages(self, uniqueName, docName): if self.documentationDir.exists(docName): self.examples[uniqueName]['document path'] = docName exampleDoc = QtXml.QDomDocument() exampleFile = QtCore.QFile(self.documentationDir.absoluteFilePath(docName)) exampleDoc.setContent(exampleFile) paragraphs = exampleDoc.elementsByTagName("p") for p in range(paragraphs.length()): descriptionNode = paragraphs.item(p) description = self.readExampleDescription(descriptionNode) if QtCore.QString(description).indexOf(QtCore.QRegExp(QtCore.QString("((The|This) )?(%1 )?.*(example|demo)").arg(self.examples[uniqueName]['name']), QtCore.Qt.CaseInsensitive)) != -1: self.examples[uniqueName]['description'] = description break images = exampleDoc.elementsByTagName("img") imageFiles = [] for i in range(images.length()): imageElement = images.item(i).toElement() source = QtCore.QString(imageElement.attribute("src")) if "-logo" not in source: imageFiles.append(self.documentationDir.absoluteFilePath(source)) if len(imageFiles) > 0: self.examples[uniqueName]['image files'] = imageFiles
def __init__(self): app = QG.QGuiApplication( sys.argv ) app.setAttribute(Qt.AA_EnableHighDpiScaling) app.setAttribute(Qt.AA_UseOpenGLES) engine = QML.QQmlApplicationEngine() engine.objectCreated.connect(self.setWindow) qmlFile = os.path.join( os.path.dirname(__file__), "ui/main.qml" ) headers = ("Groups", "Description") file = QtCore.QFile(os.path.join( os.path.dirname(__file__), "samples/editabletreemodel/default.txt" )) file.open(QtCore.QIODevice.ReadOnly) assetModel = AssetModel(headers, str(file.readAll())) bakers = Baker() root = engine.rootContext() root.setContextProperty("appconfigsmodel", crossbaker.bakers.allApps()) root.setContextProperty("assetModel", assetModel) root.setContextProperty("baker", bakers) root.setContextProperty("bakers", crossbaker.bakers.bakernames()) engine.load(QC.QUrl.fromLocalFile( os.path.abspath( qmlFile ) )) if not engine.rootObjects(): sys.exit() self.show() app.exec_()
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) headers = ("Title", "Description") file = QtCore.QFile(':/default.txt') file.open(QtCore.QIODevice.ReadOnly) model = TreeModel(headers, str(file.readAll())) file.close() self.view.setModel(model) for column in range(model.columnCount(QtCore.QModelIndex())): self.view.resizeColumnToContents(column) self.exitAction.triggered.connect(QtGui.qApp.quit) self.view.selectionModel().selectionChanged.connect(self.updateActions) self.actionsMenu.aboutToShow.connect(self.updateActions) self.insertRowAction.triggered.connect(self.insertRow) self.insertColumnAction.triggered.connect(self.insertColumn) self.removeRowAction.triggered.connect(self.removeRow) self.removeColumnAction.triggered.connect(self.removeColumn) self.insertChildAction.triggered.connect(self.insertChild) self.updateActions()
def initPages(self, files): loader = QtUiTools.QUiLoader() for i in files: file = QtCore.QFile(str(i)) if file.open(QtCore.QFile.ReadOnly): page = loader.load(file) self.addPage(page)
def theme_change_msgbox(self): msgBox = QtWidgets.QMessageBox() if self.theme == "dark": file = QtCore.QFile(":/qdarkstyle/style.qss") file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text) stream = QtCore.QTextStream(file) msgBox.setStyleSheet(stream.readAll()) msgBox_icon = QtGui.QIcon() msgBox_icon.addPixmap(QtGui.QPixmap(self.icon_file), QtGui.QIcon.Normal, QtGui.QIcon.On) msgBox.setWindowIcon(msgBox_icon) msgBox.setTextFormat(QtCore.Qt.RichText) msgBox.setWindowTitle("App Restart Required") msgBox.setIcon(msgBox.Warning) msgBox.setText("App restart required to change theme") restart = msgBox.addButton("Restart", QtWidgets.QMessageBox.YesRole) cancel = msgBox.addButton("Cancel", QtWidgets.QMessageBox.RejectRole) msgBox.exec_() if msgBox.clickedButton() is restart: self.restart_program() elif msgBox.clickedButton() is cancel: self.message_box(f"The theme will be changed on next run", info=True)
def message_box(self, text, warning=False, info=False, critical=False): msgBox = QtWidgets.QMessageBox() if self.theme == "dark": file = QtCore.QFile(":/qdarkstyle/style.qss") file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text) stream = QtCore.QTextStream(file) msgBox.setStyleSheet(stream.readAll()) msgBox_icon = QtGui.QIcon() msgBox_icon.addPixmap(QtGui.QPixmap(self.icon_file), QtGui.QIcon.Normal, QtGui.QIcon.On) msgBox.setWindowIcon(msgBox_icon) msgBox.setTextFormat(QtCore.Qt.RichText) if warning: msgBox.setWindowTitle("Warning") msgBox.setIcon(msgBox.Warning) if info: msgBox.setWindowTitle("Notice") msgBox.setIcon(msgBox.Information) if critical: msgBox.setWindowTitle("Error") msgBox.setIcon(msgBox.Critical) msgBox.setText(text) msgBox.addButton("OK", QtWidgets.QMessageBox.YesRole) msgBox.exec_()
def __init__(self): QWidget.__init__(self, parent=None) telacheia = ctypes.windll.user32 file = QtCore.QFile('TiraPeças.ui') file.open(QFile.ReadOnly) carregador = QtUiTools.QUiLoader() self.ui = carregador.load(file) grid_layout = QGridLayout() grid_layout.addWidget(self.ui) grid_layout.setMargin(0) self.setLayout(grid_layout) self.setMaximumSize(QtCore.QSize(telacheia.GetSystemMetrics(0), telacheia.GetSystemMetrics(1))) self.setGeometry(telacheia.GetSystemMetrics(0) - telacheia.GetSystemMetrics(0)+8 , telacheia.GetSystemMetrics(1) - telacheia.GetSystemMetrics(1) + 31, telacheia.GetSystemMetrics(0) - 16, telacheia.GetSystemMetrics(1) - 77) self.servidor = "MACROSUL-BTESTE\SQLEXPRESS" self.banco = "DB_desm" self.login = "******" self.senha = "m@crosul" self.servidorof = "Driver={SQL Server Native Client 11.0};Server=" + self.servidor + ';Database=' + self.banco + ';UID=' + \ self.login + ';PWD=' + self.senha self.connection = pyodbc.connect(self.servidorof)
def load_ui_widget(ui_filename, parent=None): loader = QtUiTools.QUiLoader() ui_file = QtCore.QFile(ui_filename) ui_file.open(QtCore.QFile.ReadOnly) ui = loader.load(ui_file, parent) ui_file.close() return ui
def setUp(self): self.temp_file = tempfile.NamedTemporaryFile(delete=False) self.temp_file.close() self.f = QtCore.QFile(self.temp_file.name) self.f.open(QtCore.QIODevice.WriteOnly) self.strings = (py3k.unicode_('foo'), py3k.unicode_('bar')) self.stream = QtCore.QTextStream(self.f)
def __init__(self, parent, title, iconPath): super(CollapsibleGroup, self).__init__(parent) mainLay = QtWidgets.QVBoxLayout(self) mainLay.setContentsMargins(1, 1, 1, 1) titleLay = QtWidgets.QHBoxLayout(self) titleLay.setContentsMargins(0, 0, 0, 0) self.collapsibleCBx = QtWidgets.QCheckBox() self.collapsibleCBx.setChecked(True) self.collapsibleCBx.stateChanged.connect(self.diableGroup) titleLay.addWidget(self.collapsibleCBx) titleWidg, self.title = labeledWidget(QHLine, self, title, iconPath, 30) titleLay.addWidget(titleWidg) mainLay.addLayout(titleLay) self.centerWidg = QtWidgets.QWidget(self) self.centerLay = QtWidgets.QVBoxLayout(self) self.centerLay.setContentsMargins(0, 0, 0, 0) self.centerLay.setSpacing(0) self.centerWidg.setLayout(self.centerLay) mainLay.addWidget(self.centerWidg) self.setLayout(mainLay) st = "" stream = QtCore.QFile(':styles/collapsibleGroup.qss') if stream.open(QtCore.QFile.ReadOnly): st = str(stream.readAll()) stream.close() self.collapsibleCBx.setStyleSheet(st)
def open(self): fileName = QtGui.QFileDialog.getOpenFileName( self, "Open Bookmark File", QtCore.QDir.currentPath(), "XBEL Files (*.xbel *.xml)")[0] if not fileName: return self.treeWidget.clear() handler = XbelHandler(self.treeWidget) reader = QtXml.QXmlSimpleReader() reader.setContentHandler(handler) reader.setErrorHandler(handler) file = QtCore.QFile(fileName) if not file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text): QtGui.QMessageBox.warning( self, "SAX Bookmarks", "Cannot read file %s:\n%s." % (fileName, file.errorString())) return xmlInputSource = QtXml.QXmlInputSource(file) if reader.parse(xmlInputSource): self.statusBar().showMessage("File loaded", 2000)
def initBaseStation(self, uiFilename, parent=None): uiloader = QtUiTools.QUiLoader() uiFile = QtCore.QFile(uiFilename) uiFile.open(QtCore.QFile.ReadOnly) gui = uiloader.load(uiFile, parent) uiFile.close() return gui
def load_project(project_path): """Loads project from p00p file""" file = QtCore.QFile(project_path) if not file.open(QtCore.QIODevice.ReadOnly): raise EnvironmentError(file.errorString()) else: in_ = QtCore.QDataStream(file) # Read and check the header magic = in_.readInt32() if magic != MAGIC_NUMBER: raise EnvironmentError("Bad file format") # Read the version version = in_.readInt32() if version > FORMAT_VERSION: raise EnvironmentError("File too new for this version.") in_.setVersion(QtCore.QDataStream.Qt_5_14) # Read the data data_size = in_.readInt32() data = in_.readRawData(data_size) file.close() return Project.from_JSON_serializable(pickle.loads(bytes(data)), project_path)
def loadUiWidget(self, uifilename, parent=getMayaWindow()): loader = QtUiTools.QUiLoader() uifile = QtCore.QFile(uifilename) uifile.open(QtCore.QFile.ReadOnly) ui = loader.load(uifile, parent) uifile.close() return ui
def loadUi(uiFile, wid, add_layout=True): ''' load a uiFile and wrap its Qt instance under wid ''' from PySide2 import QtUiTools from PySide2 import QtWidgets, QtCore loader = QtUiTools.QUiLoader() uifile = QtCore.QFile(uiFile) uifile.open(QtCore.QFile.ReadOnly) ui = loader.load(uifile, wid) uifile.close() """ for i in vars(ui): try: if not i.startswith("_"): exec("wid.%s = ui.%s" % (i,i)) except: pass """ if add_layout: layout = QtWidgets.QVBoxLayout() layout.addWidget(ui) wid.setLayout(layout) return ui
def load_scene(file_name): """ Carga un elemento de la UI """ loader = QUiLoader() file = QtCore.QFile(file_name) file.open(QtCore.QFile.ReadOnly) file.close() return loader.load(file, None)
def loadUiForm(self, uiPath): loader = QtUiTools.QUiLoader() file = QtCore.QFile(uiPath) file.open(QtCore.QFile.ReadOnly) LoadedWidget = loader.load(file, self) file.close() return LoadedWidget
def __init__(self): QtWidgets.QWidget.__init__(self) path = os.path.abspath(__file__) dir_path = os.path.dirname(path).replace('\\', '/') + '/' file = QtCore.QFile(dir_path + 'scene_writerUI.ui') file.open(QtCore.QFile.ReadOnly) loader = QtUiTools.QUiLoader() self.ui = loader.load(file, self) # WINDOW STYLE self.icons_path = dir_path + '/icons/' self.setWindowIcon(QtGui.QIcon(self.icons_path + 'write.png')) scene = nuke_specific_functions.get_the_scene() self.scene_name = scene if scene != '' else 'Untitled' self.setWindowTitle('Scene writer ({})'.format( self.scene_name.split('/')[-1])) self.setFixedSize(1167, 501) self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # LOG self.showing_log = True # SETUP self.setup_style() self.make_connections() self.append_to_log('-- POPULATING SCANLINE RENDER TABLE --', 'cyan') self.populate_scanline() self.append_to_log('-- POPULATING RAY RENDER TABLE --', 'cyan') self.populate_ray() self.append_to_log('-- POPULATING WRITE NODES TABLE --', 'cyan') self.populate_write() self.show()
def checkDirsQt(): it = Core.QDirIterator(BASEDIR, Core.QDirIterator.Subdirectories) while it.hasNext(): this = Core.QFile(it.next()) info = Core.QFileInfo(this) if info.suffix() == "iso": print(info.absolutePath())
def findFiles(self, files, text): progressDialog = QtWidgets.QProgressDialog(self) progressDialog.setCancelButtonText("&Cancel") progressDialog.setRange(0, len(files)) progressDialog.setWindowTitle("Find Files") foundFiles = [] for i in range(len(files)): progressDialog.setValue(i) progressDialog.setLabelText("Searching file number %d of %d..." % (i, len(files))) QtCore.qApp.processEvents() if progressDialog.wasCanceled(): break inFile = QtCore.QFile(self.currentDir.absoluteFilePath(files[i])) if inFile.open(QtCore.QIODevice.ReadOnly): stream = QtCore.QTextStream(inFile) while not stream.atEnd(): if progressDialog.wasCanceled(): break line = stream.readLine() if text in line: foundFiles.append(files[i]) break progressDialog.close() return foundFiles
def resolveExeFile(self, name): dir = self.resolveDir(name) fileName = self.info[name]['filename'] pyFile = QtCore.QFile(dir.path() + '/' + fileName + '.py') if pyFile.exists(): return pyFile.fileName() pywFile = QtCore.QFile(dir.path() + '/' + fileName + '.pyw') if pywFile.exists(): return pywFile.fileName() Colors.debug("- WARNING: Could not resolve executable:", dir.path(), fileName) return '__executable not found__'
def loadUI(uifile_path): #QtCore.QResource.addSearchPath("E:/Users/admin/Documents/GitHub/SERiggingTools/UI") uifile = QtCore.QFile(uifile_path) print(uifile) uifile.open(QtCore.QFile.ReadOnly) #QtCore.QResource.registerResource("E:/Users/admin/Documents/GitHub/SERiggingTools/UI/UIResource.qrc") uiWindow = QtUiTools.QUiLoader().load(uifile) uifile.close() uiWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) setControlToButtonMap(uiWindow) setSelectorCallBack(uiWindow) setButtonCallback(uiWindow) setMutiSelectedButtonCallback(uiWindow) setResetToModelBasePose(uiWindow) setIKFKShow(uiWindow) uiWindow.BodyBG.setPixmap(QtGui.QPixmap( (uiRootFile + "/ControllUIBG.png"))) uiWindow.RHandBG.setPixmap( QtGui.QPixmap((uiRootFile + "/ControllUIRHandBG.png"))) uiWindow.LHandBG.setPixmap( QtGui.QPixmap((uiRootFile + "/ControllUILHandBG.png"))) uiWindow.FootBG.setPixmap(QtGui.QPixmap((uiRootFile + "/Foot.png"))) refreshCharacterInSelector(uiWindow) return uiWindow
def saveFile(self): fileName = QtGui.QFileDialog.getSaveFileName(self, "Save file as", '', '*.cht') if fileName: f = QtCore.QFile(fileName) if f.open(QtCore.QFile.WriteOnly | QtCore.QFile.Text): for row in range(self.model.rowCount(QtCore.QModelIndex())): pieces = [] pieces.append( self.model.data( self.model.index(row, 0, QtCore.QModelIndex()), QtCore.Qt.DisplayRole)) pieces.append( str( self.model.data( self.model.index(row, 1, QtCore.QModelIndex()), QtCore.Qt.DisplayRole))) pieces.append( self.model.data( self.model.index(row, 0, QtCore.QModelIndex()), QtCore.Qt.DecorationRole).name()) f.write(QtCore.QByteArray(','.join(pieces))) f.write('\n') f.close() self.statusBar().showMessage("Saved %s" % fileName, 2000)