def close(self) -> bool: # if the not-appears-next-time check-box is checked if self.__pref_key is not None: PrefManager.set_pref( self.__pref_key, not self.__chk_not_appears_next_time.isChecked()) # close this message-box return super(BaseMessageBox, self).close()
def __repr__(self): if self.__str is None: return 'None' elif isinstance(self.__str, Strs): return self.__str.value[PrefManager.get_pref(PrefKey.LANG)] else: return self.__str
def _init_views(self): # the setting of interface languages self.__lbl_lang = StyledLabel(Strs.Preferences_Page_Lang) self.__comb_lang = QComboBox() self.__comb_lang.addItems(LangManager.supported_languages) self.__comb_lang.setCurrentIndex(PrefManager.get_pref(PrefKey.LANG)) self._add_layout( StyledHBox((self.__lbl_lang, 0), (self.__comb_lang, 1)))
def __event_cancel(self): # if a message-box for warning the user is needed if self.__dialog_mode == AddModifyDialogMode.A and PrefManager.get_pref(PrefKey.MSG_BOX_CANCELLING_NEW_EXAMPLE): # create & show the dialog to make sure that the user really want to cancel the action for adding it if BaseMessageBox.Builder.\ init(Strs.Make_Sure_For_Cancelling_Sth_Dialog_Title, PrefKey.MSG_BOX_CANCELLING_NEW_EXAMPLE).\ set_content(Strs.Make_Sure_For_Cancelling_Adding_New_Example_Sentence_Dialog_Content).create().\ show_and_exec().\ dialog_result == DialogResult.YES: self.close() # otherwise, close the example-form-dialog directly else: self.close()
def __event_remove_meaning(self): # the nested function for removing the meaning actually def ____remove_meaning(): # unregister the registered views LangManager.unregister(*self.__btn_actions.get_all_actions()) # remove the item in the list self.__attached.takeItem(self.__attached.indexAt(self.pos()).row()) # if a message-box for warning the user is needed if PrefManager.get_pref(PrefKey.MSG_BOX_DELETING_ADDED_MEANING): if BaseMessageBox.Builder. \ init(Strs.Make_Sure_For_Cancelling_Sth_Dialog_Title, PrefKey.MSG_BOX_DELETING_ADDED_MEANING). \ set_content(Strs.Make_Sure_For_Removing_Added_Example_Sentence_Dialog_Content).create(). \ show_and_exec(). \ dialog_result == DialogResult.YES: ____remove_meaning() # otherwise, remove the example directly else: ____remove_meaning()
def set_string_by_str_enum_or_literal_str(self, str_enum_or_literal_str): # get the literal string if isinstance(str_enum_or_literal_str, Strs): literal_str = str_enum_or_literal_str.value[PrefManager.get_pref( PrefKey.LANG)] else: literal_str = str_enum_or_literal_str # q-label, q-push-button, q-action, q-check-box, q-radio-button -> set its text if isinstance(self, (QLabel, QPushButton, QAction, QCheckBox, QRadioButton)): self.setText(literal_str) # q-line-edit, q-text-edit -> set its placeholder elif isinstance(self, (QLineEdit, QTextEdit)): self.setPlaceholderText(literal_str) # q-main-window, q-dialog -> set its window-title elif isinstance(self, (QMainWindow, QDialog)): self.setWindowTitle(literal_str) # q-menu -> set its title elif isinstance(self, QMenu): self.setTitle(literal_str)
import sys from PyQt5.QtWidgets import QApplication from managers.layout_manager import LayoutManager from managers.pref_manager import PrefManager from views.main_win.main_window import MainWindow # start the application def start_app(): app = QApplication([]) main_win = MainWindow() main_win.show() LayoutManager.set_main_window(main_win) sys.exit(app.exec()) if __name__ == '__main__': # initialize the preferences PrefManager.init_pref() # start the application start_app() # lis = WordAnalyzer.split_syllables('habláis') # WordAnalyzer.get_stressed_syllable(lis)
def __event_lang_selected(self, i): PrefManager.set_pref(PrefKey.LANG, i) LangManager.notify_all_registered()
def get_fullname(self): return Strs[self.name].value[PrefManager.get_pref(PrefKey.LANG)]