def __init__(self): ui_file_name = "record_frame.ui" ui_file = QFile(ui_file_name) if not ui_file.open(QIODevice.ReadOnly): print("can not open file " + ui_file_name) sys.exit(-1) self.window = QUiLoader().load(ui_file) ui_file.close() self._component_bind() self.window.show() self.status = "Ready" self.record = [] self.current_mill_time = current_time() self.delay = int(self.window.record_time_stepper.value()) self.run_times = int(self.window.run_time_stepper.value()) self.start_hot_key = self.window.run_hot_key.currentText() self.stop_hot_key = self.window.stop_hot_key.currentText() # self.window.record_script self.window.run_hot_key.addItems(self.HOT_KEYS) self.window.run_hot_key.setCurrentIndex(8) self.window.stop_hot_key.addItems(self.HOT_KEYS) self.window.stop_hot_key.setCurrentIndex(9) self._refresh_scripts() self.window.status.setText(self.status) self.hookManager = pyWinhook.HookManager() self.hookManager.MouseAll = self._mouse_move_handler self.hookManager.KeyAll = self._keyboard_click_handler self.hookManager.HookKeyboard() self.hookManager.HookMouse()
def load_ui(self): loader = QUiLoader() path = os.fspath(Path(__file__).resolve().parent / "form.ui") ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader.load(ui_file, self) ui_file.close()
def importXmlDOM(filename): ''' The QDomDocument class represents the entire XML document The DOM classes that will be used most often are QDomNode , QDomDocument , QDomElement and QDomText The DOM tree might end up reserving a lot of memory if the XML document is big. For such documents, the QXmlStreamReaderor the QXmlQuery classes might be better solutions. :param filename: filename_path :return: document ''' document = QDomDocument() error = None file = None try: # instantiate a device(QFile) specified by filename file = QFile(filename) if not file.open(QIODevice.ReadOnly): raise IOError(str(file.errorString())) # setContent parses an XML file and creates the DOM tree that represents the document if not document.setContent(file): raise ValueError("could not parse XML") except (IOError, OSError, ValueError) as e: error = "Failed to import: {0}".format(e) finally: if file is not None: file.close() if error is not None: print(error) return document
def load_ui(ui_file, parent=None): loader = QUiLoader() file = QFile(ui_file) file.open(QFile.ReadOnly) myWidget = loader.load(file, None) myWidget.show() file.close() myWidget.show() return myWidget
def load_ui(name, custom_widgets=[], parent=None): loader = QUiLoader() for cw in custom_widgets: loader.registerCustomWidget(cw) path = os.path.join(os.path.dirname(__file__), "ui", name) ui_file = QFile(path) if not ui_file.open(QFile.ReadOnly): logging.critical("Cannot open {}: {}".format(path, ui_file.errorString())) sys.exit(-1) ui = loader.load(ui_file, parent) ui_file.close() return ui
def initUI(self, uiname, mode): # release mode # TODO: convert .ui to py code app = QApplication(sys.argv) # debug mode if mode == 'debug': ui_file_name = uiname ui_file = QFile(ui_file_name) if not ui_file.open(QIODevice.ReadOnly): print(f"Cannot open {ui_file_name}: {ui_file.errorString()}") sys.exit(-1) loader = QUiLoader() window = loader.load(ui_file) ui_file.close() if not window: print(loader.errorString()) sys.exit(-1) window.show() return app, window
def load_items(self, file_name: str, gim): input_file = QFile(file_name) if input_file.open(QIODevice.ReadOnly): input_stream = QDataStream(input_file) while not input_stream.atEnd(): item_type = input_stream.readInt8() item_name = input_stream.readString() if item_type == QGraphicsRectItem.type(QGraphicsRectItem()): rect = QGraphicsRectItem() self.input_to_rect_item(input_stream, rect) self.scene.addItem(rect) gim.append_shape(rect, rect.type(), rect.pen(), rect.brush()) print("Rectangle loaded") elif item_type == QGraphicsEllipseItem.type( QGraphicsEllipseItem()): ellipse = QGraphicsEllipseItem() self.input_to_rect_item(input_stream, ellipse) self.scene.addItem(ellipse) gim.append_shape(ellipse, ellipse.type(), ellipse.pen(), ellipse.brush()) print("Ellipse loaded") elif item_type == QGraphicsPolygonItem.type( QGraphicsPolygonItem()): polygon = QGraphicsPolygonItem() self.input_to_polygon_item(input_stream, polygon) self.scene.addItem(polygon) gim.append_shape(polygon, polygon.type(), polygon.pen(), polygon.brush()) print("l polygon") elif item_type == QGraphicsLineItem.type(QGraphicsLineItem()): line = QGraphicsLineItem() self.input_to_line_item(input_stream, line) self.scene.addItem(line) gim.append_shape(line, line.type(), line.pen(), QBrush(Qt.black)) print("Line loaded") gim.return_shapes()[-1].name = item_name ItemsInputOutput.set_item_flags(self.scene) input_file.close()
def save_items(self, file_name: str, gim): output_file = QFile(file_name) if output_file.open(QIODevice.WriteOnly): output_stream = QDataStream(output_file) scene_items_reverse = self.scene.items() scene_items_reverse.reverse() for item in scene_items_reverse: output_stream.writeInt8(item.type()) output_stream.writeString(gim.get_name_from_reference(item)) if type(item) == QGraphicsRectItem: self.output_from_rect_item(output_stream, item) print("rect saved!") elif type(item) == QGraphicsEllipseItem: self.output_from_rect_item(output_stream, item) print("ellipse saved!") elif type(item) == QGraphicsPolygonItem: self.output_from_polygon_item(output_stream, item) print("polygon saved!") elif type(item) == QGraphicsLineItem: self.output_from_line_item(output_stream, item) print("line saved!") output_file.close()
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)
def __init__(self): super(MainWindow, self).__init__() loader = QUiLoader() path = os.path.join(os.path.dirname(__file__), "main_window.ui") ui_file = QFile(path) ui_file.open(QFile.ReadOnly) self.window = loader.load(ui_file, self) ui_file.close() self.week = 1 self.sel_block = (-1, -1) self.group = 'WCY18IJ5S1' self.blocks = list() self.loading_widget = None self.main_widget = self.window.findChild(QWidget, 'college_schedule') self.table_widget = self.window.findChild(QTableWidget, 'table_widget') self.next_week = self.window.findChild(QPushButton, 'next_week') self.previous_week = self.window.findChild(QPushButton, 'previous_week') self.save_note_button = self.window.findChild(QPushButton, 'save_note') self.group_box = self.window.findChild(QComboBox, 'group_box') self.download_button = self.window.findChild(QPushButton, 'download_data') self.note = self.window.findChild(QTextEdit, 'note') self.next_week.clicked.connect(lambda: self.get_week_click(self.week + 1)) self.previous_week.clicked.connect(lambda: self.get_week_click(self.week - 1)) self.save_note_button.clicked.connect(self.save_note_click) self.download_button.clicked.connect(lambda: self.load_data(True)) self.table_widget.cellClicked.connect(self.block_click) self.table_widget.cellDoubleClicked.connect(self.block_double_click) self.group_box.currentTextChanged.connect(self.group_change) self.loading_signal.connect(self.loading_slot) self.set_blocks_signal.connect(self.set_blocks_slot) self.scraper = Scraper() t = threading.Thread(target=lambda: self.scraper.start(self, self.group)) t.start()
def __init__(self): QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts) app = QApplication(sys.argv) app.setStyle(QStyleFactory.create('Fusion')) ui_file_name = '%s.ui' % Path(__file__).stem ui_file = QFile(ui_file_name) if not ui_file.open(QIODevice.ReadOnly): print('Cannot open %s: %s' % (ui_file_name, ui_file.errorString())) sys.exit(-1) loader = QUiLoader() self.window = loader.load(ui_file) ui_file.close() if not self.window: print(loader.errorString()) sys.exit(-1) self.connect() self.setting() self.window.show() sys.exit(app.exec())
os.system('rm *wavuntagged.wav') os.system('{} {}'.format(soundfile_editor, master_filename)) print("") except: traceback.print_exc() application = QApplication(sys.argv) ui_file = QFile(piece_ui_filepath) if not ui_file.open(QIODevice.ReadOnly): print(f"Cannot open {ui_file_name}: {ui_file.errorString()}") sys.exit(-1) ui_loader = QUiLoader() main_window = ui_loader.load(ui_file) print("main_window: {} {}".format(main_window, type(main_window))) ui_file.close() if not main_window: print(loader.errorString()) sys.exit(-1) ''' Each instance of this class encapsulates one Csound control channel along with the Qt Widget that manages it. The methods of this class should have cases for handling different types of Csound channels (strings or numbers), and different types of Qt Widgets. The Qt Widget types and corresponding signals handled here are (from less to more abstract): 1. AbstractSlider and subclasses: valueChanged. 3. QCheckBox: stateChanged. 4. QAbstractButton: pressed, released.
def load_ui(self): self.loader = QUiLoader(self) uifile = QFile(os.path.dirname(__file__) / Path("steps.ui")) self.ui = self.loader.load(uifile, parentWidget=self) uifile.close() self.setup_ui()