def __init__(self, parent, footprintlist):
QtGui.QDialog.__init__(self, parent)
self.owner = parent
self.combo_param_name = QtGui.QComboBox();
self.combo_param_name.setEditable(True)
self.footprint_list = footprintlist
self.list_widget = PartTreeWidget(self)
self.list_widget.setColumnCount(4)
self.btn_load_bom = QtGui.QPushButton("load Field from xml-BOM")
self.gridlayout = QtGui.QGridLayout()
self.label = QtGui.QLabel("Field name:")
self.gridlayout.addWidget(self.label,0,0,1,0)
self.gridlayout.addWidget(self.btn_load_bom,1,1)
self.gridlayout.addWidget(self.combo_param_name,1,0)
self.gridlayout.addWidget(self.list_widget,2,0,1,0)
self.label.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Minimum)
self.combo_param_name.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Minimum)
self.list_widget.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,QtGui.QSizePolicy.MinimumExpanding)
self.param_names = []
settings = QtCore.QSettings("./KicadSolderTool.ini",QtCore.QSettings.IniFormat)
size = settings.beginReadArray("param_names")
for i in range(size):
settings.setArrayIndex(i)
self.param_names.append(settings.value("key"))
settings.endArray()
self.combo_param_name.addItems(self.param_names)
self.combo_param_name.setCurrentIndex(int(settings.value("recent_field_name",0)))
self.setLayout(self.gridlayout)
for footprint in self.footprint_list:
if footprint['bot']:
caption = 'bot'
else:
caption = 'top'
if footprint['other_side']:
caption += "(also other side)"
item = QtGui.QTreeWidgetItem(caption)
item.setText(0,footprint['ref'])
item.setText(1,caption)
item.setText(2,footprint['val'])
item.setCheckState(0,QtCore.Qt.Unchecked)
self.list_widget.addTopLevelItem(item)
for i in range(self.list_widget.columnCount()):
self.list_widget.resizeColumnToContents(i);
self.setMinimumWidth(600)
self.show()
self.connect(self.list_widget, QtCore.SIGNAL("itemSelectionChanged()"), self.on_select)
self.connect(self.btn_load_bom, QtCore.SIGNAL("clicked()"), self.on_load_bom)
python类QDialog()的实例源码
def __init__(self, sql, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle(u'Import database')
self.sql = sql
# file
self.filePath = QtGui.QLineEdit('')
self.filePath.setReadOnly(True)
filePathButton = QtGui.QPushButton('...')
self.connect(filePathButton, QtCore.SIGNAL("clicked()"), self.chooseFile)
filePathFrame = QtGui.QFrame()
filePathFrame.setObjectName('lay_path_widget')
filePathFrame.setStyleSheet('''#lay_path_widget {background-color:#fff; border:1px solid rgb(199, 199, 199); padding: 5px;}''')
filePathLayout = QtGui.QHBoxLayout(filePathFrame)
filePathLayout.addWidget(QtGui.QLabel(u'File:\t'))
filePathLayout.addWidget(self.filePath)
filePathLayout.addWidget(filePathButton)
filePathLayout.setContentsMargins(0, 0, 0, 0)
# tabs
self.tabs = QtGui.QTabWidget()
self.tabs.setTabPosition(QtGui.QTabWidget.West)
self.tabs.setObjectName('tabs_widget')
self.tabs.addTab(self.tabCategories(), u'Categories')
self.tabs.addTab(self.tabModels(), u'Models')
self.tabs.setTabEnabled(1, False)
self.connect(self.tabs, QtCore.SIGNAL("currentChanged (int)"), self.activeModelsTab)
# buttons
buttons = QtGui.QDialogButtonBox()
buttons.addButton("Cancel", QtGui.QDialogButtonBox.RejectRole)
buttons.addButton("Import", QtGui.QDialogButtonBox.AcceptRole)
self.connect(buttons, QtCore.SIGNAL("accepted()"), self, QtCore.SLOT("accept()"))
self.connect(buttons, QtCore.SIGNAL("rejected()"), self, QtCore.SLOT("reject()"))
buttonsFrame = QtGui.QFrame()
buttonsFrame.setObjectName('lay_path_widget')
buttonsFrame.setStyleSheet('''#lay_path_widget {background-color:#fff; border:1px solid rgb(199, 199, 199); padding: 5px;}''')
buttonsLayout = QtGui.QHBoxLayout(buttonsFrame)
buttonsLayout.addWidget(buttons)
buttonsLayout.setContentsMargins(0, 0, 0, 0)
# main layout
lay = QtGui.QGridLayout(self)
lay.addWidget(filePathFrame, 0, 0, 1, 1)
lay.addWidget(self.tabs, 1, 0, 1, 1)
lay.addWidget(buttonsFrame, 2, 0, 1, 1)
lay.setRowStretch(1, 10)
lay.setContentsMargins(5, 5, 5, 5)
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle(u"Create drilling map")
#
# Output file format
self.formatList = QtGui.QComboBox()
for i, j in exportList.items():
self.formatList.addItem(j['name'], i)
# Output directory
self.pathToFile = QtGui.QLineEdit('')
self.pathToFile.setReadOnly(True)
zmianaSciezki = QtGui.QPushButton('...')
zmianaSciezki.setToolTip(u'Change path')
QtCore.QObject.connect(zmianaSciezki, QtCore.SIGNAL("pressed ()"), self.zmianaSciezkiF)
# buttons
saveButton = QtGui.QPushButton(u"Export")
self.connect(saveButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT("accept()"))
closeButton = QtGui.QPushButton(u"Close")
self.connect(closeButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT('close()'))
packageFooter = QtGui.QHBoxLayout()
packageFooter.addStretch(10)
packageFooter.addWidget(saveButton)
packageFooter.addWidget(closeButton)
packageFooter.setContentsMargins(10, 0, 10, 10)
# header
icon = QtGui.QLabel('')
icon.setPixmap(QtGui.QPixmap(":/data/img/drill-icon.png"))
headerWidget = QtGui.QWidget()
headerWidget.setStyleSheet("padding: 10px; border-bottom: 1px solid #dcdcdc; background-color:#FFF;")
headerLay = QtGui.QGridLayout(headerWidget)
headerLay.addWidget(icon, 0, 0, 1, 1)
headerLay.setContentsMargins(0, 0, 0, 0)
########
centerLay = QtGui.QGridLayout()
centerLay.addWidget(QtGui.QLabel(u'Output file format:'), 0, 0, 1, 1)
centerLay.addWidget(self.formatList, 0, 1, 1, 2)
centerLay.addWidget(QtGui.QLabel(u'Output directory:'), 1, 0, 1, 1)
centerLay.addWidget(self.pathToFile, 1, 1, 1, 1)
centerLay.addWidget(zmianaSciezki, 1, 2, 1, 1)
centerLay.setContentsMargins(10, 20, 10, 20)
mainLay = QtGui.QVBoxLayout(self)
mainLay.addWidget(headerWidget)
mainLay.addLayout(centerLay)
mainLay.addStretch(10)
mainLay.addLayout(packageFooter)
mainLay.setContentsMargins(0, 0, 0, 0)
#
self.formatList.setCurrentIndex(self.formatList.findData('dxf'))
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle(u"Export hole locations report")
# Output directory
self.pathToFile = QtGui.QLineEdit('')
self.pathToFile.setReadOnly(True)
zmianaSciezki = QtGui.QPushButton('...')
zmianaSciezki.setToolTip(u'Change path')
QtCore.QObject.connect(zmianaSciezki, QtCore.SIGNAL("pressed ()"), self.zmianaSciezkiF)
# header
icon = QtGui.QLabel('')
icon.setPixmap(QtGui.QPixmap(":/data/img/drill-icon.png"))
headerWidget = QtGui.QWidget()
headerWidget.setStyleSheet("padding: 10px; border-bottom: 1px solid #dcdcdc; background-color:#FFF;")
headerLay = QtGui.QGridLayout(headerWidget)
headerLay.addWidget(icon, 0, 0, 1, 1)
headerLay.setContentsMargins(0, 0, 0, 0)
# buttons
saveButton = QtGui.QPushButton(u"Export")
self.connect(saveButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT("accept()"))
closeButton = QtGui.QPushButton(u"Close")
self.connect(closeButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT('close()'))
packageFooter = QtGui.QHBoxLayout()
packageFooter.addStretch(10)
packageFooter.addWidget(saveButton)
packageFooter.addWidget(closeButton)
packageFooter.setContentsMargins(10, 0, 10, 10)
# report
self.reportPrev = QtGui.QTextEdit()
########
centerLay = QtGui.QGridLayout()
centerLay.addWidget(QtGui.QLabel(u'Output directory:'), 0, 0, 1, 1)
centerLay.addWidget(self.pathToFile, 0, 1, 1, 1)
centerLay.addWidget(zmianaSciezki, 0, 2, 1, 1)
centerLay.addWidget(self.reportPrev, 1, 0, 1, 3)
centerLay.setContentsMargins(10, 20, 10, 20)
mainLay = QtGui.QVBoxLayout(self)
mainLay.addWidget(headerWidget)
mainLay.addLayout(centerLay)
mainLay.addLayout(packageFooter)
mainLay.setContentsMargins(0, 0, 0, 0)
#
self.showReport()
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle(u"Centroid")
#
# Output directory
self.pathToFile = QtGui.QLineEdit('')
self.pathToFile.setReadOnly(True)
zmianaSciezki = QtGui.QPushButton('...')
zmianaSciezki.setToolTip(u'Change path')
QtCore.QObject.connect(zmianaSciezki, QtCore.SIGNAL("pressed ()"), self.zmianaSciezkiF)
# header
icon = QtGui.QLabel('')
icon.setPixmap(QtGui.QPixmap(":/data/img/exportBOM.png"))
headerWidget = QtGui.QWidget()
headerWidget.setStyleSheet("padding: 10px; border-bottom: 1px solid #dcdcdc; background-color:#FFF;")
headerLay = QtGui.QGridLayout(headerWidget)
headerLay.addWidget(icon, 0, 0, 1, 1)
headerLay.setContentsMargins(0, 0, 0, 0)
# buttons
saveButton = QtGui.QPushButton(u"Export")
self.connect(saveButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT("accept()"))
closeButton = QtGui.QPushButton(u"Close")
self.connect(closeButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT('close()'))
packageFooter = QtGui.QHBoxLayout()
packageFooter.addStretch(10)
packageFooter.addWidget(saveButton)
packageFooter.addWidget(closeButton)
packageFooter.setContentsMargins(10, 0, 10, 10)
# report
self.reportPrev = QtGui.QTextEdit()
########
centerLay = QtGui.QGridLayout()
centerLay.addWidget(QtGui.QLabel(u'Output directory:'), 0, 0, 1, 1)
centerLay.addWidget(self.pathToFile, 0, 1, 1, 1)
centerLay.addWidget(zmianaSciezki, 0, 2, 1, 1)
centerLay.addWidget(self.reportPrev, 1, 0, 1, 3)
centerLay.setContentsMargins(10, 20, 10, 20)
mainLay = QtGui.QVBoxLayout(self)
mainLay.addWidget(headerWidget)
mainLay.addLayout(centerLay)
mainLay.addLayout(packageFooter)
mainLay.setContentsMargins(0, 0, 0, 0)
#
self.showReport()
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
#############################################
universal_tool_template_0803.py 文件源码
项目:universal_tool_template.py
作者: shiningdesign
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
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')
universal_tool_template_v8.1.py 文件源码
项目:universal_tool_template.py
作者: shiningdesign
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
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
#############################################