def createStatusBar(self): statusBar = QWidget(self) statusBar.setObjectName('StatusBar') statusBar.setGeometry(STATUS_BAR_X, STATUS_BAR_Y, STATUS_BAR_WIDTH, STATUS_BAR_HEIGHT) self.modeLabel = QLabel(self) self.modeLabel.setObjectName('ModeLabel') self.modeLabel.setAlignment(Qt.AlignCenter | Qt.AlignTop) self.modeLabel.setText('Undefined') self.modeLabel.setGeometry(STATUS_MODE_X, STATUS_MODE_Y, STATUS_MODE_WIDTH, STATUS_MODE_HEIGHT) MainController.getInstance().stateChangedSignal.connect( lambda mode: self.handleModeChange(mode)) infoLabel = QLabel(self) infoLabel.setObjectName('InfoLabel') infoLabel.setAlignment(Qt.AlignCenter | Qt.AlignTop) infoLabel.setText('99.9 MHz') infoLabel.setGeometry(STATUS_INFO_X, STATUS_INFO_Y, STATUS_INFO_WIDTH, STATUS_INFO_HEIGHT) MainController.getInstance().statusLabelChangedSignal.connect( lambda text: infoLabel.setText(text)) timeLabel = QLabel(self) timeLabel.setObjectName('TimeLabel') timeLabel.setAlignment(Qt.AlignCenter | Qt.AlignTop) timeLabel.setText('17:22\t08.02.1993') timeLabel.setGeometry(STATUS_TIME_X, STATUS_TIME_Y, STATUS_TIME_WIDTH, STATUS_TIME_HEIGHT) '''
def window(): app = QApplication(sys.argv) w = QWidget() # b = QLabel(w) # b.setText("Hello World!") w.setGeometry(100,100,200,50) # b.move(50,20) w.setWindowTitle("test") w.show() painter = QPainter() painter.setRenderHint(QPainter.Antialiasing) painter.setBackground(QColor(0, 200, 0)) painter.setBrush(QColor(0, 0, 200)) # painter.setPen(QPen(QColor(0, 0, 200), 2, Qt.SolidLine)) painter.drawEllipse(40, 40, 40, 40) # painter.setBrush(Qt.NoBrush) sys.exit(app.exec_())
class Config(QDialog): ''' Configuration dialog for single book conversion. If accepted, has the following important attributes output_format - Output format (without a leading .) input_format - Input format (without a leading .) opf_path - Path to OPF file with user specified metadata cover_path - Path to user specified cover (can be None) recommendations - A pickled list of 3 tuples in the same format as the recommendations member of the Input/Output plugins. ''' def __init__(self, parent, db, book_id, preferred_input_format=None, preferred_output_format=None): QDialog.__init__(self, parent) self.setupUi() self.opt_individual_saved_settings.setVisible(False) self.db, self.book_id = db, book_id self.setup_input_output_formats(self.db, self.book_id, preferred_input_format, preferred_output_format) self.setup_pipeline() self.input_formats.currentIndexChanged[native_string_type].connect( self.setup_pipeline) self.output_formats.currentIndexChanged[native_string_type].connect( self.setup_pipeline) self.groups.setSpacing(5) self.groups.activated[(QModelIndex)].connect(self.show_pane) self.groups.clicked[(QModelIndex)].connect(self.show_pane) self.groups.entered[(QModelIndex)].connect(self.show_group_help) rb = self.buttonBox.button(self.buttonBox.RestoreDefaults) rb.setText(_('Restore &defaults')) rb.clicked.connect(self.restore_defaults) self.groups.setMouseTracking(True) geom = gprefs.get('convert_single_dialog_geom', None) if geom: self.restoreGeometry(geom) else: self.resize(self.sizeHint()) def setupUi(self): self.setObjectName("Dialog") self.resize(1024, 700) self.setWindowIcon(QIcon(I('convert.png'))) self.gridLayout = QGridLayout(self) self.gridLayout.setObjectName("gridLayout") self.horizontalLayout = QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.input_label = QLabel(self) self.input_label.setObjectName("input_label") self.horizontalLayout.addWidget(self.input_label) self.input_formats = QComboBox(self) self.input_formats.setSizeAdjustPolicy( QComboBox.AdjustToMinimumContentsLengthWithIcon) self.input_formats.setMinimumContentsLength(5) self.input_formats.setObjectName("input_formats") self.horizontalLayout.addWidget(self.input_formats) self.opt_individual_saved_settings = QCheckBox(self) self.opt_individual_saved_settings.setObjectName( "opt_individual_saved_settings") self.horizontalLayout.addWidget(self.opt_individual_saved_settings) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.label_2 = QLabel(self) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) self.output_formats = QComboBox(self) self.output_formats.setSizeAdjustPolicy( QComboBox.AdjustToMinimumContentsLengthWithIcon) self.output_formats.setMinimumContentsLength(5) self.output_formats.setObjectName("output_formats") self.horizontalLayout.addWidget(self.output_formats) self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 2) self.groups = QListView(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(1) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.groups.sizePolicy().hasHeightForWidth()) self.groups.setSizePolicy(sizePolicy) self.groups.setTabKeyNavigation(True) self.groups.setIconSize(QSize(48, 48)) self.groups.setWordWrap(True) self.groups.setObjectName("groups") self.gridLayout.addWidget(self.groups, 1, 0, 3, 1) self.scrollArea = QScrollArea(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(4) sizePolicy.setVerticalStretch(10) sizePolicy.setHeightForWidth( self.scrollArea.sizePolicy().hasHeightForWidth()) self.scrollArea.setSizePolicy(sizePolicy) self.scrollArea.setFrameShape(QFrame.NoFrame) self.scrollArea.setLineWidth(0) self.scrollArea.setWidgetResizable(True) self.scrollArea.setObjectName("scrollArea") self.scrollAreaWidgetContents = QWidget() self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 810, 494)) self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") self.verticalLayout_3 = QVBoxLayout(self.scrollAreaWidgetContents) self.verticalLayout_3.setContentsMargins(0, 0, 0, 0) self.verticalLayout_3.setObjectName("verticalLayout_3") self.stack = QStackedWidget(self.scrollAreaWidgetContents) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.stack.sizePolicy().hasHeightForWidth()) self.stack.setSizePolicy(sizePolicy) self.stack.setObjectName("stack") self.page = QWidget() self.page.setObjectName("page") self.stack.addWidget(self.page) self.page_2 = QWidget() self.page_2.setObjectName("page_2") self.stack.addWidget(self.page_2) self.verticalLayout_3.addWidget(self.stack) self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.gridLayout.addWidget(self.scrollArea, 1, 1, 1, 1) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok | QDialogButtonBox.RestoreDefaults) self.buttonBox.setObjectName("buttonBox") self.gridLayout.addWidget(self.buttonBox, 3, 1, 1, 1) self.help = QTextEdit(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.help.sizePolicy().hasHeightForWidth()) self.help.setSizePolicy(sizePolicy) self.help.setMaximumHeight(80) self.help.setObjectName("help") self.gridLayout.addWidget(self.help, 2, 1, 1, 1) self.input_label.setBuddy(self.input_formats) self.label_2.setBuddy(self.output_formats) self.input_label.setText(_("&Input format:")) self.opt_individual_saved_settings.setText( _("Use &saved conversion settings for individual books")) self.label_2.setText(_("&Output format:")) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) def sizeHint(self): desktop = QCoreApplication.instance().desktop() geom = desktop.availableGeometry(self) nh, nw = max(300, geom.height() - 100), max(400, geom.width() - 70) return QSize(nw, nh) def restore_defaults(self): delete_specifics(self.db, self.book_id) self.setup_pipeline() @property def input_format(self): return unicode_type(self.input_formats.currentText()).lower() @property def output_format(self): return unicode_type(self.output_formats.currentText()).lower() @property def manually_fine_tune_toc(self): for i in range(self.stack.count()): w = self.stack.widget(i) if hasattr(w, 'manually_fine_tune_toc'): return w.manually_fine_tune_toc.isChecked() def setup_pipeline(self, *args): oidx = self.groups.currentIndex().row() input_format = self.input_format output_format = self.output_format self.plumber = create_dummy_plumber(input_format, output_format) def widget_factory(cls): return cls(self.stack, self.plumber.get_option_by_name, self.plumber.get_option_help, self.db, self.book_id) self.mw = widget_factory(MetadataWidget) self.setWindowTitle( _('Convert') + ' ' + unicode_type(self.mw.title.text())) lf = widget_factory(LookAndFeelWidget) hw = widget_factory(HeuristicsWidget) sr = widget_factory(SearchAndReplaceWidget) ps = widget_factory(PageSetupWidget) sd = widget_factory(StructureDetectionWidget) toc = widget_factory(TOCWidget) from calibre.gui2.actions.toc_edit import SUPPORTED toc.manually_fine_tune_toc.setVisible( output_format.upper() in SUPPORTED) debug = widget_factory(DebugWidget) output_widget = self.plumber.output_plugin.gui_configuration_widget( self.stack, self.plumber.get_option_by_name, self.plumber.get_option_help, self.db, self.book_id) input_widget = self.plumber.input_plugin.gui_configuration_widget( self.stack, self.plumber.get_option_by_name, self.plumber.get_option_help, self.db, self.book_id) while True: c = self.stack.currentWidget() if not c: break self.stack.removeWidget(c) widgets = [self.mw, lf, hw, ps, sd, toc, sr] if input_widget is not None: widgets.append(input_widget) if output_widget is not None: widgets.append(output_widget) widgets.append(debug) for w in widgets: self.stack.addWidget(w) w.set_help_signal.connect(self.help.setPlainText) self._groups_model = GroupModel(widgets) self.groups.setModel(self._groups_model) idx = oidx if -1 < oidx < self._groups_model.rowCount() else 0 self.groups.setCurrentIndex(self._groups_model.index(idx)) self.stack.setCurrentIndex(idx) try: shutil.rmtree(self.plumber.archive_input_tdir, ignore_errors=True) except: pass def setup_input_output_formats(self, db, book_id, preferred_input_format, preferred_output_format): if preferred_output_format: preferred_output_format = preferred_output_format.upper() output_formats = get_output_formats(preferred_output_format) input_format, input_formats = get_input_format_for_book( db, book_id, preferred_input_format) preferred_output_format = preferred_output_format if \ preferred_output_format in output_formats else \ sort_formats_by_preference(output_formats, [prefs['output_format']])[0] self.input_formats.addItems( (unicode_type(x.upper()) for x in input_formats)) self.output_formats.addItems( (unicode_type(x.upper()) for x in output_formats)) self.input_formats.setCurrentIndex(input_formats.index(input_format)) self.output_formats.setCurrentIndex( output_formats.index(preferred_output_format)) def show_pane(self, index): self.stack.setCurrentIndex(index.row()) def accept(self): recs = GuiRecommendations() for w in self._groups_model.widgets: if not w.pre_commit_check(): return x = w.commit(save_defaults=False) recs.update(x) self.opf_file, self.cover_file = self.mw.opf_file, self.mw.cover_file self._recommendations = recs if self.db is not None: recs['gui_preferred_input_format'] = self.input_format save_specifics(self.db, self.book_id, recs) self.break_cycles() QDialog.accept(self) def reject(self): self.break_cycles() QDialog.reject(self) def done(self, r): if self.isVisible(): gprefs['convert_single_dialog_geom'] = \ bytearray(self.saveGeometry()) return QDialog.done(self, r) def break_cycles(self): for i in range(self.stack.count()): w = self.stack.widget(i) w.break_cycles() @property def recommendations(self): recs = [(k, v, OptionRecommendation.HIGH) for k, v in self._recommendations.items()] return recs def show_group_help(self, index): widget = self._groups_model.widgets[index.row()] self.help.setPlainText(widget.HELP)
class LLT_AddWord(QMainWindow): def __init__(self): super(LLT_AddWord, self).__init__() self.w = QWidget() self.setCentralWidget(self.w) self.verbDic = [] self.nounDic = [] self.adjDic = [] self.phraseDic = [] self.wordList = [] self.w.setWindowTitle("Add Word") self.w.setGeometry(0, 0, 500, 500) self.vRad = QRadioButton("Verb") self.vRad.setChecked(True) self.nRad = QRadioButton("Noun") self.aRad = QRadioButton("Adjective") self.pRad = QRadioButton("Phrase") self.okBut = QPushButton("OK") self.okBut.clicked.connect(self.OK) self.entryLab = QLabel("Word: ") self.wordEntry = QLineEdit() self.wordEntry.setEnabled(False) self.tranLab = QLabel("Translation: ") self.tranEntry = QLineEdit() self.tranEntry.setEnabled(False) self.checkBut = QPushButton("Check") self.checkBut.clicked.connect(self.check) self.saveBut = QPushButton("Save") self.saveBut.clicked.connect(self.save) self.clearBut = QPushButton("Clear") self.clearBut.clicked.connect(self.clear) self.newBut = QPushButton("New word") self.newBut.clicked.connect(self.new) self.exitBut = QPushButton("Exit") self.exitBut.clicked.connect(self.exit) grid = QGridLayout() grid.addWidget(self.vRad, 0, 0) grid.addWidget(self.nRad, 0, 1) grid.addWidget(self.aRad, 0, 2) grid.addWidget(self.pRad, 0, 3) grid.addWidget(self.okBut, 0, 4) grid.addWidget(self.entryLab, 1, 0) grid.addWidget(self.wordEntry, 1, 1, 1, 3) grid.addWidget(self.tranLab, 2, 0) grid.addWidget(self.tranEntry, 2, 1, 1, 3) grid.addWidget(self.checkBut, 3, 0) grid.addWidget(self.saveBut, 3, 1) grid.addWidget(self.clearBut, 3, 2) grid.addWidget(self.newBut, 3, 3) grid.addWidget(self.exitBut, 3, 4) self.getDics() self.setLists() self.w.setLayout(grid) self.w.show() def OK(self): self.vRad.setEnabled(False) self.nRad.setEnabled(False) self.aRad.setEnabled(False) self.pRad.setEnabled(False) self.okBut.setEnabled(False) self.wordEntry.setEnabled(True) self.tranEntry.setEnabled(True) def check(self): word = self.wordEntry.text().upper() if word in self.wordList: msgBox = QMessageBox() msgBox.setText(word + ' already in dictionary') msgBox.exec_() else: msgBox = QMessageBox() msgBox.setText(word + ' not in dictionary yet') msgBox.exec_() def save(self): spanWord = self.wordEntry.text().upper() tranWord = self.tranEntry.text().upper() if spanWord in self.wordList: msgBox = QMessageBox() msgBox.setText(spanWord + ' already in dictionary') msgBox.exec_() else: self.wordList.append(spanWord) newWord = [spanWord, tranWord] self.wordEntry.setEnabled(False) self.tranEntry.setEnabled(False) if self.vRad.isChecked(): self.verbDic.append(newWord) v = open('verb.txt', 'w') json.dump(self.verbDic, v) v.close() elif self.nRad.isChecked(): self.nounDic.append(newWord) n = open('noun.txt', 'w') json.dump(self.nounDic, n) n.close() elif self.aRad.isChecked(): self.adjDic.append(newWord) a = open('adj.txt', 'w') json.dump(self.adjDic, a) a.close() elif self.pRad.isChecked(): self.phraseDic.append(newWord) p = open('phrase.txt', 'w') json.dump(self.phraseDic, p) p.close() else: msgBox = QMessageBox() msgBox.setText( "You must select a dictionary before saving word.") msgBox.exec_() def clear(self): self.vRad.setEnabled(True) self.nRad.setEnabled(True) self.aRad.setEnabled(True) self.pRad.setEnabled(True) self.okBut.setEnabled(True) self.wordEntry.setEnabled(False) self.tranEntry.setEnabled(False) self.wordEntry.clear() self.tranEntry.clear() def new(self): self.vRad.setEnabled(True) self.nRad.setEnabled(True) self.aRad.setEnabled(True) self.pRad.setEnabled(True) self.okBut.setEnabled(True) self.wordEntry.setEnabled(False) self.tranEntry.setEnabled(False) self.wordEntry.clear() self.tranEntry.clear() def exit(self): confirm = QMessageBox.question(self.w, 'Quit', 'Are you sure you want to exit?', QMessageBox.Yes | QMessageBox.No) if confirm == QMessageBox.Yes: self.close() else: pass def getDics(self): try: v = open('verb.txt', 'r') self.verbDic = json.load(v) v.close() except: self.verbDic = [] try: n = open('noun.txt', 'r') self.nounDic = json.load(n) n.close() except: self.nounDic = [] try: p = open('phrase.txt', 'r') self.phraseDic = json.load(p) p.close() except: self.phraseDic = [] try: a = open('adj.txt', 'r') self.adjDic = json.load(a) a.close() except: self.phraseDic = [] def setLists(self): for item in self.verbDic: self.wordList.append(item[0]) for item in self.nounDic: self.wordList.append(item[0]) for item in self.phraseDic: self.wordList.append(item[0]) for item in self.adjDic: self.wordList.append(item[0])
class LLT_Lookup(QMainWindow): def __init__(self): super(LLT_Lookup, self).__init__() self.w = QWidget() self.setCentralWidget(self.w) self.verbDic = [] self.nounDic = [] self.adjDic = [] self.phraseDic = [] self.wordList = [] self.wordDic = [] self.index = int(0) self.w.setWindowTitle("Word Lookup") self.w.setGeometry(0,0,500, 500) self.lookLab = QLabel("Lookup: ") self.lookEntry = QLineEdit() self.lookBut = QPushButton("Search") self.lookBut.clicked.connect(self.search) self.wordLab = QLabel("Word: ") self.resultWord = QLabel() self.tranLab = QLabel("Translation: ") self.resultTran = QLabel() self.newBut = QPushButton("New Search") self.newBut.clicked.connect(self.new) self.exitBut = QPushButton("Exit") self.exitBut.clicked.connect(self.exit) grid = QGridLayout() grid.addWidget(self.lookLab, 0, 0) grid.addWidget(self.lookEntry, 0, 1, 1, 2) grid.addWidget(self.lookBut, 0, 3) grid.addWidget(self.wordLab, 1, 0) grid.addWidget(self.resultWord, 1, 1, 1, 3) grid.addWidget(self.tranLab, 2, 0) grid.addWidget(self.resultTran, 2, 1, 1, 3) grid.addWidget(self.newBut, 3, 0) grid.addWidget(self.exitBut, 3, 3) self.getDics() self.setLists() self.w.setLayout(grid) self.w.show() def search(self): searchWord = self.lookEntry.text().upper().strip() if searchWord in self.wordList: self.lookEntry.setEnabled(False) self.lookBut.setEnabled(False) self.index = self.wordList.index(searchWord) foundWord = self.wordDic[self.index] self.resultWord.setText(foundWord[0]) self.resultTran.setText(foundWord[1]) else: msgBox = QMessageBox() msgBox.setText("Word not currently saved in dictionary.") msgBox.exec_(); def new(self): self.lookEntry.setEnabled(True) self.lookBut.setEnabled(True) self.resultWord.setText('') self.resultTran.setText('') self.lookEntry.clear() def exit(self): confirm = QMessageBox.question(self.w, 'Quit', 'Are you sure you want to exit?', QMessageBox.Yes | QMessageBox.No) if confirm == QMessageBox.Yes: self.close() else: pass def getDics(self): try: v=open('verb.txt','r') self.verbDic=json.load(v) v.close() except: self.verbDic = [] try: n=open('noun.txt','r') self.nounDic=json.load(n) n.close() except: self.nounDic = [] try: p=open('phrase.txt','r') self.phraseDic=json.load(p) p.close() except: self.phraseDic = [] try: a=open('adj.txt','r') self.adjDic=json.load(a) a.close() except: self.phraseDic = [] def setLists(self): for item in self.verbDic: self.wordList.append(item[0]) self.wordDic.append(item) for item in self.nounDic: self.wordList.append(item[0]) self.wordDic.append(item) for item in self.adjDic: self.wordList.append(item[0]) self.wordDic.append(item) for item in self.phraseDic: self.wordList.append(item[0]) self.wordDic.append(item)
class LLT_EditWord(QMainWindow): def __init__(self): super(LLT_EditWord, self).__init__() self.w = QWidget() self.setCentralWidget(self.w) self.verbDic = [] self.nounDic = [] self.adjDic = [] self.phraseDic = [] self.wordList = [] self.verbList = [] self.nounList = [] self.adjList = [] self.phraseList = [] self.index = int(0) self.w.setWindowTitle("Edit Word") self.w.setGeometry(0,0,500, 500) self.vRad = QRadioButton("Verb") self.vRad.setChecked(True) self.nRad = QRadioButton("Noun") self.aRad = QRadioButton("Adjective") self.pRad = QRadioButton("Phrase") self.okBut = QPushButton("OK") self.okBut.clicked.connect(self.OK) self.lookLab = QLabel("Lookup: ") self.lookEntry = QLineEdit() self.lookEntry.setEnabled(False) self.lookBut = QPushButton("Search") self.lookBut.clicked.connect(self.search) self.lookBut.setEnabled(False) self.entryLab = QLabel("Word: ") self.wordEntry = QLineEdit() self.wordEntry.setEnabled(False) self.tranLab = QLabel("Translation: ") self.tranEntry = QLineEdit() self.tranEntry.setEnabled(False) self.saveBut = QPushButton("Save") self.saveBut.clicked.connect(self.save) self.clearBut = QPushButton("Reset") self.clearBut.clicked.connect(self.reset) self.newBut = QPushButton("New word") self.newBut.clicked.connect(self.new) self.exitBut = QPushButton("Exit") self.exitBut.clicked.connect(self.exit) grid = QGridLayout() grid.addWidget(self.vRad, 0, 0) grid.addWidget(self.nRad, 0, 1) grid.addWidget(self.aRad, 0, 2) grid.addWidget(self.pRad, 0, 3) grid.addWidget(self.okBut, 0, 4) grid.addWidget(self.lookLab, 1, 0) grid.addWidget(self.lookEntry, 1, 1, 1, 2) grid.addWidget(self.lookBut, 1, 4) grid.addWidget(self.entryLab, 2, 0) grid.addWidget(self.wordEntry, 2, 1, 1, 3) grid.addWidget(self.tranLab, 3, 0) grid.addWidget(self.tranEntry, 3, 1, 1, 3) grid.addWidget(self.saveBut, 4, 0) grid.addWidget(self.clearBut, 4, 1) grid.addWidget(self.newBut, 4, 2) grid.addWidget(self.exitBut, 4, 3) self.getDics() self.setLists() self.w.setLayout(grid) self.w.show() def search(self): searchWord = self.lookEntry.text().upper() currentDic = [] currentList = [] if self.vRad.isChecked(): currentDic = self.verbDic currentList = self.verbList elif self.nRad.isChecked(): currentDic = self.nounDic currentList = self.nounList elif self.aRad.isChecked(): currentDic = self.adjDic currentList = self.adjList elif self.pRad.isChecked(): currentDic = self.phraseDic currentList = self.phraseList else: msgBox = QMessageBox() msgBox.setText("You must select a dictionary before continuing.") msgBox.exec_() self.vRad.setEnabled(True) self.nRad.setEnabled(True) self.aRad.setEnabled(True) self.pRad.setEnabled(True) self.lookEntry.setEnabled(False) self.lookBut.setEnabled(False) self.wordEntry.setEnabled(False) self.tranEntry.setEnabled(False) if searchWord in self.wordList: self.lookEntry.setEnabled(False) self.lookBut.setEnabled(False) self.wordEntry.setEnabled(True) self.tranEntry.setEnabled(True) self.index = currentList.index(searchWord) oldWord = currentDic[self.index] self.wordEntry.setPlaceholderText(oldWord[0]) self.tranEntry.setPlaceholderText(oldWord[1]) else: msgBox = QMessageBox() msgBox.setText("Word not currently saved in dictionary.") msgBox.exec_(); def OK(self): self.vRad.setEnabled(False) self.nRad.setEnabled(False) self.aRad.setEnabled(False) self.pRad.setEnabled(False) self.lookEntry.setEnabled(True) self.lookBut.setEnabled(True) def save(self): spanWord = self.wordEntry.text().upper() tranWord = self.tranEntry.text().upper() if spanWord in self.wordList: msgBox = QMessageBox() msgBox.setText(spanWord + ' already in dictionary') msgBox.exec_(); else: self.wordList.append(spanWord) newWord = [spanWord,tranWord] self.wordEntry.setEnabled(False) self.tranEntry.setEnabled(False) if self.vRad.isChecked(): self.verbDic[self.index]= newWord v = open('verb.txt','w') json.dump(self.verbDic, v) v.close() elif self.nRad.isChecked(): self.nounDic[self.index]= newWord n = open('noun.txt','w') json.dump(self.nounDic, n) n.close() elif self.aRad.isChecked(): self.adjDic[self.index]= newWord a = open('adj.txt','w') json.dump(self.adjDic, a) a.close() elif self.pRad.isChecked(): self.phraseDic[self.index]= newWord p = open('phrase.txt','w') json.dump(self.phraseDic, p) p.close() else: msgBox = QMessageBox() msgBox.setText("You must select a dictionary before saving word.") msgBox.exec_(); def reset(self): self.vRad.setEnabled(True) self.nRad.setEnabled(True) self.aRad.setEnabled(True) self.pRad.setEnabled(True) self.lookEntry.setEnabled(False) self.lookBut.setEnabled(False) self.wordEntry.setEnabled(False) self.tranEntry.setEnabled(False) self.wordEntry.clear() self.tranEntry.clear() self.lookEntry.setPlaceholderText('') self.wordEntry.setPlaceholderText('') self.tranEntry.setPlaceholderText('') def new(self): self.vRad.setEnabled(True) self.nRad.setEnabled(True) self.aRad.setEnabled(True) self.pRad.setEnabled(True) self.wordEntry.setEnabled(False) self.tranEntry.setEnabled(False) self.wordEntry.clear() self.tranEntry.clear() self.lookEntry.setPlaceholderText('') self.wordEntry.setPlaceholderText('') self.tranEntry.setPlaceholderText('') def exit(self): confirm = QMessageBox.question(self.w, 'Quit', 'Are you sure you want to exit?', QMessageBox.Yes | QMessageBox.No) if confirm == QMessageBox.Yes: self.close() else: pass def getDics(self): try: v=open('verb.txt','r') self.verbDic=json.load(v) v.close() except: self.verbDic = [] try: n=open('noun.txt','r') self.nounDic=json.load(n) n.close() except: self.nounDic = [] try: p=open('phrase.txt','r') self.phraseDic=json.load(p) p.close() except: self.phraseDic = [] try: a=open('adj.txt','r') self.adjDic=json.load(a) a.close() except: self.phraseDic = [] def setLists(self): for item in self.verbDic: self.wordList.append(item[0]) self.verbList.append(item[0]) for item in self.nounDic: self.wordList.append(item[0]) self.nounList.append(item[0]) for item in self.adjDic: self.wordList.append(item[0]) self.adjList.append(item[0]) for item in self.phraseDic: self.wordList.append(item[0]) self.phraseList.append(item[0])