def setupUi(self, visualizaerWidget):
visualizaerWidget.setObjectName("visualizaerWidget")
visualizaerWidget.resize(1024, 657)
self.horizontalLayout = QtWidgets.QHBoxLayout(visualizaerWidget)
self.horizontalLayout.setObjectName("horizontalLayout")
self.tabWidget = QtWidgets.QTabWidget(visualizaerWidget)
self.tabWidget.setMinimumSize(QtCore.QSize(0, 0))
self.tabWidget.setMaximumSize(QtCore.QSize(400, 16777215))
self.tabWidget.setTabPosition(QtWidgets.QTabWidget.South)
self.tabWidget.setObjectName("tabWidget")
self.horizontalLayout.addWidget(self.tabWidget)
self.pmiWidget = QtWidgets.QWidget(visualizaerWidget)
self.pmiWidget.setObjectName("pmiWidget")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.pmiWidget)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.horizontalLayout.addWidget(self.pmiWidget)
self.tsWidget = QtWidgets.QWidget(visualizaerWidget)
self.tsWidget.setObjectName("tsWidget")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.tsWidget)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.horizontalLayout.addWidget(self.tsWidget)
self.retranslateUi(visualizaerWidget)
QtCore.QMetaObject.connectSlotsByName(visualizaerWidget)
python类QTabWidget()的实例源码
def TabWidget():
app = _app()
views = [x for x in app.allWidgets() if x.__class__ is QtWidgets.QListView]
for view in views:
if view.parent().__class__ is QtWidgets.QStackedWidget:
if view.parent().parent().__class__ is QtWidgets.QTabWidget:
return view.parent().parent()
return None
def drawDashboard(self, Widget):
# Create main widget.
Widget.setObjectName("Widget")
Widget.resize(612, 513)
# Chosing the Window Title
Widget.setWindowTitle("Dashboard Zeng Ltd.")
# Using horizontal tab-layout
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(Widget)
self.horizontalLayout_2.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.tabWidget = QtWidgets.QTabWidget(Widget)
self.tabWidget.setTabPosition(QtWidgets.QTabWidget.North)
self.tabWidget.setElideMode(QtCore.Qt.ElideRight)
self.tabWidget.setObjectName("tabWidget")
self.horizontalLayout_2.addWidget(self.tabWidget)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(Widget)
self.nodevice = QtWidgets.QLabel(Widget)
self.nodevice.setGeometry(QtCore.QRect(200, 240, 200, 23))
text = QtGui.QFont()
text.setPointSize(19)
self.nodevice.setText("No Devices Connected")
self.nodevice.setFont(text)
# Function to add a tab. This function takes a number from 1-4 as
# parameter representing the number of the arduino
def createWidgetFromDefinitionDict(self):
"""
Automatically build a widget, based on dict definition of the items.
@return: a QWidget containing all the elements of the configuration window
"""
logger.info('Creating configuration window')
tab_widget = QTabWidget()
definition = self.cfg_window_def
#Create a dict with the sections' titles if not already defined. This dict contains sections' names as key and tabs' titles as values
if '__section_title__' not in definition:
definition['__section_title__'] = {}
#Compute all the sections
for section in sorted(definition):
#skip the special section __section_title__
if section == '__section_title__':
continue
#Create the title for the section if it doesn't already exist
if section not in definition['__section_title__']:
#The title for this section doesn't exist yet
if isinstance(definition[section], dict) and '__section_title__' in definition[section]:
#The title for this section is defined into the section itself => we add the title to the dict containing all the titles
definition['__section_title__'][section] = definition[section]['__section_title__']
else:
#The title for this section is not defined anywhere, so we use the section name itself as a title
definition['__section_title__'][section] = section.replace('_', ' ')
#Create the tab (and the widget) for the current section, if it doesn't exist yet
widget = None
for i in range(tab_widget.count()):
if definition['__section_title__'][section] == tab_widget.tabText(i):
widget = tab_widget.widget(i)
break
if widget is None:
widget = QWidget()
tab_widget.addTab(widget, definition['__section_title__'][section])
#Create the tab content for this section
self.createWidgetSubSection(definition[section], widget)
#Add a separator at the end of this subsection
if widget.layout() is not None:
separator = QFrame()
separator.setFrameShape(QFrame.HLine)
widget.layout().addWidget(separator)
widget.layout().addStretch()
#Add a QSpacer at the bottom of each widget, so that the items are placed on top of each tab
for i in range(tab_widget.count()):
if tab_widget.widget(i).layout() is not None:
tab_widget.widget(i).layout().addStretch()
return tab_widget
def __init__(self):
QWidgetSavePos.__init__(self,"electrical")
self.setFixedSize(1000, 600)
self.setWindowIcon(QIcon_load("preferences-system"))
self.setWindowTitle(_("Electrical parameter editor")+" (https://www.gpvdm.com)")
self.main_vbox = QVBoxLayout()
toolbar=QToolBar()
toolbar.setIconSize(QSize(48, 48))
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
toolbar.addWidget(spacer)
self.undo = QAction(QIcon_load("help"), _("Help"), self)
self.undo.setStatusTip(_("Help"))
self.undo.triggered.connect(self.callback_help)
toolbar.addAction(self.undo)
self.main_vbox.addWidget(toolbar)
self.notebook = QTabWidget()
self.notebook.setMovable(True)
self.main_vbox.addWidget(self.notebook)
widget=tab_class()
widget.init("device.inp",_("Device"))
self.notebook.addTab(widget,_("Device"))
widget=dos_main()
widget.update()
self.notebook.addTab(widget,_("Electrical parameters"))
if enable_betafeatures()==True:
widget=tab_bands()
widget.update()
self.notebook.addTab(widget,_("Complex DoS"))
widget=pl_main()
widget.update()
self.notebook.addTab(widget,_("Luminescence"))
self.setLayout(self.main_vbox)
#self.connect("delete-event", self.callback_close_window)
self.notebook.currentChanged.connect(self.changed_click)
#self.hide()
def __init__(self,name):
QWidgetSavePos.__init__(self,name)
self.setMinimumSize(900, 600)
self.setWindowIcon(QIcon_load("preferences-system"))
self.setWindowTitle(_("Fit configure")+" (https://www.gpvdm.com)")
self.main_vbox = QVBoxLayout()
toolbar=QToolBar()
toolbar.setIconSize(QSize(48, 48))
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
toolbar.addWidget(spacer)
self.undo = QAction(QIcon_load("help"), _("Help"), self)
self.undo.setStatusTip(_("Close"))
self.undo.triggered.connect(self.callback_help)
toolbar.addAction(self.undo)
self.main_vbox.addWidget(toolbar)
self.notebook = QTabWidget()
self.notebook.setMovable(True)
self.main_vbox.addWidget(self.notebook)
files=[os.path.join(get_sim_path(),"fit.inp")]
description=[_("Configure minimizer")]
for i in range(0,len(files)):
tab=tab_class()
tab.init(files[i],description[i])
self.notebook.addTab(tab,description[i])
self.duplicate_window=duplicate()
self.notebook.addTab(self.duplicate_window,_("Duplicate window"))
self.fit_vars_window=fit_vars()
self.notebook.addTab(self.fit_vars_window,_("Fit variable window"))
self.constraints_window=constraints()
self.notebook.addTab(self.constraints_window,_("Fit constraints"))
self.setLayout(self.main_vbox)
def __init__(self):
QWidgetSavePos.__init__(self,"parasitic")
self.setFixedSize(900, 600)
self.setWindowIcon(QIcon_load("parasitic"))
self.setWindowTitle(_("Edit parasitic components")+" (https://www.gpvdm.com)")
self.main_vbox = QVBoxLayout()
toolbar=QToolBar()
toolbar.setIconSize(QSize(48, 48))
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
toolbar.addWidget(spacer)
self.help = QAction(QIcon_load("help"), _("Help"), self)
self.help.setStatusTip(_("Close"))
self.help.triggered.connect(self.callback_help)
toolbar.addAction(self.help)
self.main_vbox.addWidget(toolbar)
self.notebook = QTabWidget()
self.notebook.setMovable(True)
self.main_vbox.addWidget(self.notebook)
files=["parasitic.inp"]
description=[_("Parasitic components")]
for i in range(0,len(files)):
tab=tab_class()
tab.init(os.path.join(get_sim_path(),files[i]),description[i])
self.notebook.addTab(tab,description[i])
self.setLayout(self.main_vbox)
def __init__(self,path):
QWidgetSavePos.__init__(self,"spectra_main")
self.path=path
self.setFixedSize(900, 600)
self.setWindowIcon(QIcon_load("spectra_file"))
self.setWindowTitle(_("Optical spectrum editor")+" (https://www.gpvdm.com)"+" "+os.path.basename(self.path))
self.main_vbox = QVBoxLayout()
toolbar=QToolBar()
toolbar.setIconSize(QSize(48, 48))
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
toolbar.addWidget(spacer)
self.help = QAction(QIcon_load("help"), 'Hide', self)
self.help.setStatusTip(_("Help"))
self.help.triggered.connect(self.callback_help)
toolbar.addAction(self.help)
self.main_vbox.addWidget(toolbar)
self.notebook = QTabWidget()
self.notebook.setMovable(True)
self.main_vbox.addWidget(self.notebook)
files=["mat.inp"]
description=[_("Parameters")]
eq=equation(self.path,"spectra_eq.inp","spectra_gen.inp","spectra.inp","#spectra_equation_or_data")
eq.show_solar_spectra=True
eq.set_default_value("3")
eq.set_ylabel(_("Intensity")+" (au)")
eq.init()
self.notebook.addTab(eq,_("Intensity"))
for i in range(0,len(files)):
tab=tab_class()
tab.init(os.path.join(self.path,files[i]),description[i])
self.notebook.addTab(tab,description[i])
self.setLayout(self.main_vbox)
self.notebook.currentChanged.connect(self.changed_click)
def __init__(self):
QWidgetSavePos.__init__(self,"lasers")
self.main_vbox = QVBoxLayout()
self.setFixedSize(900, 500)
self.setWindowTitle(_("Laser configuration window")+" https://www.gpvdm.com")
self.setWindowIcon(QIcon_load("lasers"))
toolbar=QToolBar()
toolbar.setToolButtonStyle( Qt.ToolButtonTextUnderIcon)
toolbar.setIconSize(QSize(48, 48))
self.new = QAction(QIcon_load("document-new"), wrap_text(_("New laser"),2), self)
self.new.triggered.connect(self.callback_add_page)
toolbar.addAction(self.new)
self.new = QAction(QIcon_load("edit-delete"), wrap_text(_("Delete laser"),3), self)
self.new.triggered.connect(self.callback_delete_page)
toolbar.addAction(self.new)
self.clone = QAction(QIcon_load("clone.png"), wrap_text(_("Clone laser"),3), self)
self.clone.triggered.connect(self.callback_copy_page)
toolbar.addAction(self.clone)
self.clone = QAction(QIcon_load("rename"), wrap_text(_("Rename laser"),3), self)
self.clone.triggered.connect(self.callback_rename_page)
toolbar.addAction(self.clone)
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
toolbar.addWidget(spacer)
self.help = QAction(QIcon_load("help"), _("Help"), self)
self.help.setStatusTip(_("Close"))
self.help.triggered.connect(self.callback_help)
toolbar.addAction(self.help)
self.main_vbox.addWidget(toolbar)
self.notebook = QTabWidget()
self.notebook.setMovable(True)
self.load_tabs()
self.main_vbox.addWidget(self.notebook)
self.status_bar=QStatusBar()
self.main_vbox.addWidget(self.status_bar)
self.setLayout(self.main_vbox)
def init(self):
self.setFixedSize(900, 600)
self.setWindowIcon(QIcon_load("preferences-system"))
self.setWindowTitle(_("Configure")+" (https://www.gpvdm.com)")
self.main_vbox = QVBoxLayout()
toolbar=QToolBar()
toolbar.setIconSize(QSize(48, 48))
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
toolbar.addWidget(spacer)
self.undo = QAction(QIcon_load("help"), _("Help"), self)
self.undo.setStatusTip(_("Help"))
self.undo.triggered.connect(self.callback_help)
toolbar.addAction(self.undo)
self.main_vbox.addWidget(toolbar)
self.notebook = QTabWidget()
self.notebook.setMovable(True)
self.main_vbox.addWidget(self.notebook)
files=["math.inp","dump.inp","thermal.inp","led.inp","config.inp","server.inp","crypto.inp"]
description=[_("Solver configuration"),_("Output files"),_("Thermal"),_("LED"),_("GUI configuration"),_("Server configuration"),_("Cryptography")]
for i in range(0,len(files)):
file_name=os.path.join(get_sim_path(),files[i])
if inp_isfile(file_name)==True:
tab=tab_class()
tab.init(file_name,description[i])
self.notebook.addTab(tab,description[i])
if os.path.basename(file_name)=="dump.inp":
tab.changed.connect(self.callback_tab_changed)
self.detailed_file_select=dump_select()
self.notebook.addTab(self.detailed_file_select,_("Detailed dump control"))
lang_tab=language_tab_class()
self.notebook.addTab(lang_tab,_("Language"))
self.setLayout(self.main_vbox)
#self.connect("delete-event", self.callback_close_window)
#self.hide()
def __init__(self,file_name):
QWidgetSavePos.__init__(self,"info")
self.setFixedSize(900, 600)
self.setWindowIcon(QIcon_load("jv"))
self.setWindowTitle(_("Simulation information")+" (www.gpvdm.com)")
self.main_vbox = QVBoxLayout()
toolbar=QToolBar()
toolbar.setIconSize(QSize(48, 48))
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
toolbar.addWidget(spacer)
self.help = QAction(QIcon_load("help"), _("Help"), self)
self.help.setStatusTip(_("Close"))
self.help.triggered.connect(self.callback_help)
toolbar.addAction(self.help)
self.main_vbox.addWidget(toolbar)
self.notebook = QTabWidget()
self.notebook.setMovable(True)
self.main_vbox.addWidget(self.notebook)
files=[file_name]
description=[_("Simulation Information")]
for i in range(0,len(files)):
tab=tab_class()
tab.set_edit(False)
tab.init(files[i],description[i])
self.notebook.addTab(tab,description[i])
self.setLayout(self.main_vbox)
def __init__(self):
QWidgetSavePos.__init__(self,"jv")
self.setFixedSize(900, 600)
self.setWindowIcon(QIcon_load("jv"))
self.setWindowTitle(_("Steady state simulation")+" (https://www.gpvdm.com)")
self.main_vbox = QVBoxLayout()
toolbar=QToolBar()
toolbar.setIconSize(QSize(48, 48))
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
toolbar.addWidget(spacer)
self.help = QAction(QIcon_load("help"), _("Help"), self)
self.help.setStatusTip(_("Close"))
self.help.triggered.connect(self.callback_help)
toolbar.addAction(self.help)
self.main_vbox.addWidget(toolbar)
self.notebook = QTabWidget()
self.notebook.setMovable(True)
self.main_vbox.addWidget(self.notebook)
files=["jv.inp","jv_simple.inp","sun_voc.inp"]
description=[_("JV simulation"),_("Diode equation"),_("Suns v.s. Voc")]
for i in range(0,len(files)):
tab=tab_class()
tab.init(files[i],description[i])
self.notebook.addTab(tab,description[i])
self.setLayout(self.main_vbox)
self.notebook.currentChanged.connect(self.changed_click)
def setupUi(self, AddFileDialog):
AddFileDialog.setObjectName("AddFileDialog")
AddFileDialog.resize(470, 401)
self.verticalLayout_2 = QtWidgets.QVBoxLayout(AddFileDialog)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.playlistBox = QtWidgets.QComboBox(AddFileDialog)
self.playlistBox.setObjectName("playlistBox")
self.verticalLayout_2.addWidget(self.playlistBox)
self.tabWidget = QtWidgets.QTabWidget(AddFileDialog)
self.tabWidget.setObjectName("tabWidget")
self.fromFile = QtWidgets.QWidget()
self.fromFile.setObjectName("fromFile")
self.verticalLayout = QtWidgets.QVBoxLayout(self.fromFile)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.fileLabel = QtWidgets.QLabel(self.fromFile)
self.fileLabel.setMaximumSize(QtCore.QSize(16777215, 100))
self.fileLabel.setObjectName("fileLabel")
self.verticalLayout.addWidget(self.fileLabel)
self.openfilebutton = QtWidgets.QPushButton(self.fromFile)
self.openfilebutton.setObjectName("openfilebutton")
self.verticalLayout.addWidget(self.openfilebutton)
self.tabWidget.addTab(self.fromFile, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.tab_2)
self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.label = QtWidgets.QLabel(self.tab_2)
self.label.setMaximumSize(QtCore.QSize(16777215, 20))
self.label.setObjectName("label")
self.verticalLayout_3.addWidget(self.label)
self.checkBox = QtWidgets.QCheckBox(self.tab_2)
self.checkBox.setEnabled(True)
self.checkBox.setAcceptDrops(False)
self.checkBox.setCheckable(True)
self.checkBox.setChecked(False)
self.checkBox.setObjectName("checkBox")
self.verticalLayout_3.addWidget(self.checkBox)
self.url = QtWidgets.QLineEdit(self.tab_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(self.url.sizePolicy().hasHeightForWidth())
self.url.setSizePolicy(sizePolicy)
self.url.setObjectName("url")
self.verticalLayout_3.addWidget(self.url)
self.tabWidget.addTab(self.tab_2, "")
self.verticalLayout_2.addWidget(self.tabWidget)
self.buttonBox = QtWidgets.QDialogButtonBox(AddFileDialog)
self.buttonBox.setLayoutDirection(QtCore.Qt.LeftToRight)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.verticalLayout_2.addWidget(self.buttonBox)
self.retranslateUi(AddFileDialog)
self.tabWidget.setCurrentIndex(1)
self.buttonBox.accepted.connect(AddFileDialog.accept)
self.buttonBox.rejected.connect(AddFileDialog.reject)
QtCore.QMetaObject.connectSlotsByName(AddFileDialog)
universal_tool_template_1020.py 文件源码
项目:universal_tool_template.py
作者: shiningdesign
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
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 qui(self, ui_list_string, parentObject_string='', opt=''):
# pre-defined user short name syntax
type_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',
'txtEdit': 'LNTextEdit', 'txt': 'QTextEdit',
'tree': 'QTreeWidget', 'table': 'QTableWidget',
'space': 'QSpacerItem',
}
# get ui_list, creation or existing ui object
ui_list = [x.strip() for x in ui_list_string.split('|')]
for i in range(len(ui_list)):
if ui_list[i] in self.uiList:
# - exisiting object
ui_list[i] = self.uiList[ui_list[i]]
else:
# - string creation:
# get part info
partInfo = ui_list[i].split(';',1)
uiName = partInfo[0].split('@')[0]
uiType = uiName.rsplit('_',1)[-1]
if uiType in type_dict:
uiType = type_dict[uiType]
# set quickUI string format
ui_list[i] = partInfo[0]+';'+uiType
if len(partInfo)==1:
# give empty button and label a place holder name
if uiType in ('btn', 'btnMsg', 'QPushButton','label', 'QLabel'):
ui_list[i] = partInfo[0]+';'+uiType + ';'+uiName
elif len(partInfo)==2:
ui_list[i]=ui_list[i]+";"+partInfo[1]
# get parentObject or exisiting object
parentObject = parentObject_string
if parentObject in self.uiList:
parentObject = self.uiList[parentObject]
# process quickUI
self.quickUI(ui_list, parentObject, opt)
GearBox_template_1010.py 文件源码
项目:universal_tool_template.py
作者: shiningdesign
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def __init__(self, parent=None, mode=0):
super_class.__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.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.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)
#------------------------------
# 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 = {}
#------------------------------
universal_tool_template_0904.py 文件源码
项目:universal_tool_template.py
作者: shiningdesign
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
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(sys.modules[self.__class__.__module__].__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)
#------------------------------
# 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',
}
self.qui_user_dict = {}
#------------------------------
universal_tool_template_0904.py 文件源码
项目:universal_tool_template.py
作者: shiningdesign
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
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)
universal_tool_template_0904.py 文件源码
项目:universal_tool_template.py
作者: shiningdesign
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def setupUI(self):
super(self.__class__,self).setupUI('grid')
#------------------------------
# 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']
keep_margin_layout_obj = []
# add tab layouts
for each in self.uiList.values():
if isinstance(each, QtWidgets.QTabWidget):
for i in range(each.count()):
keep_margin_layout_obj.append( each.widget(i).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') and each not in keep_margin_layout_obj:
each.setContentsMargins(0, 0, 0, 0)
self.quickInfo('Ready')
# self.statusBar().hide()