def initializeInstance(self): # Remove BlissFramework application lockfile #self.guiConfiguration=qt.qApp.mainWidget().configuration if qt_variant == 'PyQt5': from PyQt5.QtWidgets import QApplication for widget in QApplication.allWidgets(): if hasattr(widget, "configuration"): self.guiConfiguration = widget.configuration break elif qt_variant == 'PyQt4': from PyQt4.QtGui import QApplication for widget in QApplication.allWidgets(): if hasattr(widget, "configuration"): self.guiConfiguration = widget.configuration break else: from qt import qApp self.guiConfiguration = qApp.mainWidget().configuration lockfilename = os.path.join(tempfile.gettempdir(), '.%s.lock' % BlissFramework.loggingName) try: os.unlink(lockfilename) except: pass self.emit('instanceInitializing', ()) if self.isLocal(): self.startServer() else: self.connectToServer()
def initializeInstance(self): # Remove BlissFramework application lockfile #self.guiConfiguration=qt.qApp.mainWidget().configuration if qt_variant == 'PyQt5': from PyQt5.QtWidgets import QApplication for widget in QApplication.allWidgets(): if hasattr(widget, "configuration"): self.guiConfiguration = widget.configuration break elif qt_variant == 'PyQt4': from PyQt4.QtGui import QApplication for widget in QApplication.allWidgets(): if hasattr(widget, "configuration"): self.guiConfiguration = widget.configuration break else: from qt import qApp self.guiConfiguration = qApp.mainWidget().configuration lockfilename=os.path.join(tempfile.gettempdir(), '.%s.lock' % BlissFramework.loggingName) try: os.unlink(lockfilename) except: pass self.emit('instanceInitializing', ()) if self.isLocal(): self.startServer() else: self.connectToServer()
def clearAll(self): for widget in QApplication.allWidgets(): if widget.__class__ is QtWidgets.QLineEdit: widget.clear() self.chkGraduate.setChecked(False) self.cboCollege.setCurrentIndex(0) self.btnSave.setDisabled(True) self.btnLoad.setDisabled(False)
def get_button_by_name(name, parentType=None): # Try 3 times for i in range(3): for widget in QApplication.allWidgets(): if isinstance(widget, QPushButton): if widget.text() == name: if parentType: if isinstance(widget.parent(), parentType): return widget else: return widget return None
def tick(self): all_widgets = QApplication.allWidgets() new_tasks = [] for task in self.tasks: res = task(all_widgets) if not res: new_tasks.append(task) self.tasks = new_tasks for widget in all_widgets: if isinstance(widget, QMessageBox) and not isinstance(widget, Dialog): widget.close()
def __init__(self, parent=None): super(Consumer, self).__init__(parent) self.setupUi(self) self.btnSave.setDisabled(True) self.btnClear.clicked.connect(self.clearAll) for widget in QApplication.allWidgets(): if widget.__class__ is QtWidgets.QLineEdit: widget.textChanged.connect(self.dataEntry) self.cboCollege.currentIndexChanged.connect(self.dataEntry) self.chkGraduate.stateChanged.connect(self.dataEntry) self.btnSave.clicked.connect(self.dataSave) self.btnLoad.clicked.connect(self.loadData)
def dataSave(self): grad = "false" if self.chkGraduate.isChecked() is True: grad = "true" name_dic = {} c_list = [] for widget in QApplication.allWidgets(): if widget.__class__ is QtWidgets.QLineEdit: name_dic[widget.objectName()] = widget.text() #pp(name_dic) for index in range(1, 20): c_name = "txtComponentName_" + str(index) c_count = "txtComponentCount_" + str(index) if name_dic[c_name]: c_list.append('<Component name="' + name_dic[c_name] + '" count="' + name_dic[c_count] + '" />') content = "" for record in c_list: content += "\t\t" + record + "\n" content = content[:len(content) - 1] #pp(content) data = { 'name': self.txtStudentName.text(), 'ID': self.txtStudentID.text(), "gradStatus": grad, "college": self.cboCollege.currentText(), "content": content } template = """<?xml version="1.0" encoding="UTF-8"?> <Content> <StudentName graduate="%(gradStatus)s">%(name)s</StudentName> <StudentID>%(ID)s</StudentID> <College>%(college)s</College> <Components> %(content)s </Components> </Content>""" with open("target.xml", "w") as f: f.write(template % data)
def loadDataFromFile(self, filePath): """ Handles the loading of the data from the given file name. This method will be invoked by the 'loadData' method. *** YOU MUST USE THIS METHOD TO LOAD DATA FILES. *** *** This method is required for unit tests! *** """ with open(filePath, "r") as f: contents = f.read().replace("\n", "") p_name = r'<StudentName graduate="(?P<graduate>[\w]+)">(?P<name>[\w\W]+)</StudentName>' match = re.search(p_name, contents) self.txtStudentName.setText(match["name"]) if match["graduate"] == "true": self.chkGraduate.setChecked(True) else: self.chkGraduate.setChecked(False) p_ID = r'<StudentID>(?P<ID>[\w\W]+)</StudentID>' match = re.search(p_ID, contents) self.txtStudentID.setText(match["ID"]) p_college = r'<College>(?P<college>[\w ]+)</College>' match = re.search(p_college, contents) self.cboCollege.setCurrentText(match["college"]) p_comp = r'<Component name="(?P<comp_name>[^"]+)" count="(?P<comp_count>[\d]+)" />' match = re.findall(p_comp, contents) length = 20 if len(match) < 20: length = len(match) for index in range(length): c_name = "txtComponentName_" + str(index + 1) c_count = "txtComponentCount_" + str(index + 1) for widget in QApplication.allWidgets(): if widget.objectName() == c_name: widget.setText(match[index][0]) elif widget.objectName() == c_count: widget.setText(match[index][1]) pass
from PyQt5.QtCore import QSettings, QStandardPaths from PyQt5.QtGui import QPixmap from PyQt5.QtWidgets import QApplication, QSplashScreen import os try: s = QSettings() s.setValue("PythonPlugins/GeoTaskOrganizer", True) s.setValue("qgis/iconSize", 32) s.setValue("qgis/stylesheet/iconSize", 32) s.setValue("qgis/stylesheet/fontPointSize", 12) except: pass try: widgets = QApplication.allWidgets() for wid in widgets: if isinstance(wid, QSplashScreen): qgisAppDataPath = QStandardPaths.standardLocations(QStandardPaths.AppDataLocation)[0] file = os.path.join(qgisAppDataPath, "splash.png") if os.path.isfile(file): pixmap = QPixmap(file) wid.setPixmap(pixmap) break except: pass
QQ: 892768447 Email: [email protected]""" __Copyright__ = "Copyright (c) 2019 Irony" __Version__ = "Version 1.0" class Window(QWidget): def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) c = win32gui.LoadImage(None, os.path.abspath('cursor.ani'), win32con.IMAGE_CURSOR, 0, 0, win32con.LR_LOADFROMFILE) print(c) win32api.SetClassLong(int(self.winId()), win32con.GCL_HCURSOR, c) if __name__ == '__main__': import sys app = QApplication(sys.argv) w = Window() w.show() print(app.topLevelWindows()) print(int(app.topLevelWindows()[0].winId()), int(w.winId())) print(app.focusWidget()) print(app.focusWindow()) print(app.allWidgets()) print(app.allWindows()) app.setActiveWindow(w) print(app.activeWindow()) sys.exit(app.exec_())