class CueSettings(QDialog): on_apply = QtCore.pyqtSignal(dict) def __init__(self, widgets=[], cue=None, check=False, **kwargs): super().__init__(**kwargs) conf = {} if(cue is not None): conf = deepcopy(cue.properties()) self.setWindowTitle(conf['name']) self.setWindowModality(QtCore.Qt.ApplicationModal) self.setMaximumSize(635, 530) self.setMinimumSize(635, 530) self.resize(635, 530) self.sections = QTabWidget(self) self.sections.setGeometry(QtCore.QRect(5, 10, 625, 470)) wsize = QtCore.QSize(625, 470 - self.sections.tabBar().height()) for widget in widgets: widget = widget(wsize, cue) widget.set_configuration(conf) widget.enable_check(check) self.sections.addTab(widget, widget.Name) self.dialogButtons = QDialogButtonBox(self) self.dialogButtons.setGeometry(10, 490, 615, 30) self.dialogButtons.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok | QDialogButtonBox.Apply) self.dialogButtons.rejected.connect(self.reject) self.dialogButtons.accepted.connect(self.accept) apply = self.dialogButtons.button(QDialogButtonBox.Apply) apply.clicked.connect(self.apply) def accept(self): self.apply() super().accept() def apply(self): new_conf = {} for n in range(self.sections.count()): deep_update(new_conf, self.sections.widget(n).get_configuration()) self.on_apply.emit(new_conf)
class AppSettings(QDialog): SettingsWidgets = [] def __init__(self, conf, **kwargs): super().__init__(**kwargs) self.conf = conf self.setWindowTitle('LiSP preferences') self.setWindowModality(QtCore.Qt.ApplicationModal) self.setMaximumSize(635, 530) self.setMinimumSize(635, 530) self.resize(635, 530) self.listWidget = QListWidget(self) self.listWidget.setGeometry(QtCore.QRect(5, 10, 185, 470)) self.sections = QStackedWidget(self) self.sections.setGeometry(QtCore.QRect(200, 10, 430, 470)) for widget in self.SettingsWidgets: widget = widget(QtCore.QSize(430, 465), self) widget.set_configuration(self.conf) self.listWidget.addItem(widget.NAME) self.sections.addWidget(widget) if len(self.SettingsWidgets) > 0: self.listWidget.setCurrentRow(0) self.listWidget.currentItemChanged.connect(self._change_page) self.dialogButtons = QDialogButtonBox(self) self.dialogButtons.setGeometry(10, 495, 615, 30) self.dialogButtons.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.dialogButtons.rejected.connect(self.reject) self.dialogButtons.accepted.connect(self.accept) def get_configuraton(self): conf = {} for n in range(self.sections.count()): widget = self.sections.widget(n) newconf = widget.get_configuration() deep_update(conf, newconf) return conf @classmethod def register_settings_widget(cls, widget): if widget not in cls.SettingsWidgets: cls.SettingsWidgets.append(widget) @classmethod def unregister_settings_widget(cls, widget): if widget not in cls.SettingsWidgets: cls.SettingsWidgets.remove(widget) def _change_page(self, current, previous): if not current: current = previous self.sections.setCurrentIndex(self.listWidget.row(current))
class Ui_DialogSettings(QWidget): def __init__(self, parent, transaction_file_name, transaction_file_name_v2, main_folder_name, distribution_file_name, settings_file): super().__init__() self.parent = parent self.transaction_file_name = transaction_file_name self.transaction_file_name_v2 = transaction_file_name_v2 self.distribution_file_name = distribution_file_name self.main_folder_name = main_folder_name self.settings_file = settings_file def setupUi(self, dialog): dialog.setObjectName("Dialog") dialog.resize(500, 155) self.gridLayoutWidget_2 = QWidget(dialog) self.gridLayoutWidget_2.setGeometry(QRect(5, 5, 490, 100)) self.gridLayoutWidget_2.setObjectName("gridLayoutWidget_2") self.gridLayout_3 = QGridLayout(self.gridLayoutWidget_2) self.gridLayout_3.setContentsMargins(0, 0, 0, 0) self.gridLayout_3.setObjectName("gridLayout_3") self.companies_label = QLabel(self.gridLayoutWidget_2) self.companies_label.setObjectName("label_4") self.gridLayout_3.addWidget(self.companies_label, 0, 2, 1, 1) self.trans_label = QLabel(self.gridLayoutWidget_2) self.trans_label.setObjectName("label_8") self.trans_label_v2 = QLabel(self.gridLayoutWidget_2) self.trans_label_v2.setObjectName("label_8") self.main_folder_label = QLabel(self.gridLayoutWidget_2) self.main_folder_label.setObjectName("main_folder_label") self.gridLayout_3.addWidget(self.trans_label, 1, 2, 1, 1) self.gridLayout_3.addWidget(self.trans_label_v2, 2, 2, 1, 1) self.gridLayout_3.addWidget(self.main_folder_label, 3, 2, 1, 1) self.trans_file = QLineEdit(self.gridLayoutWidget_2) self.trans_file.setObjectName("trans_file") self.trans_file.setReadOnly(True) self.trans_file_v2 = QLineEdit(self.gridLayoutWidget_2) self.trans_file_v2.setObjectName("trans_file") self.trans_file_v2.setReadOnly(True) self.main_folder = QLineEdit(self.gridLayoutWidget_2) self.main_folder.setObjectName("main_folder") self.main_folder.setReadOnly(True) # self.gift_codes_button = QToolButton(self.gridLayoutWidget_2) # # iconfolder = QIcon() # # iconfolder.addPixmap(QPixmap("./icons/folder.svg"), QIcon.Normal, QIcon.Off) # # self.gift_codes_button.setIcon(iconfolder) # self.gift_codes_button.setObjectName("gift_codes_button") # # # self.gift_codes_button.clicked.connect(lambda: self._open_file_gifts_codes('main_folder')) #self.gridLayout_3.addWidget(self.gift_codes_button, 4, 1, 1, 1) self.gridLayout_3.addWidget(self.trans_file, 1, 1, 1, 1) self.gridLayout_3.addWidget(self.trans_file_v2, 2, 1, 1, 1) self.gridLayout_3.addWidget(self.main_folder, 3, 1, 1, 1) self.no_dist_file = QLineEdit(self.gridLayoutWidget_2) self.no_dist_file.setObjectName("no_dist_file") self.no_dist_file.setReadOnly(True) self.gridLayout_3.addWidget(self.no_dist_file, 0, 1, 1, 1) self.toolButton_5 = QToolButton(self.gridLayoutWidget_2) iconexcel = QIcon() iconexcel.addPixmap(QPixmap("./icons/excel.svg"), QIcon.Normal, QIcon.Off) self.toolButton_5.setIcon(iconexcel) self.toolButton_5.setObjectName("toolButton_5") self.gridLayout_3.addWidget(self.toolButton_5, 1, 0, 1, 1) self.toolButton_5.clicked.connect( lambda: self._open_file_dialog('trans')) self.trans_v2_button = QToolButton(self.gridLayoutWidget_2) self.trans_v2_button.setIcon(iconexcel) self.trans_v2_button.setObjectName("trans_v2_button") self.gridLayout_3.addWidget(self.trans_v2_button, 2, 0, 1, 1) self.trans_v2_button.clicked.connect( lambda: self._open_file_dialog('trans_v2')) self.main_folder_button = QToolButton(self.gridLayoutWidget_2) iconfolder = QIcon() iconfolder.addPixmap(QPixmap("./icons/folder.svg"), QIcon.Normal, QIcon.Off) self.main_folder_button.setIcon(iconfolder) self.main_folder_button.setObjectName("main_folder_button") self.gridLayout_3.addWidget(self.main_folder_button, 3, 0, 1, 1) self.main_folder_button.clicked.connect( lambda: self._open_file_dialog('main_folder')) self.toolButton_6 = QToolButton(self.gridLayoutWidget_2) self.toolButton_6.setIcon(iconexcel) self.toolButton_6.setObjectName("toolButton_6") self.gridLayout_3.addWidget(self.toolButton_6, 0, 0, 1, 1) self.toolButton_6.clicked.connect( lambda: self._open_file_dialog('no_dis')) self.gridLayout_3.addWidget(self.toolButton_6, 0, 0, 1, 1) self.buttonBox = QDialogButtonBox(dialog) self.buttonBox.setGeometry(QRect(150, 120, 341, 32)) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setObjectName("Save") self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") # init data self.no_dist_file.setText(self.distribution_file_name) self.trans_file.setText(self.transaction_file_name) self.trans_file_v2.setText(self.transaction_file_name_v2) self.main_folder.setText(self.main_folder_name) # Extract data self.buttonBox.accepted.connect(self.__save) self.buttonBox.rejected.connect(dialog.reject) QMetaObject.connectSlotsByName(dialog) self.retranslateUi(dialog) return self.gridLayoutWidget_2 def retranslateUi(self, dialog): _translate = QCoreApplication.translate dialog.setWindowTitle(_translate("Dialog", "הגדרת קבצים")) self.companies_label.setText(_translate("Dialog", "קובץ לא להפצה")) self.trans_label.setText(_translate("Dialog", "קובץ עסקאות 200")) self.trans_label_v2.setText(_translate("Dialog", "קובץ עסקאות 1220")) self.main_folder_label.setText(_translate("Dialog", "תיקיית חג ראשית")) def _open_file_dialog(self, name): options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog if name == "no_dis": file, _ = QFileDialog.getOpenFileName( self, "QFileDialog.getOpenFileName()", "", "Excel (*.csv)", options=options) self.no_dist_file.setText('{}'.format(file)) elif name == "trans": file, _ = QFileDialog.getOpenFileName( self, "QFileDialog.getOpenFileName()", "", "Excel (*.csv)", options=options) self.trans_file.setText('{}'.format(file)) elif name == "trans_v2": file, _ = QFileDialog.getOpenFileName( self, "QFileDialog.getOpenFileName()", "", "Excel (*.csv)", options=options) self.trans_file_v2.setText('{}'.format(file)) elif name == "main_folder": directory = str(QFileDialog.getExistingDirectory()) self.main_folder.setText('{}'.format(directory)) def __save(self): if self.no_dist_file.text() != "" and self.trans_file.text() != "" \ and self.trans_file_v2.text() != "" and self.main_folder.text() != "": buttonReply = QMessageBox.question( self, 'שמירת הגדרות', "האם אתה בטוח שאתה רוצה לשמור?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if buttonReply == QMessageBox.Yes: with open(self.settings_file) as json_file: settings = json.load(json_file) settings['קובץ לא להפצה'] = self.no_dist_file.text() settings['קובץ עסקאות'] = self.trans_file.text() settings['קובץ עסקאות 200'] = self.trans_file_v2.text() settings['תיקייה ראשית'] = self.main_folder.text() with open(self.settings_file, 'w') as outfile: json.dump(settings, outfile) QMessageBox.about(self, "נשמר בהצלחה", "הנתונים נשמרו בהצלחה, הפעל מחדש") print('Saved.')
class CueSettings(QDialog): on_apply = QtCore.pyqtSignal(dict) def __init__(self, cue=None, cue_class=None, **kwargs): """ :param cue: Target cue, or None for multi-editing :param cue_class: when cue is None, used to specify the reference class """ super().__init__(**kwargs) if cue is not None: cue_class = cue.__class__ cue_properties = deepcopy(cue.properties()) self.setWindowTitle(cue_properties['name']) else: cue_properties = {} if cue_class is None: cue_class = Cue self.setWindowModality(QtCore.Qt.ApplicationModal) self.setMaximumSize(635, 530) self.setMinimumSize(635, 530) self.resize(635, 530) self.sections = QTabWidget(self) self.sections.setGeometry(QtCore.QRect(5, 10, 625, 470)) for widget in sorted(CueSettingsRegistry().filter(cue_class), key=lambda w: w.Name): if issubclass(widget, CueSettingsPage): settings_widget = widget(cue_class) else: settings_widget = widget() settings_widget.load_settings(cue_properties) settings_widget.enable_check(cue is None) self.sections.addTab(settings_widget, settings_widget.Name) self.dialogButtons = QDialogButtonBox(self) self.dialogButtons.setGeometry(10, 490, 615, 30) self.dialogButtons.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok | QDialogButtonBox.Apply) self.dialogButtons.rejected.connect(self.reject) self.dialogButtons.accepted.connect(self.accept) apply = self.dialogButtons.button(QDialogButtonBox.Apply) apply.clicked.connect(self.apply) def accept(self): self.apply() super().accept() def apply(self): settings = {} for n in range(self.sections.count()): deep_update(settings, self.sections.widget(n).get_settings()) self.on_apply.emit(settings)
class CueSettings(QDialog): on_apply = QtCore.pyqtSignal(dict) def __init__(self, cue=None, cue_class=None, **kwargs): """ :param cue: Target cue, or None for multi-editing :param cue_class: when cue is None, used to specify the reference class """ super().__init__(**kwargs) if cue is not None: cue_class = cue.__class__ cue_properties = deepcopy(cue.properties()) self.setWindowTitle(cue_properties['name']) else: cue_properties = {} if cue_class is None: cue_class = Cue self.setWindowModality(QtCore.Qt.ApplicationModal) self.setMaximumSize(635, 530) self.setMinimumSize(635, 530) self.resize(635, 530) self.sections = QTabWidget(self) self.sections.setGeometry(QtCore.QRect(5, 10, 625, 470)) def sk(widget): # Sort-Key function return translate('SettingsPageName', widget.Name) for widget in sorted(CueSettingsRegistry().filter(cue_class), key=sk): if issubclass(widget, CueSettingsPage): settings_widget = widget(cue_class) else: settings_widget = widget() settings_widget.load_settings(cue_properties) settings_widget.enable_check(cue is None) self.sections.addTab(settings_widget, translate('SettingsPageName', settings_widget.Name)) self.dialogButtons = QDialogButtonBox(self) self.dialogButtons.setGeometry(10, 490, 615, 30) self.dialogButtons.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok | QDialogButtonBox.Apply) self.dialogButtons.rejected.connect(self.reject) self.dialogButtons.accepted.connect(self.accept) apply = self.dialogButtons.button(QDialogButtonBox.Apply) apply.clicked.connect(self.apply) def load_settings(self, settings): for n in range(self.sections.count()): self.sections.widget(n).load_settings(settings) def get_settings(self): settings = {} for n in range(self.sections.count()): deep_update(settings, self.sections.widget(n).get_settings()) return settings def apply(self): self.on_apply.emit(self.get_settings()) def accept(self): self.apply() super().accept()
class ColorMapsDialog(object): def __init__(self, title, message, items_selected, imageName): self.title = title self.message = message self.items_selected = items_selected #[s for s in items_selected.split(',')] self.imageName = imageName self.cmObj = ColorMaps() self.CM = self.cmObj.colorMaps form = QFormLayout() form.addRow(QLabel(message)) self.listView = QListView() form.addRow(self.listView) font = QFont() font.setBold(True) font.setPointSize(8) self.listView.setFont(font) model = QStandardItemModel(self.listView) size = QSize(60,30) for item in self.CM: # create an item with a caption standardItem = QStandardItem(item) standardItem.setCheckable(True) if item in self.items_selected: standardItem.setCheckState(True) standardItem.setSizeHint(size) model.appendRow(standardItem) self.listView.setModel(model) def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(530, 447) Dialog.setWindowTitle(self.title) self.buttonBox = QDialogButtonBox(Dialog) self.buttonBox.setGeometry(QRect(10, 390, 511, 32)) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.horizontalLayoutWidget = QWidget(Dialog) self.horizontalLayoutWidget.setGeometry(QRect(9, 10, 511, 363)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") self.horizontalLayout = QHBoxLayout(self.horizontalLayoutWidget) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("horizontalLayout") self.horizontalLayout.addWidget(self.listView) self.label = QLabel(self.horizontalLayoutWidget) self.label.setText("") self.label.setPixmap(QPixmap(self.imageName)) self.label.setAlignment(Qt.AlignCenter) self.label.setObjectName("label") self.horizontalLayout.addWidget(self.label) self.retranslateUi(Dialog) self.buttonBox.accepted.connect(Dialog.accept) self.buttonBox.rejected.connect(Dialog.reject) QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", self.title)) def itemsSelected(self): selected = [] model = self.listView.model() i = 0 while model.item(i): if model.item(i).checkState(): selected.append(model.item(i).text()) i += 1 return selected
class Ui_INI_Dialog(object): def setupUi(self, Dialog): self.source_dir = '' self.result_dir = '' self.color_map = '' self.scale = '' self.CM =['AUTUMN','BONE','JET','WINTER','RAINBOW','OCEAN', 'SUMMER','SPRING','COOL','HSV','PINK','HOT'] self.dataList = [*range(12)] Dialog.setObjectName("Dialog") Dialog.resize(446, 316) self.buttonBox = QDialogButtonBox(Dialog) self.buttonBox.setGeometry(QRect(20, 250, 381, 32)) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.gridLayoutWidget = QWidget(Dialog) self.gridLayoutWidget.setGeometry(QRect(20, 10, 381, 211)) self.gridLayoutWidget.setObjectName("gridLayoutWidget") self.gridLayout = QGridLayout(self.gridLayoutWidget) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setObjectName("gridLayout") self.sourceDirectoryLineEdit = QLineEdit(self.gridLayoutWidget) self.sourceDirectoryLineEdit.setObjectName("sourceDirectoryLineEdit") self.gridLayout.addWidget(self.sourceDirectoryLineEdit, 0, 1, 1, 1) self.resultDirectoryLineEdit = QLineEdit(self.gridLayoutWidget) self.resultDirectoryLineEdit.setObjectName("resultDirectoryLineEdit") self.gridLayout.addWidget(self.resultDirectoryLineEdit, 1, 1, 1, 1) self.resultsDirectoryLabel = QLabel(self.gridLayoutWidget) self.resultsDirectoryLabel.setObjectName("resultsDirectoryLabel") self.gridLayout.addWidget(self.resultsDirectoryLabel, 1, 0, 1, 1) self.sourceDirectoryToolButton = QToolButton(self.gridLayoutWidget) self.sourceDirectoryToolButton.setObjectName("sourceDirectoryToolButton") self.gridLayout.addWidget(self.sourceDirectoryToolButton, 0, 2, 1, 1) self.resultDirectoryToolButton = QToolButton(self.gridLayoutWidget) self.resultDirectoryToolButton.setObjectName("resultDirectoryToolButton") self.gridLayout.addWidget(self.resultDirectoryToolButton, 1, 2, 1, 1) self.scaleSpinBox = QDoubleSpinBox(self.gridLayoutWidget) self.scaleSpinBox.setMaximumSize(QSize(50, 20)) font = QFont() font.setBold(True) font.setWeight(75) self.scaleSpinBox.setFont(font) self.scaleSpinBox.setMinimum(0.01) self.scaleSpinBox.setMaximum(10.0) self.scaleSpinBox.setSingleStep(0.05) self.scaleSpinBox.setProperty("value", 1.0) self.scaleSpinBox.setObjectName("scaleSpinBox") self.gridLayout.addWidget(self.scaleSpinBox, 4, 1, 1, 1) self.sourceDirectoryLabel = QLabel(self.gridLayoutWidget) self.sourceDirectoryLabel.setObjectName("sourceDirectoryLabel") self.gridLayout.addWidget(self.sourceDirectoryLabel, 0, 0, 1, 1) self.scaleLabel = QLabel(self.gridLayoutWidget) self.scaleLabel.setObjectName("scaleLabel") self.gridLayout.addWidget(self.scaleLabel, 4, 0, 1, 1) self.colorMapLabel = QLabel(self.gridLayoutWidget) self.colorMapLabel.setObjectName("colorMapLabel") self.gridLayout.addWidget(self.colorMapLabel, 2, 0, 1, 1) self.CMcomboBox = CheckableComboBox(self.gridLayoutWidget) self.CMcomboBox.setObjectName("CMcomboBox") self.gridLayout.addWidget(self.CMcomboBox, 2, 1, 1, 1) self.retranslateUi(Dialog) self.buttonBox.accepted.connect(self.acceptAndSave) self.buttonBox.rejected.connect(Dialog.reject) QMetaObject.connectSlotsByName(Dialog) self.sourceDirectoryToolButton.clicked.connect(self._source_dir_dialog) self.resultDirectoryToolButton.clicked.connect(self._result_dir_dialog) self.readINI() def retranslateUi(self, Dialog): _translate = QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Default Values")) self.resultsDirectoryLabel.setText(_translate("Dialog", "Results Directory")) self.sourceDirectoryToolButton.setText(_translate("Dialog", "...")) self.resultDirectoryToolButton.setText(_translate("Dialog", "...")) self.sourceDirectoryLabel.setText(_translate("Dialog", "Source Directory")) self.scaleLabel.setText(_translate("Dialog", "Scale")) self.colorMapLabel.setText(_translate("Dialog", "Default Color Map")) def acceptAndSave(self): source_dir = self.sourceDirectoryLineEdit.text() result_dir = self.resultDirectoryLineEdit.text() color_map = self.CMcomboBox.currentData() scale = str(self.scaleSpinBox.value()) f = open("elilik.ini", "w") f.write(f"source_dir : {source_dir}\n") f.write(f"result_dir : {result_dir}\n") f.write(f"color_map : {color_map}\n") f.write(f"scale : {scale}\n") f.close() msg = QMessageBox() msg.setIcon(QMessageBox.Information) msg.setText("Default values successfully updated!") msg.setWindowTitle("Saved") msg.setStandardButtons(QMessageBox.Ok) msg.exec_() def readINI(self): if os.path.exists("elilik.ini"): f = open("elilik.ini", "r") Lines = f.readlines() # Strips the newline character for line in Lines: l = line.strip() if "source_dir : " in l: self.source_dir = l.replace("source_dir : ","").strip() elif "result_dir : " in l: self.result_dir = l.replace("result_dir : ","").strip() elif "color_map : " in l: self.color_map = l.replace("color_map : ","").strip() elif "scale : " in l: self.scale = l.replace("scale : ","").strip() else: ... self.sourceDirectoryLineEdit.setText(self.source_dir) self.resultDirectoryLineEdit.setText(self.result_dir) self.scaleSpinBox.setValue(float(self.scale)) self.CMcomboBox.addItems(self.CM,None,self.color_map) def _source_dir_dialog(self): directory = str(QFileDialog.getExistingDirectory()) self.sourceDirectoryLineEdit.setText('{}'.format(directory)) def _result_dir_dialog(self): directory = str(QFileDialog.getExistingDirectory()) self.resultDirectoryLineEdit.setText('{}'.format(directory))
class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(390, 400) Dialog.setMinimumSize(QSize(390, 400)) Dialog.setMaximumSize(QSize(390, 400)) Dialog.setFocusPolicy(Qt.StrongFocus) self.button = QDialogButtonBox(Dialog) self.button.setGeometry(QRect(220, 370, 161, 23)) self.button.setOrientation(Qt.Horizontal) self.button.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) self.button.setObjectName("button") self.group_info = QGroupBox(Dialog) self.group_info.setGeometry(QRect(10, 10, 370, 110)) self.group_info.setObjectName("group_info") self.grid_layout = QGridLayout(self.group_info) self.grid_layout.setObjectName("grid_layout") self.edit_name = QLineEdit(self.group_info) self.edit_name.setObjectName("edit_name") self.grid_layout.addWidget(self.edit_name, 2, 2, 1, 1) self.edit_path = QLineEdit(self.group_info) self.edit_path.setObjectName("edit_path") self.grid_layout.addWidget(self.edit_path, 1, 2, 1, 1) self.label_type = QLabel(self.group_info) self.label_type.setObjectName("label_type") self.grid_layout.addWidget(self.label_type, 3, 0, 1, 1) self.label_name = QLabel(self.group_info) self.label_name.setObjectName("label_name") self.grid_layout.addWidget(self.label_name, 2, 0, 1, 1) self.label_path = QLabel(self.group_info) self.label_path.setObjectName("label_path") self.grid_layout.addWidget(self.label_path, 1, 0, 1, 1) self.edit_type = QLineEdit(self.group_info) self.edit_type.setObjectName("edit_type") self.grid_layout.addWidget(self.edit_type, 3, 2, 1, 1) self.group_type = QGroupBox(Dialog) self.group_type.setGeometry(QRect(10, 140, 370, 221)) self.group_type.setObjectName("group_type") self.horizontal_layout = QHBoxLayout(self.group_type) self.horizontal_layout.setObjectName("horizontal_layout") self.tree_module = QTreeWidget(self.group_type) self.tree_module.setObjectName("tree_module") self.tree_module.headerItem().setText(0, "1") self.tree_module.header().setVisible(False) self.horizontal_layout.addWidget(self.tree_module) self.list_type = QListWidget(self.group_type) self.list_type.setObjectName("list_type") self.horizontal_layout.addWidget(self.list_type) self.retranslateUi(Dialog) self.button.accepted.connect(Dialog.accept) self.button.rejected.connect(Dialog.reject) self.tree_module.currentItemChanged.connect(Dialog.bindNodeList) self.list_type.itemClicked.connect(Dialog.setNodeName) QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "노드 생성")) self.group_info.setTitle(_translate("Dialog", "노드 생성 정보")) self.label_type.setText(_translate("Dialog", "노드 타입")) self.label_name.setText(_translate("Dialog", "노드 이름")) self.label_path.setText(_translate("Dialog", "부모 경로")) self.group_type.setTitle(_translate("Dialog", "노드 타입"))
def initUI(self): lblFind=QLabel(self) lblFind.setGeometry(QRect(10, 20, 51, 21)) defaultFont=QFont() defaultFont.setPointSize(10) lblFind.setFont(defaultFont) lblFind.setText("Find:") self.txtFind=QLineEdit(self) self.txtFind.setGeometry(QRect(70, 20, 321, 20)) self.txtFind.setFont(defaultFont) self.chkRE=QCheckBox(self) self.chkRE.setGeometry(QRect(10, 60, 281, 17)) self.chkRE.setFont(defaultFont) self.chkRE.setText("Regular Expression") self.chkCS=QCheckBox(self) self.chkCS.setGeometry(QRect(10, 90, 281, 17)) self.chkCS.setFont(defaultFont) self.chkCS.setText("Case sensitive") self.chkWord=QCheckBox(self) self.chkWord.setGeometry(QRect(10, 120, 281, 17)) self.chkWord.setFont(defaultFont) self.chkWord.setText("Whole word") self.chkWrap=QCheckBox(self) self.chkWrap.setGeometry(QRect(10, 150, 281, 17)) self.chkWrap.setFont(defaultFont) self.chkWrap.setText("Wrap around") defaultDialogButtons=QDialogButtonBox(self) defaultDialogButtons.setGeometry(QRect(240, 270, 156, 23)) defaultDialogButtons.setFont(defaultFont) defaultDialogButtons.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) btnFind=QPushButton(self) btnFind.setGeometry(QRect(160, 270, 75, 23)) btnFind.setFont(defaultFont) btnFind.setText("Find...") directionBox=QGroupBox(self) directionBox.setGeometry(QRect(10, 180, 341, 51)) directionBox.setFont(defaultFont) directionBox.setTitle("Direction") self.rbFwd=QRadioButton(directionBox) self.rbFwd.setGeometry(QRect(0, 20, 82, 17)) self.rbFwd.setFont(defaultFont) self.rbFwd.setText("Forward") self.rbFwd.setChecked(True) self.rbBwd=QRadioButton(directionBox) self.rbBwd.setGeometry(QRect(260, 20, 82, 17)) self.rbBwd.setFont(defaultFont) self.rbBwd.setText("Backward") btnFind.clicked.connect(self.FindText) defaultDialogButtons.accepted.connect(self.accept) defaultDialogButtons.rejected.connect(self.reject)
class project: projectName = "" paratextFolder = "" audioFolderName = "" textFont = "" textSize = 0 fileType = "" bBook = False currentBook = 1 currentChapter = 1 def project(self): pass def readProject(self, currentProject): try: print("Reading project " + currentProject) refMatcher = re.compile("^CurrentReference=([^ ]+) (\\d+)$") for line in open(currentProject + '.prj'): line = line.strip() mtch = refMatcher.match(line) if mtch: self.currentBook = mtch.group(1) # bk = mtch.group(1) # for i, b in enumerate(data.data.book): # if b.equals(bk): # self.currentBook = i # break self.currentChapter = mtch.group(2) elif line.startswith("ProjectName="): self.projectName = line[len("ProjectName="):] elif line.startswith("VersionName="): self.projectName = line[len("VersionName="):] elif line.startswith("ParatextFolder="): self.paratextFolder = line[len("ParatextFolder="):] elif line.startswith("SoundFolder="): self.audioFolderName = line[len("SoundFolder="):] elif line.startswith("AudioFolder="): self.audioFolderName = line[len("AudioFolder="):] elif line.startswith("Font="): self.textFont = line[len("Font="):] elif line.startswith("FontSize="): self.textSize = int(line[len("FontSize=")]) elif line.startswith("FileType="): self.fileType = line[len("FileType="):] self.bBook = self.fileType == "Book" else: print("Unknown project option: ", line) except FileNotFoundError: print("Failed to open project file") self.writeProject(currentProject) pass except Exception as detail: print("Exception reading project file: ", detail) pass def writeProject(self, currentProject): print("Writing project file") try: fh = open(currentProject + ".prj", "w+") fh.write("CurrentReference=" + self.currentBook + " " + str(self.currentChapter) + "\n") fh.write("ProjectName=" + self.projectName + "\n") fh.write("ParatextFolder=" + self.paratextFolder + "\n") fh.write("AudioFolder=" + self.audioFolderName + "\n") fh.write("Font=" + self.textFont + "\n") fh.write("FontSize=" + str(self.textSize) + "\n") fh.write("FileType=" + self.fileType + "\n") fh.close() except Exception as detail: print("IOException writing project file: ", detail) pass # class Ui_Dialog(object): def setupUi(self, Dialog, proj, newProject): try: self.dialog = Dialog self.proj = proj Dialog.setObjectName("Dialog") Dialog.resize(400, 357) self.buttonBox = QDialogButtonBox(Dialog) self.buttonBox.setGeometry(QRect(30, 310, 341, 32)) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.groupBox = QGroupBox(Dialog) self.groupBox.setGeometry(QRect(10, 0, 381, 61)) self.groupBox.setObjectName("groupBox") self.lineEditProjectName = QLineEdit(self.groupBox) self.lineEditProjectName.setGeometry(QRect(10, 30, 361, 23)) self.lineEditProjectName.setObjectName("lineEditProjectName") self.groupBox_2 = QGroupBox(Dialog) self.groupBox_2.setGeometry(QRect(10, 60, 381, 61)) self.groupBox_2.setObjectName("groupBox_2") self.comboBoxProjectType = QComboBox(self.groupBox_2) self.comboBoxProjectType.setGeometry(QRect(10, 30, 361, 23)) self.comboBoxProjectType.setObjectName("comboBoxProjectType") self.groupBox_3 = QGroupBox(Dialog) self.groupBox_3.setGeometry(QRect(10, 120, 381, 61)) self.groupBox_3.setObjectName("groupBox_3") self.lineEditSourcePath = QLineEdit(self.groupBox_3) self.lineEditSourcePath.setGeometry(QRect(10, 30, 271, 23)) self.lineEditSourcePath.setObjectName("lineEditSourcePath") self.pushButtonBrowseSource = QPushButton(self.groupBox_3) self.pushButtonBrowseSource.setGeometry(QRect(290, 30, 80, 23)) self.pushButtonBrowseSource.setObjectName("pushButtonBrowseSource") self.groupBox_4 = QGroupBox(Dialog) self.groupBox_4.setGeometry(QRect(10, 180, 381, 61)) self.groupBox_4.setObjectName("groupBox_4") self.pushButtonBrowseAudio = QPushButton(self.groupBox_4) self.pushButtonBrowseAudio.setGeometry(QRect(290, 30, 80, 23)) self.pushButtonBrowseAudio.setObjectName("pushButtonBrowseAudio") self.lineEditAudioFilesPath = QLineEdit(self.groupBox_4) self.lineEditAudioFilesPath.setGeometry(QRect(10, 30, 271, 23)) self.lineEditAudioFilesPath.setObjectName("lineEditAudioFilesPath") self.groupBox_5 = QGroupBox(Dialog) self.groupBox_5.setGeometry(QRect(10, 240, 381, 61)) self.groupBox_5.setObjectName("groupBox_5") self.comboBoxFont = QFontComboBox(self.groupBox_5) self.comboBoxFont.setGeometry(QRect(10, 30, 271, 23)) self.comboBoxFont.setObjectName("comboBoxFont") self.lineEditFontSize = QLineEdit(self.groupBox_5) self.lineEditFontSize.setGeometry(QRect(290, 30, 81, 23)) self.lineEditFontSize.setObjectName("lineEditFontSize") # set up fields if newProject: self.projectName = "" self.paratextFolder = "c:\\My Paratext 8 Projects" self.textFont = "Times New Roman" self.textSize = 25 self.fileType = "Paratext" typeList = ("Paratext", "Book", "BART") # self.comboBoxProjectType.clear() for index, i in enumerate(typeList): self.comboBoxProjectType.addItem(i) index = self.comboBoxProjectType.findText(self.fileType, Qt.MatchFixedString) if index >= 0: self.comboBoxProjectType.setCurrentIndex(index) self.lineEditProjectName.setText(self.projectName) self.lineEditSourcePath.setText(self.paratextFolder) self.lineEditAudioFilesPath.setText(self.audioFolderName) index = self.comboBoxFont.findText(self.textFont, Qt.MatchFixedString) if index >= 0: self.comboBoxFont.setCurrentIndex(index) self.lineEditFontSize.setText(str(self.textSize)) self.retranslateUi(Dialog) self.pushButtonBrowseSource.clicked.connect(self.browse_source) self.pushButtonBrowseAudio.clicked.connect(self.browse_audio_path) self.lineEditProjectName.textChanged.connect( self.lineEditProjectName_changed) self.comboBoxProjectType.currentTextChanged.connect( self.comboBoxProjectType_changed) self.comboBoxFont.currentTextChanged.connect( self.comboBoxFont_changed) self.lineEditFontSize.textChanged.connect( self.lineEditFontSize_changed) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) QMetaObject.connectSlotsByName(Dialog) except Exception as detail: print("Exception: " + detail) def retranslateUi(self, Dialog): _translate = QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.groupBox.setTitle(_translate("Dialog", "Project name")) self.groupBox_2.setTitle(_translate("Dialog", "Type")) self.groupBox_3.setTitle(_translate("Dialog", "Source")) self.pushButtonBrowseSource.setText(_translate("Dialog", "Browse...")) self.groupBox_4.setTitle(_translate("Dialog", "Audio files folder")) self.pushButtonBrowseAudio.setText(_translate("Dialog", "Browse...")) self.groupBox_5.setTitle(_translate("Dialog", "Font")) def accept(self): self.writeProject(self.projectName) print("Saved project " + self.projectName) self.dialog.close() def reject(self): print("Cancel") self.dialog.close() def comboBoxProjectType_changed(self): self.fileType = self.comboBoxProjectType.currentText() # print("Changing project type to " + self.fileType) self.bBook = True if self.fileType == "Paratext": self.paratextFolder = "c:\\Paratext\\My Paratext 8 Projects\\" + self.lineEditProjectName.text( ) self.bBook = False elif self.fileType == "Book": self.paratextFolder = "" else: self.paratextFolder = "" self.lineEditSourcePath.setText(self.paratextFolder) def lineEditProjectName_changed(self): self.comboBoxProjectType_changed() self.lineEditSourcePath.setText(self.paratextFolder) self.projectName = self.lineEditProjectName.text() def comboBoxFont_changed(self): self.textFont = self.comboBoxFont.currentText() def lineEditFontSize_changed(self): self.textSize = int(self.lineEditFontSize.text()) def browse_source(self): try: my_dir = QFileDialog.getExistingDirectory(self.dialog, "Open a folder", self.paratextFolder, QFileDialog.ShowDirsOnly) if my_dir: self.paratextFolder = my_dir self.lineEditSourcePath.setText(self.paratextFolder) # except TypeError as detail: # print (detail) except Exception: print("Failed choose Paratext folder: ") # + detail) def browse_audio_path(self): try: my_dir = QFileDialog.getExistingDirectory(self.dialog, "Open a folder", self.audioFolderName, QFileDialog.ShowDirsOnly) if my_dir: self.audioFolderName = my_dir self.lineEditAudioFilesPath.setText(self.audioFolderName) # except TypeError as detail: # print (detail) except Exception: print("Failed choose audio folder: ") # + detail)