我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtWidgets.QMainWindow()。
def setupWin(self): super(self.__class__,self).setupWin() self.setGeometry(500, 300, 250, 110) # self.resize(250,250) #------------------------------ # template list: for frameless or always on top option #------------------------------ # - template : keep ui always on top of all; # While in Maya, dont set Maya as its parent ''' self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) ''' # - template: hide ui border frame; # While in Maya, use QDialog instead, as QMainWindow will make it disappear ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint) ''' # - template: best solution for Maya QDialog without parent, for always on-Top frameless ui ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) ''' # - template: for transparent and non-regular shape ui # note: use it if you set main ui to transparent, and want to use alpha png as irregular shape window # note: black color better than white for better look of semi trans edge, like pre-mutiply ''' self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setStyleSheet("background-color: rgba(0, 0, 0,0);") '''
def main(): app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = DottorrentGUI() ui.setupUi(MainWindow) MainWindow.resize(500, 0) MainWindow.setGeometry( QtWidgets.QStyle.alignedRect( QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter, MainWindow.size(), app.desktop().availableGeometry() ) ) MainWindow.setWindowTitle(PROGRAM_NAME_VERSION) ui.loadSettings() ui.clipboard = app.clipboard app.aboutToQuit.connect(lambda: ui.saveSettings()) MainWindow.show() sys.exit(app.exec_())
def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) self.limit_button.clicked.connect(self.limittfunc) self.diffButton_normal.clicked.connect(self.diff_normal) self.diffButton_complex.clicked.connect(self.diff_complex) self.integralButton_normal.clicked.connect(self.integral_normal) self.integralButton_complex.clicked.connect(self.integral_complex) self.allCalculator.clicked.connect(self.allcalc) self.binomialButton.clicked.connect(self.binomialfunc) self.solver_button.clicked.connect(self.solver) self.sumButton.clicked.connect(self.sumfunc) self.factorButton.clicked.connect(self.factorfunc) self.fourierButton.clicked.connect(self.fourier) self.integralButton_copy.clicked.connect(self.copy) self.integralButton_copy_3.clicked.connect(self.copy) self.integralButton_copy_9.clicked.connect(self.copy) self.integralButton_copy_10.clicked.connect(self.copy) self.integralButton_copy_11.clicked.connect(self.copy) self.integralButton_copy_12.clicked.connect(self.copy) self.integralButton_copy_13.clicked.connect(self.copy) self.integralButton_copy_2.clicked.connect(self.copy) self.integralButton_copy_4.clicked.connect(self.copy)
def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) self.__register__ = None self.__attendance____ = None self.btn_Register.clicked.connect(self.Register) self.btn_Attendance.clicked.connect(self.Attendance) self.btnSearch.clicked.connect(self.Search) self.report_date.setDate(QtCore.QDate.currentDate()) cursor = connection.cursor() sql = "Select * from attendance" cursor.execute(sql) result = cursor.fetchall() rows = len(result) if rows <= 0: QMessageBox.about(self, "No Data", "No Attendance has been recorded yet") else: self.tableWidget.setRowCount(rows) self.tableWidget.setColumnCount(3) header_labels = ['Matric Number', 'Date', 'Status'] self.tableWidget.setHorizontalHeaderLabels(header_labels) for count in range(0, rows): self.tableWidget.setItem(count, 0, QTableWidgetItem(str(result[count]["matric_num"].encode('ascii', 'ignore')))) self.tableWidget.setItem(count, 1, QTableWidgetItem(result[count]["dte"].encode('ascii', 'ignore'))) self.tableWidget.setItem(count, 2, QTableWidgetItem(result[count]["status"].encode('ascii', 'ignore')))
def __init__(self): QtWidgets.QMainWindow.__init__(self) self.ui = uic.loadUi(l('cmd.ui'), self) self.ui.show() self.plainTextEdit.appendPlainText("Microsoft Windows (Version 10.0.10240)") self.plainTextEdit.appendPlainText("(c) 2015 Microsoft Corporation. All rights reserved. \n") self.plainTextEdit.appendPlainText("C:\\> ") self.plainTextEdit.installEventFilter(self) self.editable = True self.keys = [] self.lolnope = []
def main(): app = QApplication(sys.argv) w = QMainWindow() central_widget = CentralWidget() my_widgets = [ (GoalWidget('one', '5'), 1, 1), (GoalWidget('two', '2'), 1, 2), (GoalWidget('An example of goal\nwith a long name', '3'), 2, 2), (GoalWidget('four', '1'), 2, 3), (GoalWidget('five', '4'), 3, 2), ] my_lines = [ (0, 2), (1, 2), (2, 4), (3, 4), ] for widget, row, column in my_widgets: central_widget.addCustomWidget(widget, row, column) for upper, lower in my_lines: central_widget.addCustomLine(upper, lower) w.setCentralWidget(central_widget) w.show() sys.exit(app.exec_())
def _setup_ui(self): geometry = ConfigFile.GEOMETRY x = Configuration().parser.getint(geometry, 'x', fallback=480) y = Configuration().parser.getint(geometry, 'y', fallback=320) width = Configuration().parser.getint(geometry, 'width', fallback=880) height = Configuration().parser.getint(geometry, 'height', fallback=474) self.setMinimumSize(QtCore.QSize(480, 320)) self.setGeometry(x, y, 480, 320) self.setWindowIcon(QtGui.QIcon(config.ICON)) self.set_title() self.resize(width, height) self.setLayoutDirection(QtCore.Qt.LeftToRight) self.setDockNestingEnabled(False) self.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks | QtWidgets.QMainWindow.AnimatedDocks | QtWidgets.QMainWindow.ForceTabbedDocks)
def rewind(self): if not cfg[CONFIG_BUFFER_STREAM]: QtWidgets.QMessageBox().warning( self, "Warning", "Cannot Rewind. You currently have buffering turned off." ) return if self.rewound is None: self.rewound = QtWidgets.QMainWindow(parent=self) self.rewound.setWindowTitle("Rewound Stream") self.rewound.resize(QtWidgets.QDesktopWidget().availableGeometry(-1).size() * 0.5) self.rewound.frame = RewoundVideoFrame(self.rewound, self.stream.buffer) # Set events: self.rewound.closeEvent = self.close_rewound self.rewound.frame._fullscreen = self.fullscreen_rewound self.rewound.setCentralWidget(self.rewound.frame) self.rewound.show() # Init values self.rewound.is_fullscreen = False # Following functions belong to the rewound window
def qui_menubar(self, menu_list_str): if not isinstance(self, QtWidgets.QMainWindow): print("Warning: Only QMainWindow can have menu bar.") return menubar = self.menuBar() create_opt_list = [ x.strip() for x in menu_list_str.split('|') ] for each_creation in create_opt_list: ui_info = [ x.strip() for x in each_creation.split(';') ] menu_name = ui_info[0] menu_title = '' if len(ui_info) > 1: menu_title = ui_info[1] if menu_name not in self.uiList.keys(): self.uiList[menu_name] = QtWidgets.QMenu(menu_title) menubar.addMenu(self.uiList[menu_name]) # compatible hold function
def main(*filenames: 'Files to open immediately'): """Start the Solar Sails GUI.""" app = App(sys.argv) midi.load() midi.listener.update_ports() midi.listener.start_port_listener('Metrasynth Solar Sails', virtual=True) app.aboutToQuit.connect(midi.listener.stop) loop = QEventLoop(app) asyncio.set_event_loop(loop) main_window = QMainWindow() main_window.setMenuBar(MainMenuBar()) welcome_widget = WelcomeWidget(main_window) main_window.setCentralWidget(welcome_widget) main_window.show() for filename in filenames: window = Opener.open_file(filename) if window: window.show() window.setFocus(True) loop.run_forever()
def _readAndApplyWindowAttributeSettings(self): ''' Read window attributes from settings, using current attributes as defaults (if settings not exist.) Called at QMainWindow initialization, before show(). ''' self.settings.beginGroup("mainWindow") # No need for toPoint, etc. : PySide converts types try: self.MainWindow.move(self.settings.value("pos")) if self.settings.value("maximized") in 'true': self.MainWindow.showMaximized() else: self.MainWindow.resize(self.settings.value("size")) except: pass self.settings.endGroup()
def __init__(self): self.receivingQueue = Utils.globals.receivingQueue self.sendingQueue = Utils.globals.sendingQueue self.app = QtWidgets.QApplication(sys.argv) self.MainWindow = QtWidgets.QMainWindow() self.ui = Ui_MainWindow() self.stack = Stack() # Start UI self.ui.setupUi(self.MainWindow) # Init components self.init_components() UI_updater(self.ui).start() # CLose UI self.MainWindow.show() sys.exit(self.app.exec_()) # define the actions when event triggered by the UI
def __init__(self): self.app = QApplication(sys.argv) self.mainWindow = QMainWindow() self.ui = Ui_MainWindow() self.ui.setupUi(self.mainWindow) self.Dialog = QtWidgets.QDialog() self.ui2 = Ui_Form() self.ui2.setupUi(self.Dialog) self.ui.textEdit.setReadOnly(True) self.clipboard = QApplication.clipboard() self.clipboard.selectionChanged.connect(self.fanyi) self.mainWindow.setWindowTitle("????") self.mainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) self.ui2.lineEdit.editingFinished.connect(self.callInput) self.Dialog.moveEvent = self.mainMove self.wordutil = wordutil() self.time = time.time() self.ui.textEdit.mouseDoubleClickEvent = self.inputText
def init_gui(): """ Tries to find the main Binja window. If we've already found it, does nothing. Call this as many times as you want, just in case. """ global main_window if main_window is None: app = QApplication.instance() main_window = [x for x in app.allWidgets() if x.__class__ is QMainWindow][0]
def __init__(self): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.__dashboard__ = None self.setupUi(self) self.btn_exit.clicked.connect(self.Exit) self.btn_login.clicked.connect(self.Login)
def __init__(self): QtWidgets.QMainWindow.__init__(self) self.__get_face__ = None Ui_MainWindow.__init__(self) self.setupUi(self) self.btn_train_classifier.clicked.connect(self.classifier) self.dte_dob.setDate(QtCore.QDate.currentDate())
def __init__(self, parent=None): QtWidgets.QMainWindow.__init__(self, parent) self.model = ReorderableListModel() self.selectionModel = SelectionModel(self.model) self.model.dragDropFinished.connect(self.selectionModel.onModelItemsReordered) self.view = QtWidgets.QListView() self.view.setModel(self.model) self.view.setSelectionModel(self.selectionModel) self.view.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove) self.view.setDragDropOverwriteMode(False) self.setCentralWidget(self.view)
def __init__(self): QtWidgets.QMainWindow.__init__(self) self.ui = uic.loadUi(l('mainwindow.ui'), self) self.ui.show() self.ui.runIcon.pixmap = l("run_37198.jpg") self.okButton.clicked.connect(self.run) self.commandBox.lineEdit().returnPressed.connect(self.run) self.commandBox.setFocus()
def __init__(self, hostname=None, status_port=7771, data_port=7772): QtWidgets.QMainWindow.__init__(self) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle("Auspex Plotting") self.file_menu = self.menuBar().addMenu('&File') self.file_menu.addAction('&Quit', self.fileQuit, QtCore.Qt.CTRL + QtCore.Qt.Key_Q) self.file_menu.addAction('&Open', self.open_connection_dialog, QtCore.Qt.CTRL + QtCore.Qt.Key_O) self.file_menu.addAction('&Open Localhost', lambda: self.open_connection("localhost"), QtCore.Qt.SHIFT + QtCore.Qt.CTRL + QtCore.Qt.Key_O) self.recent = self.file_menu.addMenu("Open Recent") self.main_widget = QtWidgets.QWidget(self) self.main_widget.setMinimumWidth(800) self.main_widget.setMinimumHeight(600) self.layout = QtWidgets.QVBoxLayout(self.main_widget) self.main_widget.setFocus() self.setCentralWidget(self.main_widget) self.context = zmq.Context() self.listener_thread = None if hostname: self.open_connection(hostname, status_port, data_port)
def keyPressEvent(self, event): """Qt callback for key presses. This overrides the `QMainWindow` method. It does not need to be called directly and it doesn't need to be overriden. Connect to the :meth:`key_pressed` transmitter to handle key press events. """ try: key = key_map[event.key()] except KeyError: return super().keyPressEvent(event) self.key_pressed(key)
def __init__(self, renderer, title): QApplication.__init__(self, sys.argv) self.window = QMainWindow() self.window.setWindowTitle(title) self.window.resize(800,600) # Get OpenGL 4.1 context glformat = QGLFormat() glformat.setVersion(4, 1) glformat.setProfile(QGLFormat.CoreProfile) glformat.setDoubleBuffer(False) self.glwidget = MyGlWidget(renderer, glformat, self) self.window.setCentralWidget(self.glwidget) self.window.show()
def __init__(self, parent = None): QtWidgets.QMainWindow.__init__(self, parent) self.setWindowFlags(QtCore.Qt.Widget)
def __init__(self, parent=None): QtWidgets.QMainWindow.__init__(self, parent) self.setupUi(self) self.btn_video.clicked.connect(self.start_video_clicked) self.btn_autofocus.setEnabled(False) self.push_zero.clicked.connect(self.zero_clicked) self.push_zero.setEnabled(False) self.btn_connect.clicked.connect(self.btn_connect_clicked) self.btn_autofocus.clicked.connect(self.btn_autofocus_clicked) self.dial_2.valueChanged.connect(self.adjust_1) self.dial_1.valueChanged.connect(self.adjust_2) self.group_controls.setEnabled(False) self.dial_2.setMaximum(max_1) self.dial_1.setMaximum(max_2) # setup video timer and widget w = self.widget_video.width() h = self.widget_video.height() self.widget_video = OwnImageWidget(self.widget_video) self.widget_video.resize(w, h) # setup update frame thread self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.update_frame) self.timer.start(1) # setup com port comunication self.combo_ports.clear() com_ports = sorted(comports()) for port, desc, hwid in com_ports: self.combo_ports.addItem(port) self.timer1 = QtCore.QTimer(self) self.timer1.timeout.connect(self.update_pos) self.timer1.start(1)
def __init__(self, parent=None): QtWidgets.QMainWindow.__init__(self, parent) self.setupUi(self) self.btn_video.clicked.connect(self.start_video_clicked) self.btn_autofocus.setEnabled(False) self.push_zero.clicked.connect(self.zero_clicked) self.push_zero.setEnabled(False) self.btn_connect.clicked.connect(self.btn_connect_clicked) self.btn_autofocus.clicked.connect(self.btn_autofocus_clicked) self.dial_1.valueChanged.connect(self.adjust_1) self.dial_2.valueChanged.connect(self.adjust_2) self.group_controls.setEnabled(False) self.dial_1.setMaximum(max_1) self.dial_2.setMaximum(max_2) # setup video timer and widget w = self.widget_video.width() h = self.widget_video.height() self.widget_video = OwnImageWidget(self.widget_video) self.widget_video.resize(w, h) # setup update frame thread self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.update_frame) self.timer.start(1) # setup com port comunication self.combo_ports.clear() com_ports = sorted(comports()) for port, desc, hwid in com_ports: self.combo_ports.addItem(port) self.timer1 = QtCore.QTimer(self) self.timer1.timeout.connect(self.update_pos) self.timer1.start(1)
def new_project(self) -> QtWidgets.QMainWindow: new_window = True dialog = CreateProject() if dialog.exec_(): self.log.info("Creating new project") project = dialog.project if new_window: self.log.debug("Opening project in new window") return MainWindow(project) else: self.project = project self.project.save() self.update_project() # TODO: This will eventually require a dialog to allow selection of project type
def __init__(self): super().__init__() uic.loadUi('ui/main_window.ui', self) # The QListWidget item currently selected. self.selected = None # The nickname of th currently selected note. self.selected_nickname = None # Timer used to add a delay when selecting a note. self.timer = None # The secondary window currently opened. It' here to force having only # one window opened at a time. self.win = None # The mail window. This is needed to store the mail window which cannot # be used as a usual secondary window as it's a QMainWindow instead # of a QDiaload. A QMainWindow is required in order to have a menubar self.mail_window = None # Hack to count ecocups to add/delete. self.eco_diff = 0 # Build the notes_list self.rebuild_notes_list() # Set product list header width self.product_list.setColumnWidth(0, 30) self.product_list.setColumnWidth(1, 128) self.product_list.setColumnWidth(2, 40) # Set the headers of the history in the note details. self.note_history.header().setStretchLastSection(False) self.note_history.header().setSectionResizeMode( 2, QtWidgets.QHeaderView.Stretch ) self.check_alcohol()
def __init__(self, *__args): super(BinjaDockWidget, self).__init__(*__args) self._app = QtWidgets.QApplication.instance() self._main_window = [x for x in self._app.allWidgets() if x.__class__ is QtWidgets.QMainWindow][0] self._tool_menu = [x for x in self._main_window.menuWidget().children() if x.__class__ is QtWidgets.QMenu and x.title() == u'&Tools'][0] self._main_window.addDockWidget(Qt.RightDockWidgetArea, self) self._tabs = QtWidgets.QTabWidget() self._tabs.setTabPosition(QtWidgets.QTabWidget.East) self.setWidget(self._tabs) self.addToolMenuAction('Toggle plugin dock', self.toggle) self.hide()
def instance(): app = QtWidgets.QApplication.instance() main_window = [x for x in app.allWidgets() if x.__class__ is QtWidgets.QMainWindow][0] try: dock = [x for x in main_window.children() if x.__class__ is BinjaDockWidget][0] except: dock = BinjaDockWidget() return dock
def __init__(self, appname, cmd): QtWidgets.QMainWindow.__init__(self) vq_hotkeys.HotKeyMixin.__init__(self) self._vq_appname = appname self._vq_dockwidgets = [] self._vq_settings = QtCore.QSettings('invisigoth', application=appname, parent=self) self._vq_histfile = os.path.join(os.path.expanduser('~'), '.%s_history' % appname) self._dock_classes = {} self.vqInitDockWidgetClasses() self._vq_mbar = vq_menu.VQMenuBar() self.setMenuBar(self._vq_mbar) # AnimatedDocks, AllowNestedDocks, AllowTabbedDocks, ForceTabbedDocks, VerticalTabs self.setDockOptions(self.AnimatedDocks | self.AllowTabbedDocks) self._vq_cli = self.__cli_widget_class__(cmd) self._vq_cli.input.loadHistory(self._vq_histfile) self._vq_cli.sigCliQuit.connect(self.close) self.setCentralWidget(self._vq_cli) self.vqRestoreGuiSettings(self._vq_settings)
def __init__(self, args): QtWidgets.QMainWindow.__init__(self) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle("application main window") self.file_menu = QtWidgets.QMenu('&File', self) self.file_menu.addAction('&Quit', self.file_quit, QtCore.Qt.CTRL + QtCore.Qt.Key_Q) self.menuBar().addMenu(self.file_menu) self.help_menu = QtWidgets.QMenu('&Help', self) self.menuBar().addSeparator() self.menuBar().addMenu(self.help_menu) self.help_menu.addAction('&About', self.about) self.main_widget = QtWidgets.QWidget(self) layout = QtWidgets.QVBoxLayout(self.main_widget) qicanvas = QICanvas(args, self.main_widget, width=5, height=4, dpi=100) layout.addWidget(qicanvas) self.main_widget.setFocus() self.setCentralWidget(self.main_widget) self.statusBar().showMessage("QIView", 2000)
def main(): """ Application entry point """ logging.basicConfig(level=logging.DEBUG) # create the application and the main window app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() # setup ui ui = example_ui.Ui_MainWindow() ui.setupUi(window) ui.bt_delay_popup.addActions([ ui.actionAction, ui.actionAction_C ]) ui.bt_instant_popup.addActions([ ui.actionAction, ui.actionAction_C ]) ui.bt_menu_button_popup.addActions([ ui.actionAction, ui.actionAction_C ]) window.setWindowTitle("QDarkStyle example") # tabify dock widgets to show bug #6 window.tabifyDockWidget(ui.dockWidget1, ui.dockWidget2) # setup stylesheet app.setStyleSheet(PyQt5_stylesheets.load_stylesheet_pyqt5(style="style_black")) # auto quit after 2s when testing on travis-ci if "--travis" in sys.argv: QtCore.QTimer.singleShot(2000, app.exit) # run window.show() app.exec_()
def Logout(self): import bb_downloader_loginUi as loginUi self.MainWindow.close() self.LoginWindow = QtWidgets.QMainWindow() self.ui = loginUi.Ui_LoginWindow() self.ui.setupUi(self.LoginWindow) self.LoginWindow.show()
def end(self): self.MainWindow = QtWidgets.QMainWindow() self.ui = mainUi.Ui_MainWindow() self.ui.setupUi(self.MainWindow, self.account) self.MainWindow.show() self.WaitingWindow.accept() NotifyWindow = QtWidgets.QMessageBox(self.MainWindow) NotifyWindow.setWindowTitle("?? ??!") NotifyWindow.setText("??? ?? ??????.") NotifyWindow.setStandardButtons(QtWidgets.QMessageBox.Ok) NotifyWindow.setIcon(QtWidgets.QMessageBox.Information) NotifyWindow.show() self.LoginWindow.close()
def __init__(self, parent=None, mode=0): UniversalToolUI.__init__(self, parent) # class variables self.version= version self.date = date self.log = log self.help = help # mode: example for receive extra user input as parameter self.mode = 0 if mode in [0,1]: self.mode = mode # mode validator # Custom user variable #------------------------------ # initial data #------------------------------ self.memoData['data']=[] self.qui_user_dict = {} # e.g: 'edit': 'LNTextEdit', self.setupStyle() if isinstance(self, QtWidgets.QMainWindow): self.setupMenu() self.setupWin() self.setupUI() self.Establish_Connections() self.loadLang() self.loadData() #------------------------------ # overwrite functions #------------------------------
def __init__(self, parent=None, mode=0): super_class.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version="2.0" self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.fileType='.UITranslator_EXT' # mode: example for receive extra user input as parameter self.mode = 0 if mode in [0,1]: self.mode = mode # mode validator self.location = "" if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(__file__) # location: ref: sys.modules[__name__].__file__ # Custom variable #------------------------------ # initial data #------------------------------ self.memoData['data']=[] self.setupStyle() if isinstance(self, QtWidgets.QMainWindow): self.setupMenu() # only if you use QMainWindows Class self.setupWin() self.setupUI() self.Establish_Connections() self.loadData() self.loadLang()
def quickMenu(self, ui_names): if isinstance(self, QtWidgets.QMainWindow): menubar = self.menuBar() for each_ui in ui_names: createOpt = each_ui.split(';') if len(createOpt) > 1: uiName = createOpt[0] uiLabel = createOpt[1] self.uiList[uiName] = QtWidgets.QMenu(uiLabel) menubar.addMenu(self.uiList[uiName]) else: print("Warning (QuickMenu): Only QMainWindow can have menu bar.")
def setupUI(self, layout='grid'): #------------------------------ # main_layout auto creation for holding all the UI elements #------------------------------ main_layout = None if isinstance(self, QtWidgets.QMainWindow): main_widget = QtWidgets.QWidget() self.setCentralWidget(main_widget) main_layout = self.quickLayout(layout, 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) else: # main_layout for QDialog main_layout = self.quickLayout(layout, 'main_layout') self.setLayout(main_layout)
def quickMenu(self, ui_names): if not isinstance(ui_names, (list, tuple)): # support qui format menu creation ui_names = [ x.strip() for x in ui_names.split('|') ] if isinstance(self, QtWidgets.QMainWindow): menubar = self.menuBar() for each_ui in ui_names: createOpt = each_ui.split(';') if len(createOpt) > 1: uiName = createOpt[0] uiLabel = createOpt[1] self.uiList[uiName] = QtWidgets.QMenu(uiLabel) menubar.addMenu(self.uiList[uiName]) else: print("Warning (QuickMenu): Only QMainWindow can have menu bar.")
def __init__(self, parent=None, mode=0): UniversalToolUI.__init__(self, parent) # class variables self.version="0.1" self.help = "(UserClassUI)How to Use:\n1. Put source info in\n2. Click Process button\n3. Check result output\n4. Save memory info into a file." # mode: example for receive extra user input as parameter self.mode = 0 if mode in [0,1]: self.mode = mode # mode validator # Custom user variable #------------------------------ # initial data #------------------------------ self.memoData['data']=[] self.qui_user_dict = {} # e.g: 'edit': 'LNTextEdit', self.setupStyle() if isinstance(self, QtWidgets.QMainWindow): self.setupMenu() self.setupWin() self.setupUI() self.Establish_Connections() self.loadData() self.loadLang() #------------------------------ # overwrite functions #------------------------------
def __init__(self, parent=None, mode=0): super_class.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version="0.1" self.help = "How to Use:\n1. Put source info in\n2. Click Process button\n3. Check result output\n4. Save memory info into a file." self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.location = "" if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(__file__) # location: ref: sys.modules[__name__].__file__ self.name = self.__class__.__name__ self.iconPath = os.path.join(os.path.dirname(self.location),'icons',self.name+'.png') self.iconPix = QtGui.QPixmap(self.iconPath) self.icon = QtGui.QIcon(self.iconPath) self.fileType='.{0}_EXT'.format(self.name) # Custom user variable #------------------------------ # initial data #------------------------------ self.memoData['data']=[] self.setupStyle() if isinstance(self, QtWidgets.QMainWindow): self.setupMenu() self.setupWin() self.setupUI() self.Establish_Connections() self.loadData() self.loadLang()
def setupWin(self): self.setWindowTitle(self.name + " - v" + self.version + " - host: " + hostMode) self.setWindowIcon(self.icon) # initial win drag position self.drag_position=QtGui.QCursor.pos() self.setGeometry(500, 300, 250, 110) # self.resize(250,250) #------------------------------ # template list: for frameless or always on top option #------------------------------ # - template : keep ui always on top of all; # While in Maya, dont set Maya as its parent ''' self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) ''' # - template: hide ui border frame; # While in Maya, use QDialog instead, as QMainWindow will make it disappear ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint) ''' # - template: best solution for Maya QDialog without parent, for always on-Top frameless ui ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) ''' # - template: for transparent and non-regular shape ui # note: use it if you set main ui to transparent, and want to use alpha png as irregular shape window # note: black color better than white for better look of semi trans edge, like pre-mutiply ''' self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setStyleSheet("background-color: rgba(0, 0, 0,0);") ''' ############################################# # customized SUPER quick ui function for speed up programming #############################################
def __init__(self, parent=None, mode=0): UniversalToolUI.__init__(self, parent) # class variables self.version="0.1" self.help = "(UserClassUI)How to Use:\n1. Put source info in\n2. Click Process button\n3. Check result output\n4. Save memory info into a file." # mode: example for receive extra user input as parameter self.mode = 0 if mode in [0,1]: self.mode = mode # mode validator # Custom user variable #------------------------------ # initial data #------------------------------ self.memoData['data']=[] self.setupStyle() if isinstance(self, QtWidgets.QMainWindow): self.setupMenu() self.setupWin() self.setupUI() self.Establish_Connections() self.loadData() self.loadLang() #------------------------------ # overwrite functions #------------------------------