我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PySide.QtGui.QCheckBox()。
def setLang(self, langName): uiList_lang_read = self.memoData['lang'][langName] for ui_name in uiList_lang_read: ui_element = self.uiList[ui_name] if type(ui_element) in [ QtGui.QLabel, QtGui.QPushButton, QtGui.QAction, QtGui.QCheckBox ]: # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox if uiList_lang_read[ui_name] != "": ui_element.setText(uiList_lang_read[ui_name]) elif type(ui_element) in [ QtGui.QGroupBox, QtGui.QMenu ]: # uiType: QMenu, QGroupBox if uiList_lang_read[ui_name] != "": ui_element.setTitle(uiList_lang_read[ui_name]) elif type(ui_element) in [ QtGui.QTabWidget]: # uiType: QTabWidget tabCnt = ui_element.count() if uiList_lang_read[ui_name] != "": tabNameList = uiList_lang_read[ui_name].split(';') if len(tabNameList) == tabCnt: for i in range(tabCnt): if tabNameList[i] != "": ui_element.setTabText(i,tabNameList[i]) elif type(ui_element) == str: # uiType: string for msg if uiList_lang_read[ui_name] != "": self.uiList[ui_name] = uiList_lang_read[ui_name]
def __init__(self): super(MatcherUI, self).__init__() self.setWindowTitle("Matcher") self.resize(230, 180) self.layout = QtGui.QVBoxLayout(self) label = QtGui.QLabel("Match attributes\nbetween objects") separator = HSeparator() self.name = QtGui.QCheckBox("Name") self.color = QtGui.QCheckBox("Color") self.position = QtGui.QCheckBox("Position") self.rotation = QtGui.QCheckBox("Rotation") self.ref = QtGui.QCheckBox("Ref") separator2 = HSeparator() self.button = QtGui.QPushButton("Apply") self.layout.addWidget(label) self.layout.addWidget(separator) self.layout.addWidget(self.name) self.layout.addWidget(self.color) self.layout.addWidget(self.position) self.layout.addWidget(self.rotation) self.layout.addWidget(self.ref) self.layout.addWidget(separator2) self.layout.addWidget(self.button)
def create_check_setting(self, name): hlayout = QtGui.QHBoxLayout() setting = self.get_setting(name) check = QtGui.QCheckBox() check.setObjectName(setting.name) check.clicked.connect(self.call_with_object('setting_changed', check, setting)) check.setChecked(setting.value) check.setStatusTip(setting.description) check.setToolTip(setting.description) hlayout.addWidget(check) return hlayout
def setLang(self, langName): uiList_lang_read = self.memoData['lang'][langName] for ui_name in uiList_lang_read: 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 if uiList_lang_read[ui_name] != "": ui_element.setText(uiList_lang_read[ui_name]) elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]: # uiType: QMenu, QGroupBox if uiList_lang_read[ui_name] != "": ui_element.setTitle(uiList_lang_read[ui_name]) elif type(ui_element) in [ QtWidgets.QTabWidget]: # uiType: QTabWidget tabCnt = ui_element.count() if uiList_lang_read[ui_name] != "": tabNameList = uiList_lang_read[ui_name].split(';') if len(tabNameList) == tabCnt: for i in range(tabCnt): if tabNameList[i] != "": ui_element.setTabText(i,tabNameList[i]) elif type(ui_element) == str: # uiType: string for msg if uiList_lang_read[ui_name] != "": self.uiList[ui_name] = uiList_lang_read[ui_name]
def createIconGroupBox(self): self.iconGroupBox = QtGui.QGroupBox("Tray Icon") self.iconLabel = QtGui.QLabel("Icon:") self.iconComboBox = QtGui.QComboBox() self.iconComboBox.addItem(QtGui.QIcon(':/icons/miner.svg'), "Miner") self.iconComboBox.addItem(QtGui.QIcon(':/images/heart.svg'), "Heart") self.iconComboBox.addItem(QtGui.QIcon(':/images/trash.svg'), "Trash") self.showIconCheckBox = QtGui.QCheckBox("Show icon") self.showIconCheckBox.setChecked(True) iconLayout = QtGui.QHBoxLayout() iconLayout.addWidget(self.iconLabel) iconLayout.addWidget(self.iconComboBox) iconLayout.addStretch() iconLayout.addWidget(self.showIconCheckBox) self.iconGroupBox.setLayout(iconLayout)
def __init__(self, model): super(PassiveEditWidget, self).__init__() self.__model = model self.__idx_to_wk = {} self.__wk_to_idx = {} self.cb_well_known = QtGui.QComboBox() self.layout.addRow("Package", self.cb_well_known) self.__add_wk(None, "Custom") self.cb_well_known.insertSeparator(self.cb_well_known.maxCount()) for v in well_known_chip: self.__add_wk(v) self.cb_well_known.currentIndexChanged.connect(self.pkg_changed) self.cb_well_known.setCurrentIndex(self.__wk_to_idx[self.__model.well_known]) self.pkg_changed(self.cb_well_known.currentIndex()) # Snap checkbox self.cb_snap = QtGui.QCheckBox() self.cb_snap.setChecked(self.__model.snap_well) self.layout.addRow("Snap to Well Known", self.cb_snap) self.gs = [ self.addEdit("Pad Centers", UnitEditable(self.__model, "pin_d", UNIT_GROUP_MM)), self.addEdit("Body length", PointUnitEditable(self.__model, "body_corner_vec", "x", UNIT_GROUP_MM)), self.addEdit("Body width", PointUnitEditable(self.__model, "body_corner_vec", "y", UNIT_GROUP_MM)), self.addEdit("Pad length", PointUnitEditable(self.__model, "pin_corner_vec", "x", UNIT_GROUP_MM)), self.addEdit("Pad width", PointUnitEditable(self.__model, "pin_corner_vec", "y", UNIT_GROUP_MM)), ]
def setupUi(self, sonosConnect): sonosConnect.setObjectName("sonosConnect") self.gridLayout = QtGui.QGridLayout(sonosConnect) self.connectList = QtGui.QListWidget(sonosConnect) QtGui.QListWidgetItem(self.connectList) self.gridLayout.addWidget(self.connectList, 0, 0, 1, 3) self.checkBox = QtGui.QCheckBox(sonosConnect) self.gridLayout.addWidget(self.checkBox, 2, 0, 1, 1) self.connectButton = QtGui.QPushButton(sonosConnect) self.gridLayout.addWidget(self.connectButton, 2, 2, 1, 1) self.rescanButton = QtGui.QPushButton(sonosConnect) self.gridLayout.addWidget(self.rescanButton, 2, 1, 1, 1) self.retranslateUi(sonosConnect) QtCore.QMetaObject.connectSlotsByName(sonosConnect)
def dialog(fn): w=QtGui.QWidget() box = QtGui.QVBoxLayout() w.setLayout(box) w.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) l=QtGui.QLabel("Path to Image" ) box.addWidget(l) w.anz = QtGui.QLineEdit() w.anz.setText(fn) box.addWidget(w.anz) loff=QtGui.QLabel("Offset Border" ) box.addWidget(loff) w.off = QtGui.QLineEdit() w.off.setText("100") box.addWidget(w.off) w.rotpos=QtGui.QCheckBox("Rot +90") box.addWidget(w.rotpos) w.rotneg=QtGui.QCheckBox("Rot -90") box.addWidget(w.rotneg) w.rot180=QtGui.QCheckBox("Rot 180") box.addWidget(w.rot180) w.r=QtGui.QPushButton("run") box.addWidget(w.r) w.r.pressed.connect(lambda :runw(w)) w.show() return w
def generateWidget( self, idGDT, ContainerOfData ): self.idGDT = idGDT self.ContainerOfData = ContainerOfData self.checkBox = QtGui.QCheckBox(self.Text) self.checkBox.setChecked(True) global checkBoxState checkBoxState = True hbox = QtGui.QHBoxLayout() hbox.addWidget(self.checkBox) hbox.addStretch(1) self.checkBox.stateChanged.connect(self.updateState) return hbox
def __init__(self): rv.rvtypes.MinorMode.__init__(self) self.init("pyside_example", None, None) self.loader = QUiLoader() uifile = QFile(os.path.join(self.supportPath(pyside_example, "pyside_example"), "control.ui")) uifile.open(QFile.ReadOnly) self.dialog = self.loader.load(uifile) uifile.close() self.enableCheckBox = self.dialog.findChild(QCheckBox, "enableCheckBox") # # To retrieve the current RV session window and # use it as a Qt QMainWindow, we do the following: self.rvSessionQObject = rv.qtutils.sessionWindow() # have to hold refs here so they don't get deleted self.radialDistortDials = self.findSet(QDial, ["k1Dial", "k2Dial", "k3Dial"]) self.radialDistortSpins = self.findSet(QDoubleSpinBox, ["k1SpinBox", "k2SpinBox", "k3SpinBox"]) self.lastRadialDistort = [0,0,0] self.hookup(self.enableCheckBox, self.radialDistortSpins, self.radialDistortDials, "#RVLensWarp", self.lastRadialDistort)
def loadCategories(self): for i in range(self.categoriesTable.rowCount(), 0, -1): self.categoriesTable.removeRow(i - 1) ## self.tabs.setTabEnabled(1, True) for i in self.newDtabase.getElementsByTagName('categories')[0].getElementsByTagName('category'): rowNumber = self.categoriesTable.rowCount() self.categoriesTable.insertRow(rowNumber) ###### widgetActive = QtGui.QCheckBox('') widgetActive.setStyleSheet('margin-left:18px;') self.categoriesTable.setCellWidget(rowNumber, 0, widgetActive) # itemID = QtGui.QTableWidgetItem(i.getAttribute("number")) self.categoriesTable.setItem(rowNumber, 1, itemID) # itemName = QtGui.QTableWidgetItem(i.getAttribute("name")) self.categoriesTable.setItem(rowNumber, 2, itemName) # try: cDescription = i.firstChild.data except: cDescription = '' itemDescription = QtGui.QTableWidgetItem(cDescription) self.categoriesTable.setItem(rowNumber, 3, itemDescription) # new category widgetAction = QtGui.QComboBox() widgetAction.addItem('New category', [-1, '']) # new category # nr = 1 for j, k in readCategories().items(): widgetAction.addItem('Move all objects to existing category: {0}'.format(k[0]), [j, k[0]]) if k[0] == i.getAttribute("name"): widgetAction.setCurrentIndex(nr) nr += 1 self.categoriesTable.setCellWidget(rowNumber, 4, widgetAction)
def exportUstawienia(self): page = QtGui.QWizardPage() page.setSubTitle(u"<span style='font-weight:bold;font-size:13px;'>Settings</span>") # 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) # self.addHoles = QtGui.QCheckBox(u'Add holes') self.addDimensions = QtGui.QCheckBox(u'Add dimensions') self.addAnnotations = QtGui.QCheckBox(u'Add annotations') self.addGluePaths = QtGui.QCheckBox(u'Export glue paths') # lay = QtGui.QGridLayout(page) lay.addWidget(QtGui.QLabel(u'Path: '), 0, 0, 1, 1) lay.addWidget(self.pathToFile, 0, 1, 1, 1) lay.addWidget(zmianaSciezki, 0, 2, 1, 1) lay.addItem(QtGui.QSpacerItem(1, 10), 1, 0, 1, 3) lay.addWidget(self.addHoles, 2, 0, 1, 3) lay.addWidget(self.addDimensions, 3, 0, 1, 3) lay.addWidget(self.addAnnotations, 4, 0, 1, 3) lay.addWidget(self.addGluePaths, 5, 0, 1, 3) lay.setColumnStretch(1, 6) return page
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) # self.form = self self.form.setWindowTitle(u'Check collisions') self.form.setWindowIcon(QtGui.QIcon(":/data/img/collisions.png")) self.root = None self.obj = None self.tmpFile = None self.transaprency = {} # self.createSolid = QtGui.QCheckBox(u'Create solid on exit') # self.table1 = collisionObjectTable() # self.table2 = collisionObjectTable() # checkButton = QtGui.QPushButton(u"Check") self.connect(checkButton, QtCore.SIGNAL("released ()"), self.preview) # lay = QtGui.QGridLayout(self) lay.addWidget(checkButton, 0, 0, 1, 2) lay.addWidget(QtGui.QLabel(u'First group'), 1, 0, 1, 1) lay.addWidget(self.table1, 2, 0, 1, 1) lay.addWidget(QtGui.QLabel(u'Second group'), 1, 1, 1, 1) lay.addWidget(self.table2, 2, 1, 1, 1) lay.addWidget(self.createSolid, 3, 0, 1, 2) # self.readObjects() self.removeRoot()
def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle("Convert old database to a new format") self.setMinimumWidth(500) # stary plik z modelami self.oldFilePath = QtGui.QLineEdit(os.path.join(__currentPath__, "param.py")) # nowy plik z modelami self.newFilePath = QtGui.QLineEdit(os.path.join(__currentPath__, "data/dane.cfg")) # self.pominDuplikaty = QtGui.QCheckBox(u"Skip duplicates") self.pominDuplikaty.setChecked(True) self.pominDuplikaty.setDisabled(True) # self.removeOld = QtGui.QCheckBox(u"Remove old database") self.removeOld.setChecked(True) # przyciski buttons = QtGui.QDialogButtonBox() buttons.addButton("Cancel", QtGui.QDialogButtonBox.RejectRole) buttons.addButton("Convert", QtGui.QDialogButtonBox.AcceptRole) self.connect(buttons, QtCore.SIGNAL("accepted()"), self.konwertuj) self.connect(buttons, QtCore.SIGNAL("rejected()"), self, QtCore.SLOT("reject()")) # self.mainLayout = QtGui.QGridLayout(self) #self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(QtGui.QLabel(u"Old database"), 0, 0, 1, 1) self.mainLayout.addWidget(self.oldFilePath, 0, 1, 1, 1) self.mainLayout.addWidget(QtGui.QLabel(u"New database"), 1, 0, 1, 1) self.mainLayout.addWidget(self.newFilePath, 1, 1, 1, 1) self.mainLayout.addWidget(self.pominDuplikaty, 3, 0, 1, 2) self.mainLayout.addWidget(self.removeOld, 4, 0, 1, 2) self.mainLayout.addWidget(buttons, 5, 1, 1, 1, QtCore.Qt.AlignRight) self.mainLayout.setRowStretch(6, 10)
def spisWarstwAddRow(self, ID, layerColor, layerTransparent, layerName): self.spisWarstw.insertRow(self.spisWarstw.rowCount()) check = QtGui.QCheckBox() check.setStyleSheet("QCheckBox {margin:7px;}") self.spisWarstw.setCellWidget(self.spisWarstw.rowCount() - 1, 0, check) # num = QtGui.QTableWidgetItem(str(ID)) num.setTextAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter) self.spisWarstw.setItem(self.spisWarstw.rowCount() - 1, 1, num) # if layerColor: color = kolorWarstwy() color.setColor(layerColor) color.setToolTip(u"Click to change color") else: color = QtGui.QLabel("") self.spisWarstw.setCellWidget(self.spisWarstw.rowCount() - 1, 2, color) # if layerTransparent: if layerTransparent[0] == 'int': transparent = transpSpinBox() else: transparent = transpDoubleSpinBox() transparent.setRange(layerTransparent[3], layerTransparent[4]) transparent.setSuffix(layerTransparent[1]) transparent.setValue(layerTransparent[2]) else: transparent = QtGui.QLabel("") self.spisWarstw.setCellWidget(self.spisWarstw.rowCount() - 1, 3, transparent) # name = QtGui.QTableWidgetItem(layerName) name.setTextAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) name.setToolTip(u"Click to change name") self.spisWarstw.setItem(self.spisWarstw.rowCount() - 1, 4, name)
def build_ui(self): self.setLayout(QtGui.QVBoxLayout()) self.label = QtGui.QLabel("some label") self.btn = QtGui.QPushButton("button") self.lineedit = QtGui.QLineEdit() self.textedit = QtGui.QTextEdit() self.grp = QtGui.QGroupBox("group box grid layout") self.grp.setLayout(QtGui.QGridLayout()) self.chkbx_1 = QtGui.QCheckBox("chkbx_1") self.chkbx_2 = QtGui.QCheckBox("chkbx_2l") self.chkbx_2.setDisabled(True) self.chkbx_3 = QtGui.QCheckBox("chkbx_2r") self.chkbx_4 = QtGui.QCheckBox("chkbx_3") self.chkbx_5 = QtGui.QCheckBox("chkbx_4") self.grp.layout().addWidget(self.chkbx_1, 0, 0) self.grp.layout().addWidget(self.chkbx_2, 1, 0) self.grp.layout().addWidget(self.chkbx_3, 1, 1) self.grp.layout().addWidget(self.chkbx_4, 2, 0) self.grp.layout().addWidget(self.chkbx_5, 3, 0) self.grp.layout().setColumnStretch(2,1) self.lrbox = QtGui.QHBoxLayout() self.lrbox.addWidget(self.textedit) self.lrbox.addWidget(self.grp) self.layout().addWidget(self.label) self.layout().addWidget(self.btn) self.layout().addWidget(self.lineedit) self.layout().addLayout(self.lrbox)
def setLang(self, langName): lang_data = self.memoData['lang'][langName] for ui_name in lang_data.keys(): if ui_name in self.uiList.keys() and lang_data[ui_name] != '': ui_element = self.uiList[ui_name] # '' means no translation availdanle in that data file if isinstance(ui_element, (QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox) ): # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox ui_element.setText(lang_data[ui_name]) elif isinstance(ui_element, (QtWidgets.QGroupBox, QtWidgets.QMenu) ): # uiType: QMenu, QGroupBox ui_element.setTitle(lang_data[ui_name]) elif isinstance(ui_element, QtWidgets.QTabWidget): # uiType: QTabWidget tabCnt = ui_element.count() tabNameList = lang_data[ui_name].split(';') if len(tabNameList) == tabCnt: for i in range(tabCnt): if tabNameList[i] != '': ui_element.setTabText(i,tabNameList[i]) elif isinstance(ui_element, QtWidgets.QComboBox): # uiType: QComboBox itemCnt = ui_element.count() itemNameList = lang_data[ui_name].split(';') ui_element.clear() ui_element.addItems(itemNameList) elif isinstance(ui_element, QtWidgets.QTreeWidget): # uiType: QTreeWidget labelCnt = ui_element.headerItem().columnCount() labelList = lang_data[ui_name].split(';') ui_element.setHeaderLabels(labelList) elif isinstance(ui_element, QtWidgets.QTableWidget): # uiType: QTableWidget colCnt = ui_element.columnCount() headerList = lang_data[ui_name].split(';') cur_table.setHorizontalHeaderLabels( headerList ) elif isinstance(ui_element, (str, unicode) ): # uiType: string for msg self.uiList[ui_name] = lang_data[ui_name]
def loadLang(self): 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.readRawFile( os.path.join(lang_path,fileName) ) self.quickMenuAction(langName+'_atnLang', langName.upper(),'',langName + '.png', cur_menu) self.uiList[langName+'_atnLang'].triggered.connect(partial(self.setLang,langName)) # if no language file detected, add export default language option if len(self.memoData['lang']) == 1: self.quickMenuAction('langExport_atnLang', 'Export Default Language','','langExport.png', cur_menu) self.uiList['langExport_atnLang'].triggered.connect(self.exportLang)
def loadLang(self): self.quickMenu(['language_menu;&Language']) cur_menu = self.uiList['language_menu'] self.quickMenuAction('langDefault_atnLang', 'Default','','langDefault.png', cur_menu) cur_menu.addSeparator() QtCore.QObject.connect( self.uiList['langDefault_atnLang'], QtCore.SIGNAL("triggered()"), 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 [ QtGui.QLabel, QtGui.QPushButton, QtGui.QAction, QtGui.QCheckBox ]: # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox self.memoData['lang']['default'][ui_name] = str(ui_element.text()) elif type(ui_element) in [ QtGui.QGroupBox, QtGui.QMenu ]: # uiType: QMenu, QGroupBox self.memoData['lang']['default'][ui_name] = str(ui_element.title()) elif type(ui_element) in [ QtGui.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.readRawFile( os.path.join(lang_path,fileName) ) self.quickMenuAction(langName+'_atnLang', langName.upper(),'',langName + '.png', cur_menu) QtCore.QObject.connect( self.uiList[langName+'_atnLang'], QtCore.SIGNAL("triggered()"), partial(self.setLang, langName) ) # if no language file detected, add export default language option if len(self.memoData['lang']) == 1: self.quickMenuAction('langExport_atnLang', 'Export Default Language','','langExport.png', cur_menu) QtCore.QObject.connect( self.uiList['langExport_atnLang'], QtCore.SIGNAL("triggered()"), self.exportLang )
def setAttributes(self): for attr in self.attributes: qw = self.__getattribute__(attr) if isinstance(qw, QtGui.QCheckBox): value = qw.isChecked() elif isinstance(qw, QtGui.QLineEdit): value = str(qw.text()) else: value = qw.value() config.__setattr__(attr, value) config.saveConfig()
def dialog(): w=QtGui.QWidget() box = QtGui.QVBoxLayout() w.setLayout(box) w.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) l=QtGui.QLabel("Anzahl" ) w.l=l box.addWidget(l) w.mina = QtGui.QLabel("Anzahl" ) w.mina.setText('3') box.addWidget(w.mina) w.anz = QtGui.QLabel("Anzahl" ) w.anz.setText('13') box.addWidget(w.anz) w.maxa = QtGui.QLabel("Anzahl" ) w.maxa.setText('3') box.addWidget(w.maxa) # w.random=QtGui.QCheckBox("Zufall") # box.addWidget(w.random) # w.r=QtGui.QPushButton("run") # box.addWidget(w.r) # w.r.pressed.connect(lambda :run(w)) w.show() return w
def create_item(self, widget_config, grid, row_index): widget_config.widget_title = QtGui.QLabel(self.form) widget_config.widget_title.setText("%s : " % widget_config.show_name) if widget_config.type == float and not hasattr(widget_config, 'step'): widget_config.widget = QtGui.QLabel(self.form) widget_config.widget.setText("%f" % self.get_property_value(widget_config.name)) elif widget_config.type == float: widget_config.widget = QtGui.QDoubleSpinBox(self.form) widget_config.widget.setDecimals(widget_config.decimals) widget_config.widget.setSingleStep(widget_config.step) widget_config.widget.setMinimum(widget_config.interval_value[0]) widget_config.widget.setValue(self.get_property_value(widget_config.name)) widget_config.widget.setMaximum(widget_config.interval_value[-1]) elif widget_config.type == bool: widget_config.widget = QtGui.QCheckBox("", self.form) state = QtCore.Qt.Checked if self.get_property_value(widget_config.name) == True else QtCore.Qt.Unchecked widget_config.widget.setCheckState(state) elif widget_config.type == list: widget_config.widget = QtGui.QComboBox(self.form) widget_config.widget.addItems(widget_config.interval_value) default_value_index = 0 for str_value in widget_config.interval_value: if self.get_property_value(widget_config.name) == str_value: break default_value_index += 1 if default_value_index == len(widget_config.interval_value): raise ValueError("Default value not found for list" + widget_config.name) widget_config.widget.setCurrentIndex(default_value_index) widget_config.widget.currentIndexChanged.connect(self.listchangeIndex) elif widget_config.type == str: widget_config.widget = QtGui.QLineEdit(self.form) widget_config.widget.setText(self.get_property_value(widget_config.name)) else: raise ValueError("Undefined widget type") grid.addWidget(widget_config.widget_title, row_index, 0) grid.addWidget(widget_config.widget, row_index, 1)
def showNotes(self,*args): while self.checksVLayout.count(): child = self.checksVLayout.takeAt(0) if child.widget() is not None: child.widget().deleteLater() elif child.layout() is not None: clearLayout(child.layout()) #self.notesTextEdit.setPlainText("") if self.selShot in self.shotgunNotes.keys(): for note in self.shotgunNotes[self.selShot]: nId,noteContent=note.split('###') #self.notesTextEdit.insertPlainText(note+"\n") self.notesCheck = QtGui.QCheckBox(noteContent,self.notesTab) self.notesCheck.setObjectName(nId) self.checksVLayout.addWidget(self.notesCheck)
def __init__(self, model, attr): self.widget = QtGui.QCheckBox() self.model = model self.attr = attr self.widget.setChecked(getattr(self.model, self.attr))
def setupUi(self, Form): Form.setObjectName("Form") Form.resize(186, 154) Form.setMaximumSize(QtCore.QSize(200, 16777215)) self.gridLayout = QtGui.QGridLayout(Form) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setSpacing(0) self.gridLayout.setObjectName("gridLayout") self.label = QtGui.QLabel(Form) self.label.setObjectName("label") self.gridLayout.addWidget(self.label, 7, 0, 1, 2) self.linkCombo = QtGui.QComboBox(Form) self.linkCombo.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.linkCombo.setObjectName("linkCombo") self.gridLayout.addWidget(self.linkCombo, 7, 2, 1, 2) self.autoPercentSpin = QtGui.QSpinBox(Form) self.autoPercentSpin.setEnabled(True) self.autoPercentSpin.setMinimum(1) self.autoPercentSpin.setMaximum(100) self.autoPercentSpin.setSingleStep(1) self.autoPercentSpin.setProperty("value", 100) self.autoPercentSpin.setObjectName("autoPercentSpin") self.gridLayout.addWidget(self.autoPercentSpin, 2, 2, 1, 2) self.autoRadio = QtGui.QRadioButton(Form) self.autoRadio.setChecked(True) self.autoRadio.setObjectName("autoRadio") self.gridLayout.addWidget(self.autoRadio, 2, 0, 1, 2) self.manualRadio = QtGui.QRadioButton(Form) self.manualRadio.setObjectName("manualRadio") self.gridLayout.addWidget(self.manualRadio, 1, 0, 1, 2) self.minText = QtGui.QLineEdit(Form) self.minText.setObjectName("minText") self.gridLayout.addWidget(self.minText, 1, 2, 1, 1) self.maxText = QtGui.QLineEdit(Form) self.maxText.setObjectName("maxText") self.gridLayout.addWidget(self.maxText, 1, 3, 1, 1) self.invertCheck = QtGui.QCheckBox(Form) self.invertCheck.setObjectName("invertCheck") self.gridLayout.addWidget(self.invertCheck, 5, 0, 1, 4) self.mouseCheck = QtGui.QCheckBox(Form) self.mouseCheck.setChecked(True) self.mouseCheck.setObjectName("mouseCheck") self.gridLayout.addWidget(self.mouseCheck, 6, 0, 1, 4) self.visibleOnlyCheck = QtGui.QCheckBox(Form) self.visibleOnlyCheck.setObjectName("visibleOnlyCheck") self.gridLayout.addWidget(self.visibleOnlyCheck, 3, 2, 1, 2) self.autoPanCheck = QtGui.QCheckBox(Form) self.autoPanCheck.setObjectName("autoPanCheck") self.gridLayout.addWidget(self.autoPanCheck, 4, 2, 1, 2) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def dialog(points): print "dialog ",points.Label w=QtGui.QWidget() w.source=points box = QtGui.QVBoxLayout() w.setLayout(box) w.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) l=QtGui.QLabel("Model" ) box.addWidget(l) w.mode = QtGui.QListWidget() w.mode.addItems( ['linear','thin_plate', 'cubic','inverse','multiquadric','gaussian' ,'quintic' ]) box.addWidget(w.mode) l=QtGui.QLabel("count grid lines" ) box.addWidget(l) w.grid = QtGui.QLineEdit() w.grid.setText('20') box.addWidget(w.grid) l=QtGui.QLabel("z-scale factor" ) box.addWidget(l) w.zfac = QtGui.QLineEdit() w.zfac.setText('10') box.addWidget(w.zfac) l=QtGui.QLabel("z-max " ) box.addWidget(l) w.zmax = QtGui.QLineEdit() w.zmax.setText('0') box.addWidget(w.zmax) w.matplot=QtGui.QCheckBox("show Matplot") box.addWidget(w.matplot) w.colormap=QtGui.QCheckBox("show colors") box.addWidget(w.colormap) # h=QtGui.QDial() # h.setMaximum(100) # h.setMinimum(0) # w.ha=h # box.addWidget(h) w.r=QtGui.QPushButton("run") box.addWidget(w.r) w.r.pressed.connect(lambda :srun(w)) w.show() return w
def findEntries(self): for i in range(self.categoriesTable.rowCount(), 0, -1): self.categoriesTable.removeRow(i - 1) ## self.sql.reloadList() for i in self.sql.packages(): dane = self.sql.getValues(i) software = eval(dane["soft"]) for j in software: if j[1] == self.fromSoftware.currentText(): rowNumber = self.categoriesTable.rowCount() self.categoriesTable.insertRow(rowNumber) # widgetActive = QtGui.QCheckBox('') widgetActive.setStyleSheet('margin-left:18px;') self.categoriesTable.setCellWidget(rowNumber, 0, widgetActive) # item0 = QtGui.QTableWidgetItem(i) self.categoriesTable.setItem(rowNumber, 1, item0) # item1 = QtGui.QTableWidgetItem(dane["name"]) item1.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.categoriesTable.setItem(rowNumber, 2, item1) # item2 = QtGui.QTableWidgetItem(j[0]) self.categoriesTable.setItem(rowNumber, 3, item2) # itemCat = QtGui.QTableWidgetItem(readCategories()[int(dane['category'])][0]) itemCat.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.categoriesTable.setItem(rowNumber, 4, itemCat) # item3 = QtGui.QTableWidgetItem(str(j[2])) item3.setTextAlignment(QtCore.Qt.AlignCenter) self.categoriesTable.setItem(rowNumber, 5, item3) # item4 = QtGui.QTableWidgetItem(str(j[3])) item4.setTextAlignment(QtCore.Qt.AlignCenter) self.categoriesTable.setItem(rowNumber, 6, item4) # item5 = QtGui.QTableWidgetItem(str(j[4])) item5.setTextAlignment(QtCore.Qt.AlignCenter) self.categoriesTable.setItem(rowNumber, 7, item5) # item6 = QtGui.QTableWidgetItem(str(j[5])) item6.setTextAlignment(QtCore.Qt.AlignCenter) self.categoriesTable.setItem(rowNumber, 8, item6) # item7 = QtGui.QTableWidgetItem(str(j[6])) item7.setTextAlignment(QtCore.Qt.AlignCenter) self.categoriesTable.setItem(rowNumber, 9, item7) # item8 = QtGui.QTableWidgetItem(str(j[7])) item8.setTextAlignment(QtCore.Qt.AlignCenter) self.categoriesTable.setItem(rowNumber, 10, item8)
def addRow(self, rowType): self.insertRow(self.rowCount()) row = self.rowCount() - 1 b = QtGui.QCheckBox("") b.setToolTip(u"Active") self.setCellWidget(row, 0, b) a = QtGui.QTableWidgetItem(rowType) a.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.setItem(row, 1, a) c = QtGui.QComboBox() c.addItems(["True", "False"]) self.setCellWidget(row, 2, c) d = QtGui.QDoubleSpinBox() d.setSingleStep(0.1) d.setRange(-1000, 1000) d.setSuffix("mm") self.setCellWidget(row, 3, d) e = QtGui.QDoubleSpinBox() e.setSingleStep(0.1) e.setRange(-1000, 1000) e.setSuffix("mm") self.setCellWidget(row, 4, e) f = QtGui.QDoubleSpinBox() f.setSingleStep(0.1) f.setRange(-1000, 1000) f.setSuffix("mm") self.setCellWidget(row, 5, f) g = QtGui.QDoubleSpinBox() g.setSingleStep(0.1) g.setValue(1.27) g.setSuffix("mm") self.setCellWidget(row, 6, g) color = kolorWarstwy() color.setToolTip(u"Click to change color") self.setCellWidget(row, 7, color) i = QtGui.QComboBox() i.addItems(["bottom-left", "bottom-center", "bottom-right", "center-left", "center", "center-right", "top-left", "top-center", "top-right"]) i.setCurrentIndex(4) self.setCellWidget(row, 8, i) # self.setColumnWidth(0, 25)
def __init__(self, session, **kwargs): """ A widget to show solve options when determining the stellar parameters. :param session: A session. """ super(SolveOptionsDialog, self).__init__(**kwargs) self.session = session # Display dialog in center and set size policy. self.setGeometry(640, 480, 640, 480) self.move(QtGui.QApplication.desktop().screen().rect().center() \ - self.rect().center()) self.setWindowTitle("Solve options for stellar parameter determination") sp = QtGui.QSizePolicy( QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.MinimumExpanding) sp.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(sp) vbox = QtGui.QVBoxLayout(self) self.check_use_uncertainties_in_line_fits = QtGui.QCheckBox(self) self.check_use_uncertainties_in_line_fits.setText( "Use abundance uncertainties in line fits") vbox.addWidget(self.check_use_uncertainties_in_line_fits) vbox.addItem(QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)) hbox = QtGui.QHBoxLayout() self.btn_save_as_default = QtGui.QPushButton(self) self.btn_save_as_default.setText("Save settings as default") self.btn_save_as_default.clicked.connect(self.save_as_default) hbox.addWidget(self.btn_save_as_default) hbox.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)) self.btn_apply = QtGui.QPushButton(self) self.btn_apply.setText("Apply") self.btn_apply.setDefault(True) self.btn_apply.clicked.connect(self.apply) hbox.addWidget(self.btn_apply) self.btn_cancel = QtGui.QPushButton(self) self.btn_cancel.setText("Cancel") self.btn_cancel.clicked.connect(self.close) hbox.addWidget(self.btn_cancel) vbox.addLayout(hbox) self.populate_widgets() return None
def createWidgets(self): mainVLayout = QtGui.QVBoxLayout() fileFLayout = QtGui.QFormLayout() self.exportPath = QtGui.QLineEdit(self) self.exportPath.setText(config.tiltBrushExportDir) fileFLayout.addRow('Exported Files path: ', self.exportPath) self.outputPath = QtGui.QLineEdit(self) self.outputPath.setText(config.tiltBrushExportDir) fileFLayout.addRow('Output path: ', self.outputPath) mainVLayout.addLayout(fileFLayout) self.updateListButton = QtGui.QPushButton(self) self.updateListButton.setText("Update List") mainVLayout.addWidget(self.updateListButton) optionsHLayout = QtGui.QHBoxLayout() optionsFLayout1 = QtGui.QFormLayout() self.add_backface = QtGui.QCheckBox(self) optionsFLayout1.addRow("Add Backface: ", self.add_backface) self.weld_verts = QtGui.QCheckBox(self) optionsFLayout1.addRow("Weld Vertices: ", self.weld_verts) optionsFLayout2 = QtGui.QFormLayout() self.merge_stroke = QtGui.QCheckBox(self) optionsFLayout2.addRow("Merge Strokes: ", self.merge_stroke) self.merge_brush = QtGui.QCheckBox(self) self.merge_brush.setChecked(True) optionsFLayout2.addRow("Merge Brushes: ", self.merge_brush) optionsHLayout.addLayout(optionsFLayout1) optionsHLayout.addLayout(optionsFLayout2) mainVLayout.addLayout(optionsHLayout) listVLayout = QtGui.QVBoxLayout() listVLayout.addWidget(QtGui.QLabel('Exported Files:')) self.jsonFiles = QListWidget(parent=self) listVLayout.addWidget(self.jsonFiles) mainVLayout.addLayout(listVLayout) self.convertButton = QtGui.QPushButton(self) self.convertButton.setText('Convert') mainVLayout.addWidget(self.convertButton) self.setLayout(mainVLayout)
def createWidgets(self): mainVLayout = QtGui.QVBoxLayout() fileFLayout = QtGui.QFormLayout() self.exportPath = QtGui.QLineEdit(self) self.exportPath.setText(config.tiltBrushExportDir) fileFLayout.addRow('Exported Files path: ', self.exportPath) self.outputPath = QtGui.QLineEdit(self) self.outputPath.setText(config.tiltBrushExportDir) fileFLayout.addRow('Output path: ', self.outputPath) mainVLayout.addLayout(fileFLayout) self.updateListButton = QtGui.QPushButton(self) self.updateListButton.setText("Update List") mainVLayout.addWidget(self.updateListButton) optionsFLayout = QtGui.QFormLayout() self.cooked = QtGui.QCheckBox(self) self.cooked.setChecked(True) optionsFLayout.addRow("Cook meshes: ", self.cooked) mainVLayout.addLayout(optionsFLayout) listVLayout = QtGui.QVBoxLayout() listVLayout.addWidget(QtGui.QLabel('Exported Files:')) self.jsonFiles = QListWidget(parent=self) listVLayout.addWidget(self.jsonFiles) mainVLayout.addLayout(listVLayout) self.convertButton = QtGui.QPushButton(self) self.convertButton.setText('Convert') mainVLayout.addWidget(self.convertButton) self.setLayout(mainVLayout)
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)
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', '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)
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 = {} #------------------------------
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 __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.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 = {} #------------------------------
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', 'txt': 'QTextEdit', 'list': 'QListWidget', '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)