我们从Python开源项目中,提取了以下46个代码示例,用于说明如何使用PySide.QtGui.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 __build_main_window(self): """ Builds the QML interface """ self.mainwindow = QtGui.QMainWindow() self.mainview = QtDeclarative.QDeclarativeView() if OPENGL: glw = QtOpenGL.QGLWidget() self.mainview.setViewport(glw) self.mainview.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView) self.engine = self.mainview.engine() self.engine.rootContext().setBaseUrl(QtCore.QUrl.fromLocalFile( os.path.join(ROOT_DIR, "guiQML"))) #set up the family tree list to select from self.dbman = DbManager(self.dbstate, self.engine, self.load_db)
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 setupWin(self): self.setWindowTitle("UITranslator" + " - v" + self.version) self.setGeometry(300, 300, 300, 300) # win icon setup path = os.path.join(os.path.dirname(self.location),'icons','UITranslator.png') self.setWindowIcon(QtGui.QIcon(path)) # initial win drag position self.drag_position=QtGui.QCursor.pos() #self.resize(250,250) # - for frameless or always on top option #self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # it will keep ui always on top of desktop, but to set this in Maya, dont set Maya as its parent #self.setWindowFlags(QtCore.Qt.FramelessWindowHint) # it will hide ui border frame, but in Maya, use QDialog instead as QMainWindow will disappear #self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) # best for Maya case with QDialog without parent, for always top frameless ui # - for transparent and non-regular shape ui #self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # use it if you set main ui to transparent and want to use alpha png as irregular shape window #self.setStyleSheet("background-color: rgba(0, 0, 0,0);") # black color better white color for get better look of semi trans edge, like pre-mutiply
def getMainWindowByName(name): toplevel2 = QtGui.qApp.topLevelWidgets() for i in toplevel2: if name == i.windowTitle(): i.show() return i r=QtGui.QMainWindow() FreeCAD.r=r r.setWindowTitle(name) r.show() return r
def __init__(self, parent=None): self.editor = UI_MainWindow() self.ui = QtGui.QMainWindow() self.editor.setupUi(self.ui) self.editor.txtInput.textChanged.connect(self.textChange)
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 main(): """ Application entry point """ logging.basicConfig(level=logging.DEBUG) # create the application and the main window app = QtGui.QApplication(sys.argv) window = QtGui.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(qdarkstyle.load_stylesheet(pyside=True)) # 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 __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): QtGui.QMainWindow.__init__(self, parent) #QtGui.QDialog.__init__(self, parent) self.version="0.1" self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.fileType='.TMP_UniversalToolUI_TND_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__ #~~~~~~~~~~~~~~~~~~ # initial data #~~~~~~~~~~~~~~~~~~ self.memoData['data']=[] self.setupStyle() 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, QtGui.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] = QtGui.QMenu(uiLabel) menubar.addMenu(self.uiList[uiName]) else: print("Warning (QuickMenu): Only QMainWindow can have menu bar.")
def __init__(self, parent=None, mode=0): QtGui.QMainWindow.__init__(self, parent) #QtGui.QDialog.__init__(self, parent) self.version="1.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__ self.setupStyle() self.setupMenu() # only if you use QMainWindows Class self.setupWin() self.setupUI() self.Establish_Connections() self.loadData() self.loadLang()
def setupUI(self): #============================== # main_layout for QMainWindow main_widget = QtGui.QWidget() self.setCentralWidget(main_widget) main_layout = self.quickLayout('vbox') # grid for auto fill window size main_widget.setLayout(main_layout) ''' # main_layout for QDialog main_layout = self.quickLayout('vbox') self.setLayout(main_layout) ''' #------------------------------ # ui element creation part info_split = self.quickSplitUI( "info_split", self.quickUI(["dict_table;QTableWidget","source_txtEdit;LNTextEdit","result_txtEdit;LNTextEdit"]), "v" ) fileBtn_layout = self.quickUI(["filePath_input;QLineEdit", "fileLoad_btn;QPushButton;Load", "fileLang_choice;QComboBox", "fileExport_btn;QPushButton;Export"],"fileBtn_QHBoxLayout") self.quickUI( [info_split, "process_btn;QPushButton;Process and Update Memory From UI", fileBtn_layout], main_layout) self.uiList["source_txtEdit"].setWrap(0) self.uiList["result_txtEdit"].setWrap(0) ''' self.uiList['secret_btn'] = QtGui.QPushButton(self) # invisible but functional button self.uiList['secret_btn'].setText("") self.uiList['secret_btn'].setGeometry(0, 0, 50, 20) self.uiList['secret_btn'].setStyleSheet("QPushButton{background-color: rgba(0, 0, 0,0);} QPushButton:pressed{background-color: rgba(0, 0, 0,0); border: 0px;} QPushButton:hover{background-color: rgba(0, 0, 0,0); border: 0px;}") #:hover:pressed:focus:hover:disabled '''
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 setupUI(self): #------------------------------ # 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('vbox', 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) else: # main_layout for QDialog main_layout = self.quickLayout('vbox', 'main_layout') self.setLayout(main_layout)
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 #------------------------------
def __init__(self, parent=None, mode=0): super_class.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version="0.1" self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.fileType='.UniversalToolUI_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 __init__(self, sandbox, *args, **kwargs): QtGui.QMainWindow.__init__(self, *args, **kwargs) loadUi(get_resource('window_reference.ui'), self) self.move( self.parent().window().mapToGlobal( self.parent().window().rect().center()) - self.mapToGlobal(self.rect().center())) self.sandbox = sandbox self.actionOptimizeSource.triggered.connect( self.sandbox.optimizeSource) self.createView(self.sandbox)
def __init__(self, parent=None, mode=0): QtWidgets.QMainWindow.__init__(self, parent) #------------------------------ # class variables #------------------------------ self.version = '0.1' self.date = '2017.01.01' self.log = 'no version log in user class' self.help = 'no help guide in user class' self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.memoData['font_size_default'] = QtGui.QFont().pointSize() self.memoData['font_size'] = self.memoData['font_size_default'] self.memoData['last_export'] = '' self.memoData['last_import'] = '' self.name = self.__class__.__name__ self.location = '' if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(sys.modules[self.__class__.__module__].__file__) 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) #------------------------------ # core function variable #------------------------------ self.qui_core_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txt': 'QTextEdit', 'list': 'QListWidget', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', 'menu' : 'QMenu', 'menubar' : 'QMenuBar', } self.qui_user_dict = {}
def setupWin(self): self.setWindowTitle("UITranslator" + " - v" + self.version + " - host: " + hostMode) self.setGeometry(300, 300, 300, 300) #------------------------------ # auto window icon setup path = os.path.join(os.path.dirname(self.location),'icons','UITranslator.png') self.setWindowIcon(QtGui.QIcon(path)) #------------------------------ # initial win drag position self.drag_position=QtGui.QCursor.pos() #------------------------------ # 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 setupUI(self): #============================== # main_layout for QMainWindow main_widget = QtGui.QWidget() self.setCentralWidget(main_widget) main_layout = self.quickLayout('vbox', 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) ''' # main_layout for QDialog main_layout = self.quickLayout('vbox', 'main_layout') self.setLayout(main_layout) ''' #------------------------------ # ui element creation part # quickUI version from universal tool template v6 ''' upper_layout = self.quickUI(["source_txtEdit;LNTextEdit","process_btn;QPushButton;Process and Update"],"upper_QVBoxLayout") upper_layout.setContentsMargins(0,0,0,0) input_split = self.quickSplitUI("input_split", [ upper_layout, self.quickUI(["result_txtEdit;LNTextEdit"])[0] ], "v") fileBtn_layout = self.quickUI(["filePath_input;QLineEdit", "fileLoad_btn;QPushButton;Load", "fileExport_btn;QPushButton;Export"],"fileBtn_QHBoxLayout") self.quickUI([input_split, fileBtn_layout], main_layout) self.uiList["source_txtEdit"].setWrap(0) self.uiList["result_txtEdit"].setWrap(0) ''' #------------------------------ # qui version from template 7 # no extra variable name, all text based creation and reference self.qui('source_txtEdit | process_btn;Process and Update', 'upper_vbox') self.qui('upper_vbox | result_txtEdit', 'input_split;v') self.qui('filePath_input | fileLoad_btn;Load | fileExport_btn;Export', 'fileBtn_layout;hbox') self.qui('input_split | fileBtn_layout', 'main_layout') self.uiList["source_txtEdit"].setWrap(0) self.uiList["result_txtEdit"].setWrap(0) ''' self.uiList['secret_btn'] = QtGui.QPushButton(self) # invisible but functional button self.uiList['secret_btn'].setText("") self.uiList['secret_btn'].setGeometry(0, 0, 50, 20) self.uiList['secret_btn'].setStyleSheet("QPushButton{background-color: rgba(0, 0, 0,0);} QPushButton:pressed{background-color: rgba(0, 0, 0,0); border: 0px;} QPushButton:hover{background-color: rgba(0, 0, 0,0); border: 0px;}") #:hover:pressed:focus:hover:disabled ''' #------------- end ui creation -------------------- for name,each in self.uiList.items(): if isinstance(each, QtGui.QLayout) and name!='main_layout' and not name.endswith('_grp_layout'): each.setContentsMargins(0,0,0,0) self.quickInfo('Ready')
def loadLang(self): if isinstance(self, QtWidgets.QMainWindow): self.quickMenu(['language_menu;&Language']) cur_menu = self.uiList['language_menu'] self.quickMenuAction('langDefault_atnLang', 'Default','','langDefault.png', cur_menu) cur_menu.addSeparator() self.uiList['langDefault_atnLang'].triggered.connect(partial(self.setLang,'default')) # store default language self.memoData['lang']={} self.memoData['lang']['default']={} for ui_name in self.uiList: ui_element = self.uiList[ui_name] if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]: # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox self.memoData['lang']['default'][ui_name] = str(ui_element.text()) elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]: # uiType: QMenu, QGroupBox self.memoData['lang']['default'][ui_name] = str(ui_element.title()) elif type(ui_element) in [ QtWidgets.QTabWidget]: # uiType: QTabWidget tabCnt = ui_element.count() tabNameList = [] for i in range(tabCnt): tabNameList.append(str(ui_element.tabText(i))) self.memoData['lang']['default'][ui_name]=';'.join(tabNameList) elif type(ui_element) == str: # uiType: string for msg self.memoData['lang']['default'][ui_name] = self.uiList[ui_name] # try load other language lang_path = os.path.dirname(self.location) # better in packed than(os.path.abspath(__file__)) baseName = os.path.splitext( os.path.basename(self.location) )[0] for fileName in os.listdir(lang_path): if fileName.startswith(baseName+"_lang_"): langName = fileName.replace(baseName+"_lang_","").split('.')[0].replace(" ","") self.memoData['lang'][ langName ] = self.readFileData( os.path.join(lang_path,fileName) ) if isinstance(self, QtWidgets.QMainWindow): self.quickMenuAction(langName+'_atnLang', langName.upper(),'',langName + '.png', self.uiList['language_menu']) self.uiList[langName+'_atnLang'].triggered.connect(partial(self.setLang,langName)) # if no language file detected, add export default language option if isinstance(self, QtWidgets.QMainWindow) and len(self.memoData['lang']) == 1: self.quickMenuAction('langExport_atnLang', 'Export Default Language','','langExport.png', self.uiList['language_menu']) self.uiList['langExport_atnLang'].triggered.connect(self.exportLang)
def setupUI(self): #------------------------------ # 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('vbox', 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) else: # main_layout for QDialog main_layout = self.quickLayout('vbox', 'main_layout') self.setLayout(main_layout) #------------------------------ # user ui creation part #------------------------------ # + template: qui version since universal tool template v7 # - no extra variable name, all text based creation and reference self.qui('source_txt | process_btn;Process and Update', 'upper_vbox') self.qui('upper_vbox | result_txt', 'input_split;v') self.qui('filePath_input | fileLoad_btn;Load | fileExport_btn;Export', 'fileBtn_layout;hbox') self.qui('input_split | fileBtn_layout', 'main_layout') # - template : quickUI version since universal tool template v6 ''' upper_layout = self.quickUI(["source_txt;QTextEdit","process_btn;QPushButton;Process and Update"],"upper_QVBoxLayout") upper_layout.setContentsMargins(0,0,0,0) input_split = self.quickSplitUI("input_split", [ upper_layout, self.quickUI(["result_txt;QTextEdit"])[0] ], "v") fileBtn_layout = self.quickUI(["filePath_input;QLineEdit", "fileLoad_btn;QPushButton;Load", "fileExport_btn;QPushButton;Export"],"fileBtn_QHBoxLayout") self.quickUI([input_split, fileBtn_layout], main_layout) ''' # - template : invisible but functional button ''' self.uiList['secret_btn'] = QtWidgets.QPushButton(self) self.uiList['secret_btn'].setText("") self.uiList['secret_btn'].setGeometry(0, 0, 50, 20) self.uiList['secret_btn'].setStyleSheet("QPushButton{background-color: rgba(0, 0, 0,0);} QPushButton:pressed{background-color: rgba(0, 0, 0,0); border: 0px;} QPushButton:hover{background-color: rgba(0, 0, 0,0); border: 0px;}") #:hover:pressed:focus:hover:disabled ''' #------------- end ui creation -------------------- keep_margin_layout = ['main_layout'] for name, each in self.uiList.items(): if isinstance(each, QtWidgets.QLayout) and name not in keep_margin_layout and not name.endswith('_grp_layout'): each.setContentsMargins(0, 0, 0, 0) self.quickInfo('Ready')
def setupWin(self): self.setWindowTitle("UniversalToolUI" + " - v" + self.version + " - host: " + hostMode) self.setGeometry(500, 300, 250, 110) # self.resize(250,250) #------------------------------ # auto window icon setup path = os.path.join(os.path.dirname(self.location),'icons','UniversalToolUI.png') self.setWindowIcon(QtGui.QIcon(path)) #------------------------------ # initial win drag position self.drag_position=QtGui.QCursor.pos() #------------------------------ # 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 setupUI(self): #------------------------------ # 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('vbox', 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) else: # main_layout for QDialog main_layout = self.quickLayout('vbox', 'main_layout') self.setLayout(main_layout) #------------------------------ # user ui creation part #------------------------------ # + template: qui version since universal tool template v7 # - no extra variable name, all text based creation and reference self.qui('source_txtEdit | process_btn;Process and Update', 'upper_vbox') self.qui('upper_vbox | result_txtEdit', 'input_split;v') self.qui('filePath_input | fileLoad_btn;Load | fileExport_btn;Export', 'fileBtn_layout;hbox') self.qui('input_split | fileBtn_layout', 'main_layout') self.uiList["source_txtEdit"].setWrap(0) self.uiList["result_txtEdit"].setWrap(0) # - template : quickUI version since universal tool template v6 ''' upper_layout = self.quickUI(["source_txtEdit;LNTextEdit","process_btn;QPushButton;Process and Update"],"upper_QVBoxLayout") upper_layout.setContentsMargins(0,0,0,0) input_split = self.quickSplitUI("input_split", [ upper_layout, self.quickUI(["result_txtEdit;LNTextEdit"])[0] ], "v") fileBtn_layout = self.quickUI(["filePath_input;QLineEdit", "fileLoad_btn;QPushButton;Load", "fileExport_btn;QPushButton;Export"],"fileBtn_QHBoxLayout") self.quickUI([input_split, fileBtn_layout], main_layout) self.uiList["source_txtEdit"].setWrap(0) self.uiList["result_txtEdit"].setWrap(0) ''' # - template : invisible but functional button ''' self.uiList['secret_btn'] = QtWidgets.QPushButton(self) self.uiList['secret_btn'].setText("") self.uiList['secret_btn'].setGeometry(0, 0, 50, 20) self.uiList['secret_btn'].setStyleSheet("QPushButton{background-color: rgba(0, 0, 0,0);} QPushButton:pressed{background-color: rgba(0, 0, 0,0); border: 0px;} QPushButton:hover{background-color: rgba(0, 0, 0,0); border: 0px;}") #:hover:pressed:focus:hover:disabled ''' #------------- end ui creation -------------------- for name,each in self.uiList.items(): if isinstance(each, QtWidgets.QLayout) and name!='main_layout' and not name.endswith('_grp_layout'): each.setContentsMargins(0,0,0,0) # clear extra margin some nested layout #self.quickInfo('Ready')
def __init__(self, *args, **kwargs): filename = kwargs.pop('filename', None) QtGui.QMainWindow.__init__(self, *args, **kwargs) loadUi(get_resource('talpa.ui'), baseinstance=self) self.sandbox = SandboxModel.empty() self.log = SceneLog(self, self.sandbox) self.actionSaveModel.triggered.connect( self.onSaveModel) self.actionLoadModel.triggered.connect( self.loadModel) self.actionExportKiteScene.triggered.connect( self.onExportScene) self.actionChangeExtent.triggered.connect( self.extentDialog) self.actionLoadReferenceScene.triggered.connect( self.onLoadReferenceScene) self.actionConfiguration.triggered.connect( self.configDialog) self.actionHelp.triggered.connect( lambda: QtGui.QDesktopServices.openUrl('http://pyrocko.org')) self.actionAbout_Talpa.triggered.connect( self.aboutDialog().show) self.actionLog.triggered.connect( self.log.show) self.sandbox.sigModelChanged.connect( self.createMisfitWindow) self.progress = QtGui.QProgressDialog('', None, 0, 0, self) self.progress.setValue(0) self.progress.closeEvent = lambda ev: ev.ignore() self.progress.setMinimumWidth(400) self.progress.setWindowTitle('processing...') self.sandbox.sigProcessingFinished.connect( self.processingFinished) self.sandbox.sigProcessingStarted.connect( self.processingStarted) if filename is not None: self.loadModel(filename) self.createView(self.sandbox)
def __init__(self, *args, **kwargs): QtGui.QMainWindow.__init__(self, *args, **kwargs) self.loadUi() self.views = [KiteScene, KiteQuadtree, KiteCovariance] self.ptree = KiteParameterTree(showHeader=False) self.ptree_dock = QtGui.QDockWidget('Parameters', self) self.ptree_dock.setFeatures(QtGui.QDockWidget.DockWidgetFloatable | QtGui.QDockWidget.DockWidgetMovable) self.ptree_dock.setWidget(self.ptree) self.addDockWidget( QtCore.Qt.LeftDockWidgetArea, self.ptree_dock) self.model = SceneModel() self.model.sigSceneModelChanged.connect( self.buildViews) self.sigLoadFile.connect( self.model.loadFile) self.sigImportFile.connect( self.model.importFile) self.sigLoadConfig.connect( self.model.loadConfig) self.sigExportWeightMatrix.connect( self.model.exportWeightMatrix) self.actionSave_config.triggered.connect( self.onSaveConfig) self.actionSave_scene.triggered.connect( self.onSaveScene) self.actionLoad_config.triggered.connect( self.onLoadConfig) self.actionLoad_scene.triggered.connect( self.onOpenScene) self.actionImport_scene.triggered.connect( self.onImportScene) self.actionExport_quadtree.triggered.connect( self.onExportQuadtree) self.actionExport_weights.triggered.connect( self.onExportWeightMatrix) self.actionAbout_Spool.triggered.connect( self.aboutDialog().show) self.actionHelp.triggered.connect( lambda: QtGui.QDesktopServices.openUrl('http://pyrocko.org')) self.log = SceneLog(self, self.model) self.actionLog.triggered.connect( self.log.show) self.progress = QtGui.QProgressDialog('', None, 0, 0, self) self.progress.setValue(0) self.progress.closeEvent = lambda ev: ev.ignore() self.progress.setMinimumWidth(400) self.progress.setWindowTitle('processing...') self.model.sigProcessingFinished.connect(self.progress.reset)
def __init__(self, parent = None): path = os.path.dirname(ui.__file__) # chat self.message_window_path = os.path.join(path, "message_window.ui") self.chat_main_path = os.path.join(path, "chat_dialog.ui") self.chat_add_topic_path = os.path.join(path, "chat_add_topic.ui") self.chat_img_viewer_path = os.path.join(path, "chat_img_viewer.ui") # moduls self.db_studio = db.studio() self.db_artist = db.artist() self.db_task = db.task() self.db_log = db.log() self.db_chat = db.chat() # get data home_dir = os.path.expanduser('~') json_path = os.path.normpath(os.path.join(home_dir, '.blend_chat.json')) with open(json_path, 'r') as read: data_dict = json.load(read) self.chat_status = 'user' self.current_task = data_dict['current_task'] self.current_user = data_dict['current_user'] self.current_project = data_dict['current_project'] print(data_dict) # create widget QtGui.QMainWindow.__init__(self, parent) self.setWindowTitle('Chat Message Window') self.textBox = QtGui.QTextEdit(parent = self) self.textBox.setReadOnly(True) self.setCentralWidget(self.textBox) ''' # test text text = self.textBox.toPlainText() text = text + '\n' + '>>> ' + 'text.text' self.textBox.setPlainText(text) ''' self.run_chat_ui()