def load_ui_widget(self, ui_filename, parent=None): loader = uic() file = QFile(ui_filename) file.open(QFile.ReadOnly) self.ui = loader.load(file, parent) file.close() return self.ui
def testBasic(self): '''QFile.getChar''' obj = QFile(self.filename) obj.open(QIODevice.ReadOnly) self.assertEqual(obj.getChar(), (True, 'a')) self.assertFalse(obj.getChar()[0]) obj.close()
class TestQFileSignalBlocking(unittest.TestCase): '''Test case for blocking the signal QIODevice.aboutToClose()''' def setUp(self): #Set up the needed resources - A temp file and a QFile self.called = False handle, self.filename = mkstemp() os.close(handle) self.qfile = QFile(self.filename) def tearDown(self): #Release acquired resources os.remove(self.filename) del self.qfile def callback(self): #Default callback self.called = True def testAboutToCloseBlocking(self): #QIODevice.aboutToClose() blocking QObject.connect(self.qfile, SIGNAL('aboutToClose()'), self.callback) self.assert_(self.qfile.open(QFile.ReadOnly)) self.qfile.close() self.assert_(self.called) self.called = False self.qfile.blockSignals(True) self.assert_(self.qfile.open(QFile.ReadOnly)) self.qfile.close() self.assert_(not self.called)
def __init__(self, parent=None): super(DragWidget, self).__init__(parent) dictionaryFile = QFile(':/dictionary/words.txt') dictionaryFile.open(QIODevice.ReadOnly) x = 5 y = 5 for word in 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(QPalette.Window, Qt.white) self.setPalette(newPalette) self.setAcceptDrops(True) self.setMinimumSize(400, max(200, y)) self.setWindowTitle("Draggable Text")
def testBug721(self): obj = QFile(self.filename) obj.open(QIODevice.ReadOnly) memory = obj.map(0, 1) self.assertEqual(len(memory), 1) self.assertEqual(memory[0], py3k.b('a')) obj.unmap(memory)
def load_ui_widget(self, ui_filename, parent=None): loader = uic() file = QFile(ui_filename) file.open(QFile.ReadOnly) loader.registerCustomWidget(MouthView) loader.registerCustomWidget(WaveformView) self.ui = loader.load(file, parent) file.close() return self.ui
def __init__(self): # 从文件中加载UI定义 qfile_stats = QFile("classifier.ui") qfile_stats.open(QFile.ReadOnly) qfile_stats.close() self.ui = QUiLoader().load(qfile_stats) self.ui.button1.clicked.connect(self.click_button1) self.ui.button2.clicked.connect(self.click_button2)
def __init__(self, ui_file, parent=None): #reference to our music player self.music_player = QMediaPlayer() self.music_player.setVolume(100) self.music_player.positionChanged.connect(self.position_changed) self.music_player.durationChanged.connect(self.duration_changed) #call parent QObject constructor super(MainWindow, self).__init__(parent) #load the UI file into Python ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(ui_file) #always remember to close files ui_file.close() #add event listeners open_action = self.window.findChild(QAction, 'action_open') open_action.triggered.connect(self.open_action_triggered) quit_action = self.window.findChild(QAction, 'action_quit') quit_action.triggered.connect(self.quit_action_triggered) play_button = self.window.findChild(QPushButton, 'play_button') play_button.clicked.connect(self.play_button_clicked) pause_button = self.window.findChild(QPushButton, 'pause_button') pause_button.clicked.connect(self.pause_button_clicked) toggle_forward = self.window.findChild(QPushButton, 'toggle_forward') toggle_forward.clicked.connect(self.toggle_forward_function) self.progress_bar = self.window.findChild(QSlider, 'progress_bar') self.progress_bar.sliderMoved.connect(self.set_position) # toggle_back = self.window.findChild(QPushButton, 'toggle_back') # toggle_back.clicked.connect(self.toggle_back_function) self.song_library = self.window.findChild(QListWidget, 'song_library') #self.song_library.addItem(1, "videogame.mp3") self.volume_slider = self.window.findChild(QSlider, 'volume_slider') self.volume_slider.valueChanged.connect(self.volume_control) self.volume_slider.setMinimum(1) self.volume_slider.setMaximum(90) self.volume_slider.setValue(25) self.volume_slider.setTickInterval(10) self.volume_slider.setTickPosition(QSlider.TicksBelow) #show window to user self.window.show()
def __init__(self, uiFilePath): super(FlickerView, self).__init__() uiFile = QFile(uiFilePath) uiFile.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(uiFile) uiFile.close() self.loadLightsButton = self.window.findChild(QPushButton, 'loadLightsButton') self.loadLightsButton.clicked.connect(self.getSelectedLights) self.lightComboBox = self.window.findChild(QComboBox, 'lightComboBox') self.lightComboBox.activated.connect(self.loadSelectedLight) self.keyTableWidget = self.window.findChild(QTableWidget, 'keyTableWidget') self.keyTableWidget.cellChanged.connect(self.tableChanged) self.keyRangeTextEdit = self.window.findChild(QTextEdit, 'keyRangeTextEdit') self.loadKeysButton = self.window.findChild(QPushButton, 'loadKeysButton') self.loadKeysButton.clicked.connect(self.loadKeys) self.randomKeyButton = self.window.findChild(QPushButton, 'randomKeyButton') self.randomKeyButton.clicked.connect(self.generateRandomKey) self.deleteKeyButton = self.window.findChild(QPushButton, 'deleteKeyButton') self.deleteKeyButton.clicked.connect(self.deleteKey) self.biasTextEdit = self.window.findChild(QTextEdit, 'biasTextEdit') self.generateKeysButton = self.window.findChild( QPushButton, 'generateKeysButton') self.generateKeysButton.clicked.connect(self.generateRandomKeys) self.exposureRange1TextEdit = self.window.findChild( QTextEdit, 'exposureRange1TextEdit') self.exposureRange2TextEdit = self.window.findChild( QTextEdit, 'exposureRange2TextEdit') self.timeRange1TextEdit = self.window.findChild( QTextEdit, 'timeRange1TextEdit') self.timeRange2TextEdit = self.window.findChild( QTextEdit, 'timeRange2TextEdit') self.keys = [] self.window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) self.window.show()
def get_ui(): # TODO: use compiled ui file instead of dynamic loading # pyside2-uic mainwindow.ui > ui_mainwindow.py ui_file = QFile("mainwindow.ui") ui_file.open(QFile.ReadOnly) loader = QUiLoader() window = loader.load(ui_file) ui_file.close() return window
def setup_ui(self): loader = QUiLoader() file = QFile('./main_window.ui') file.open(QFile.ReadOnly) self._window = loader.load(file) file.close() self.set_title() self.set_buttons() self.set_edits()
def __init__(self): designer_file = QFile("server.ui") designer_file.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(designer_file) designer_file.close() self.window.setWindowTitle("Server Application") self.window.lineEdit_host.setText('127.0.0.1') self.window.lineEdit_port.setText('1996') self.window.pushButton_start_server.clicked.connect(self.start_server)
def __init__(self): QtWidgets.QWidget.__init__(self) # super().__init__() loader = QUiLoader() ui_file = QFile("form.ui") ui_file.open(QFile.ReadOnly) self.ui = loader.load(ui_file, self) ui_file.close() self.ui.allRadioButton.setChecked(True) title_str = self.ui.analyseButton.clicked.connect(self.analyse)
def create_dialog(parent=None): ui_file = QFile('settings.ui') ui_file.open(QFile.ReadOnly) loader = QUiLoader() loader.registerCustomWidget(SettingsDialog) win = loader.load(ui_file, parent) ui_file.close() return win
def __init__(self): super().__init__() # 从文件中加载ui定义 qfile = QFile("../ui/uifile.ui") qfile.open(QFile.ReadOnly) qfile.close() # 从ui定义中动态创建一个窗口对象 self.ui = QUiLoader().load(qfile)
def main(): app = QApplication(sys.argv) ui_file = QFile(os.path.join(os.path.dirname(__file__), "main.ui")) ui_file.open(QFile.ReadOnly) loader = QUiLoader() Window(loader.load(ui_file)) sys.exit(app.exec_())
def _read_file(self, file_path: str) -> str: from PySide2.QtCore import QFile from PySide2.QtCore import QTextStream from PySide2.QtCore import QIODevice file = QFile(file_path) file.open(QIODevice.ReadOnly) ts = QTextStream(file) string = ts.readAll() return string
def __init__(self, ui_file, parent=None): super(Form, self).__init__(parent) ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(ui_file) ui_file.close() self.window.show() self.stacked = self.window.findChild(QStackedWidget, 'stackedWidget') self.setup()
def loadUi(self): """ load GUI """ loader = QUiLoader() path = os.path.join(os.path.dirname(__file__), "form.ui") ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader.load(ui_file, self) ui_file.close()
def add_player_to_team(self, parent, summoner): file = QFile("UI/ui_playerteamwidget.ui") file.open(QFile.ReadOnly) loader = QUiLoader() PlayerTeamWidget = loader.load(file, parent) PlayerTeamWidget.summoner = summoner file.close() return PlayerTeamWidget
def getprod1(callval1, codnum1, prodnom1): #loginwindow.show() connectionStock1 = MySQLdb.connect(host='xxxxxxxxxxxx', port=3336, database='xxxxStock', user='******', password='******') QueryprodC1 = """SELECT codigo, nombre, PrecioDetal FROM stockRioCuarto WHERE codigo='"""+str(codnum1)+"""';""" QueryprodN1 = """SELECT codigo, nombre, PrecioDetal FROM stockRioCuarto WHERE locate('""" + str(prodnom1) + """', nombre);""" cursorQp1 = connectionStock1.cursor() if callval1 == int(1): Queryprodf1=QueryprodC1 if callval1 == int(2): Queryprodf1=QueryprodN1 cursorQp1.execute(Queryprodf1) # print(result) connectionStock1.commit() recordst1 = cursorQp1.fetchall() recordst2 = recordst1[int(int(len(recordst1))-int(1))] cursorQp1.close() print(recordst1) for i in range(int(len(recordst1))): stockwfile = QFile("prodstockwidget.ui") stockwfile.open(QFile.ReadOnly) stockloader = QUiLoader() stockwwindow = stockloader.load(stockwfile) tam1=QSize() tam1.setHeight(44) tam1.setWidth(963) itemN1 = QtWidgets.QListWidgetItem() itemN1.setSizeHint(tam1) Codpros1 = stockwwindow.findChild(QLabel, 'codn1') Nombpros1 = stockwwindow.findChild(QLabel, 'nomp1') pricest1 = stockwwindow.findChild(QLabel, 'preciow1') Codpros1.setText(str(recordst1[int(i)][0])) Nombpros1.setText(str(recordst1[int(i)][1])) pricest1.setText(str(recordst1[int(i)][2])) Busqlis1.addItem(itemN1) Busqlis1.setItemWidget(itemN1, stockwwindow)
def load_ui(self): #main loader path = os.path.join(os.path.dirname(__file__), "settings.ui") print(path) ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader = QUiLoader() win = loader.load(ui_file, self) win.showFullScreen() ui_file.close()
def load_style(self): """ The style is a css-like file """ file = QFile(":/styles/style.qss") file.open(QFile.ReadOnly) style = file.readAll() style = style.data().decode() file.close() self.setStyleSheet(style)
def __init__(self): # 从UI中加载 qfile_stats = QFile("UI/export_0.1.ui") qfile_stats.open(QFile.ReadOnly) qfile_stats.close() # 从UI定义中动态创建一个响应的窗口对象 # 注意:里面的空间对象也成为窗口对象的属性了 # 比如:self.ui.button, self.ui.textEdit self.ui = QUiLoader().load(qfile_stats)
def __init__(self): loader = QUiLoader() dirname = os.path.dirname(os.path.abspath(__file__)) os.chdir(dirname) ui_file = QFile("mover.ui") ui_file.open(QFile.ReadOnly) self.interface = loader.load(ui_file) self.interface.setWindowTitle( 'Projeto Integrador 2 - Carrinho Autônomo') ui_file.close() super(janela, self).__init__()
def loadscreen(self): try: ui_file = QFile(Mainwindow.guiname) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(ui_file) ui_file.close() self.window.show() self.log.debug('Loading screen ' + self.guiname) except FileNotFoundError: self.log.debug("Could not find {}".format(self.guiname)) # CATCHES EXIT SHUTDOWN
def __init__(self): # 从文件中加载UI定义 qfile_base = QFile('ui/第一个小说界面.ui') qfile_base.open(QFile.ReadOnly) qfile_base.close() # 从UI定义中动态创建一个相应的窗口对象 # 注意:里面的控件对象也成为窗口对象的属性了 # 比如self.ui.button, self.ui.textEdit self.ui = QUiLoader().load(qfile_base) self.ui.searchBtn.clicked.connect(self.searchBtnClick)
def buildGUI(self): ui_file_loader = QUiLoader() dialog_ui_file = QFile("ui/select_ic.ui") dialog_ui_file.open(QFile.ReadOnly) self._window = ui_file_loader.load(dialog_ui_file) dialog_ui_file.close() self.__lv = self._window.findChild(QListView, "listView") self.__lv.setModel(self.__ic_model) self.__lv.activated.connect(self.onActivated) self._window.accepted.connect(self.onAccepted)
def __init__(self): super().__init__() file = QFile("mainwindow.ui") file.open(QFile.ReadOnly) self.ui = QUiLoader().load(file, self) file.close() self.machine = transitions.Machine(model=self, states=["disconnected", "waiting", "placing", "aiming"], initial='disconnected', transitions=[{ "trigger": "get_aim", "source": "waiting", "dest": "aiming" }, { "trigger": "fire", "source": "aiming", "dest": "waiting" }, { "trigger": "get_place", "source": "waiting", "dest": "placing" }, { "trigger": "place", "source": "placing", "dest": "waiting" }, { "trigger": "server_connect", "source": "disconnected", "dest": "waiting", "after": "on_connect" }, { "trigger": "server_disconnect", "source": "*", "dest": "disconnected", "after": "on_disconnect" }], auto_transitions=False, queued=True) self.disconnect_event = asyncio.Event() self.loop = asyncio.get_event_loop() self.ui.connect_btn.clicked.connect(self.handle_connect_disconnect_btn) self.ui.input_edit.returnPressed.connect(self.handle_input) self.ui.execute_btn.clicked.connect(self.handle_input) self.pusher_client = pysherasync.PusherAsyncClient(self.APP_KEY, cluster=self.CLUSTER) self.client_task: Optional[asyncio.Task] = None self.connection_ready = asyncio.Event() self.pusher_socket = None self.ui.show()
def getUiFromFile(uiFileName): uiFile = QFile(uiFileName) uiFile.open(QFile.ReadOnly) uiLoader = QUiLoader() ui = uiLoader.load(uiFile) uiFile.close() return ui
def load_ui(self): path = os.path.join(os.path.dirname(__file__), "categories.ui") print(path) ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader = QUiLoader() win = loader.load(ui_file, self) self.center() #win.show() ui_file.close()
def setup_ui(self): loader = QUiLoader() file = QFile('./dialog.ui') file.open(QFile.ReadOnly) self._window = loader.load(file) file.close() self.set_title() self.set_buttons() self._window.finished.connect(self.finish_dialog)
def async_play_sound(self): file = QFile(":/sounds/click.mp3") file.open(QFile.ReadOnly) byte_array = file.readAll() file.close() with tempfile.NamedTemporaryFile("wb", delete=True) as temp: temp.write(byte_array.data()) playsound(temp.name)
def load_ui(self): print('loadui') #laods the answer screen and applies the theme path = os.path.join(os.path.dirname(__file__), "ansSheet.ui") print(path) ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self.win=loader.load(ui_file, self) #win.show() ui_file.close()
def __init__(self, ui_file): """Initialize the exporter window Arguments: ui_file {str} -- Path to the Qt ui file """ file = QFile(ui_file) file.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(file)
def testPhrase(self): #Test loading of quote.txt resource f = open(adjust_filename('quoteEnUS.txt', __file__), "r") orig = f.read() f.close() f = QFile(':/quote.txt') f.open(QIODevice.ReadOnly) #|QIODevice.Text) print("Error:", f.errorString()) copy = f.readAll() f.close() self.assertEqual(orig, copy)
def load_ui(self): #load the main screen path = os.path.join(os.path.dirname(__file__), "form.ui") print(path) ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self.win = loader.load(ui_file, self) #self.add_menu_theme(self.win, self.win.menuStyles) self.center() #win.show() ui_file.close()
def testImage(self): #Test loading of sample.png resource f = open(adjust_filename('sample.png', __file__), "rb") orig = f.read() f.close() f = QFile(':/sample.png') f.open(QIODevice.ReadOnly) copy = f.readAll() f.close() self.assertEqual(len(orig), len(copy)) self.assertEqual(orig, copy)
def restoreLayout(self): if os.path.isfile(get_config_path("layout.dat")): try: f=open(get_config_path("layout.dat"), 'rb') geometry, state=pickle.load(f) self.restoreGeometry(geometry) self.restoreState(state) except Exception as e: print("Exception on restoreLayout, {}".format(e)) else: try: f=QFile(':/default_layout.dat') f.open(QIODevice.ReadOnly) geometry, state=pickle.loads(f.readAll()) self.restoreGeometry(geometry) self.restoreState(state) except Exception as e: print("Exception on restoreLayout, {}".format(e))
def setupUi(self, Form): path = f"{os.path.dirname(__file__)}/new_gui.ui" ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self._window = loader.load(ui_file) # Need to fix this courses list view self._window.coursesView = CoursesListView(self._window.courses_tab) self._window.courses_layout.addWidget(self._window.coursesView) self._window.coursesView.setObjectName("coursesView") self._window.coursesView2.deleteLater() self.icon = QIcon(":/icons/uglytheme/polibeepsync.svg") self.retranslateUi(self._window) self._window.tabWidget.setCurrentIndex(0) QMetaObject.connectSlotsByName(self._window)
def saveFile(self, fileName): file = QFile(fileName) if not file.open(QFile.WriteOnly | QFile.Text): QMessageBox.warning(self, "MDI", "Cannot write file %s:\n%s." % (fileName, file.errorString())) return False outstr = QTextStream(file) QApplication.setOverrideCursor(Qt.WaitCursor) outstr << self.toPlainText() QApplication.restoreOverrideCursor() self.setCurrentFile(fileName) return True
def loadFile(self, fileName): file = QFile(fileName) if not file.open(QFile.ReadOnly | QFile.Text): QMessageBox.warning(self, "MDI", "Cannot read file %s:\n%s." % (fileName, file.errorString())) return False instr = QTextStream(file) QApplication.setOverrideCursor(Qt.WaitCursor) self.setPlainText(instr.readAll()) QApplication.restoreOverrideCursor() self.setCurrentFile(fileName) self.document().contentsChanged.connect(self.documentWasModified) return True
def testHuge(self): handle = QFile(":manychars.txt") handle.open(QFile.ReadOnly) original = open(os.path.join(self.testdir, "manychars.txt"), "r") self.assertEqual(handle.readLine(), original.readline())
def testSimple(self): handle = QFile(":words.txt") handle.open(QFile.ReadOnly) original = open(os.path.join(self.testdir, "words.txt"), "r") self.assertEqual(handle.readLine(), original.readline())
def testAlias(self): handle = QFile(":jack") handle.open(QFile.ReadOnly) original = open(os.path.join(self.testdir, "shining.txt"), "r") self.assertEqual(handle.readLine(), original.readline())
# directly_loading_QML import sys from PySide2.QtUiTools import QUiLoader from PySide2.QtWidgets import QApplication from PySide2.QtCore import QFile if __name__ == '__main__': app = QApplication(sys.argv) ui_file=QFile('./mainwindow.ui') ui_file.open(QFile.ReadOnly) loader = QUiLoader() window = loader.load(ui_file) ui_file.close() window.show() sys.exit(app.exec_())