def enableDisable(self, app, userVars): """Enable or disable controls as appropriate.""" logger.debug(util.funcName('begin')) if self.optSearchRefNum.getState() == 1: self.btnReplace.Label = theLocale.getText( "Replace with Example") self.btnReplaceAll.Label = theLocale.getText( "Replace All") app.setUpdateExamples(False) userVars.store("SearchFor", "RefNum") self.chkStartFromBeginning.setState(True) else: self.btnReplace.Label = theLocale.getText( "Update Example") self.btnReplaceAll.Label = theLocale.getText( "Update All") app.setUpdateExamples(True) userVars.store("SearchFor", "Existing") self.chkStartFromBeginning.setState(False) if self.single_refnum(): self.comboRefnum.Visible = True self.listboxRefnum.Visible = False else: self.comboRefnum.Visible = False self.listboxRefnum.Visible = True
def switch(self): logger.debug(util.funcName('begin')) if self.step == self.STEP_SETTINGS: self.getFormResults() if self.whichSource == "Generate": if not self.script.scriptNameIsSet(): self.msgbox.display("Please select a script.") return elif self.whichSource == "Wordlist": if len(self.wordList) == 0: self.msgbox.display( "Please load a word list by clicking on the " "Files... button. When file settings are " "finished, click Get words.") return self.step = self.STEP_PRACTICE self.dlg.getModel().Step = self.step # change the dialog self.dlgCtrls.btnSwitch.Label = theLocale.getText( "Back to Settings") self.dlg.setTitle(theLocale.getText("Script Practice")) self.dlgCtrls.btnNextWord.setFocus() self.showNextQuestion() elif self.step == self.STEP_PRACTICE: self.step = self.STEP_SETTINGS self.dlg.getModel().Step = self.step # change the dialog self.dlgCtrls.btnSwitch.Label = theLocale.getText("Go to Practice") self.dlg.setTitle(theLocale.getText("Script Practice - Settings")) self.resetStats()
def questionFromList(self): logger.debug("questionFromList()") if len(self.datalist) == 0: self.questionString = theLocale.getText("(no words found)") else: word = random.choice(self.datalist) self.questionString = word.text
def showDlg(self): logger.debug(util.funcName(obj=self)) dlg = dutil.createDialog(self.unoObjs, _dlgdef) if not dlg: return ctrl_getter = dutil.ControlGetter(dlg) self.listbox = ctrl_getter.get(_dlgdef.WSLIST_BOX) btnOK = ctrl_getter.get(_dlgdef.BTN_OK) logger.debug("Got controls.") def_ws_display = theLocale.getText("(none)") self.listbox.addItem(def_ws_display, 0) for ws in self.writingSystems: listCount = self.listbox.getItemCount() ws_display = "%s (%s)" % (ws.name, ws.internalCode) self.listbox.addItem(ws_display, listCount) # add at end of list if ws.internalCode == self.def_ws_code: def_ws_display = ws_display self.listbox.selectItem(def_ws_display, True) logger.debug("Added " + str(len(self.writingSystems)) + " to list.") btnOK.setActionCommand("OK") btnOK.addActionListener(self) self.dlgClose = dlg.endExecute self.dlgDispose = dlg.dispose dlg.execute()
def __init__(self, exType, unoObjs): self.exType = exType self.unoObjs = unoObjs logger.debug("DlgGrabExamples() %s", exType) self.msgbox = MessageBox(unoObjs) if exType == EXTYPE_PHONOLOGY: USERVAR_PREFIX = Prefix.PHONOLOGY self.titleText = theLocale.getText("Get Phonology Examples") else: USERVAR_PREFIX = Prefix.INTERLINEAR self.titleText = theLocale.getText("Get Interlinear Examples") self.userVars = UserVars(USERVAR_PREFIX, unoObjs.document, logger) self.app = lingexamples.ExServices(exType, unoObjs) self.dlgCtrls = None self.evtHandler = None self.dlgClose = None logger.debug("DlgGrabExamples init() finished")
def __init__(self, unoObjs): self.scriptName = "" self.charset = dict() self.allFonts = styles.getListOfFonts(unoObjs) self.fontList = [] self.onlyKnownFonts = True theLocale.loadUnoObjs(unoObjs) self.fallbackFontDisplay = theLocale.getText("(Fallback Font)")
def addContents(self): """Add explanation text to the document.""" oVC = self.unoObjs.viewcursor # shorthand variable name oVC.gotoEnd(False) componentName = "LingTools" if self.VAR_PREFIX == Prefix.SCRIPT_PRACTICE: componentName = theLocale.getText("Script Practice") elif self.VAR_PREFIX == Prefix.WORD_LIST: componentName = theLocale.getText("Word Lists and Spelling") elif self.VAR_PREFIX == Prefix.SPELLING: componentName = theLocale.getText("Spelling") elif self.VAR_PREFIX == Prefix.BULK_CONVERSION: componentName = theLocale.getText("Bulk Conversion") elif self.VAR_PREFIX == Prefix.DATA_CONV_DRAW: componentName = theLocale.getText("Draw") elif self.VAR_PREFIX == Prefix.MAKE_OXT: componentName = theLocale.getText("Make OXT") message = theLocale.getText( "This document stores settings for %s. " "Please leave it open while using %s. " "If you want to keep the settings to use again later, " "then save this document.") % (componentName, componentName) self.unoObjs.text.insertControlCharacter(oVC, PARAGRAPH_BREAK, 0) self.unoObjs.text.insertControlCharacter(oVC, PARAGRAPH_BREAK, 0) self.unoObjs.text.insertString(oVC, message, 0) self.unoObjs.text.insertControlCharacter(oVC, PARAGRAPH_BREAK, 0)
def __str__(self): """Used for list box displaying and sorting. Call theLocale.loadUnoObjs() before using this method. """ logger.debug("str(WhatToGrab) %d %s", self.grabType, self.whichOne) if self.grabType == self.PART and self.whichOne == self.WHOLE_DOC: return theLocale.getText("Whole Document") if self.grabType in self.TITLES: display = theLocale.getText(self.TITLES[self.grabType]) if (self.grabType == self.FONT and self.fontType in ['Complex', 'Asian']): display += " (%s)" % theLocale.getText(self.fontType) val = self.whichOne if self.grabType == self.FIELD: val = self.LINGEX_DICT.get(val, val) val = theLocale.getText(val) return display + ": " + val return ""
def loadValues(self, userVars, fileItems, disposeWhenFinished): logger.debug("Initializing list of files") fileItems.loadUserVars() dutil.fill_list_ctrl(self.listboxFiles, fileItems.getItemTextList()) varname = 'Punctuation' if userVars.isEmpty(varname) and len(fileItems) == 0: punctToRemove = u" ".join(letters.PUNCTUATION) userVars.store(varname, punctToRemove) else: punctToRemove = userVars.get(varname) self.txtRemovePunct.setText(punctToRemove) varname = 'NormForm' if userVars.isEmpty(varname): userVars.store(varname, DEFAULT_NORM_FORM) if len(fileItems) == 0: self.btnMakeList.Label = theLocale.getText("Make Empty List") if not disposeWhenFinished: self.btnMakeList.Label = theLocale.getText("Get words")
def fillFieldList(self): """Fills listWhatToGrab based on self.filetype.""" count = self.dlgCtrls.listWhatToGrab.getItemCount() self.dlgCtrls.listWhatToGrab.removeItems(0, count) self.titles = [("", "")] if self.filetype in PhonReader.supportedNames(): self.titles.extend(lingex_structs.LingPhonExample.GRAB_FIELDS) elif self.filetype in InterlinReader.supportedNames(): self.titles.extend(lingex_structs.LingGramExample.GRAB_FIELDS) elif self.filetype in DocReader.supportedNames(): self.titles.append((WhatToGrab.WHOLE_DOC, "Whole Document")) elif self.filetype in CalcFileReader.supportedNames(): for char in string.ascii_uppercase: self.titles.append( (char, "%s %s" % (theLocale.getText("Column"), char))) if len(self.titles) > 1: stringList = [ theLocale.getText(display) for dummy_key, display in self.titles ] self.dlgCtrls.listWhatToGrab.addItems(tuple(stringList), 0)
def chooseSyllable(self, wordInitial, wordFinal): """Make a syllable of up to three characters in length.""" charset = self.script.charset firstcharset = charset["AnyVowels"] + charset["AnyConsonants"] if wordInitial: firstcharset += charset["WI_Vowels"] + charset["WI_Consonants"] if not firstcharset: self.questionString = theLocale.getText("(cannot make word)") return "" firstchar = random.choice(firstcharset) if self.script.getVirama() and not wordInitial: prevChar = self.questionString[-1:] # preceding this syllable logger.debug("prevChar %s", prevChar) if (firstchar in charset["AnyConsonants"] and prevChar in charset["AnyConsonants"]): # Insert virama in between two consonants logger.debug("Inserting virama") firstchar = self.script.getVirama() + firstchar if self.config.syllableSize <= 1: return firstchar singlefirstchar = firstchar[-1:] # make sure it's only one character logger.debug("firstchar %s", singlefirstchar) if (singlefirstchar in charset["WI_Consonants"] or singlefirstchar in charset["AnyConsonants"]): secondcharset = (charset["DepVowels"] + charset["AnyVowels"]) else: secondcharset = list(charset["AnyConsonants"]) # copy if wordFinal: secondcharset += charset["WF_Consonants"] if len(secondcharset) == 0: return firstchar secondchar = random.choice(secondcharset) if (self.config.syllableSize <= 2 or secondchar in charset["WI_Consonants"] or secondchar in charset["WF_Consonants"] or secondchar in charset["AnyConsonants"]): return firstchar + secondchar thirdcharset = list(charset["AnyConsonants"]) # copy if wordFinal: thirdcharset += charset["WF_Consonants"] if len(thirdcharset) == 0: return firstchar + secondchar thirdchar = random.choice(thirdcharset) return firstchar + secondchar + thirdchar
def fileRemove(self): logger.debug(util.funcName('begin')) try: itemPos = dutil.get_selected_index( self.dlgCtrls.listboxFiles, "a file") self.fileItems.deleteItem(itemPos) except exceptions.ChoiceProblem as exc: self.msgbox.displayExc(exc) return self.fileItems.storeUserVars() self.dlgCtrls.listboxFiles.removeItems(itemPos, 1) if len(self.fileItems) == 0 and self.disposeWhenFinished: self.dlgCtrls.btnMakeList.Label = theLocale.getText( "Make Empty List") # Select the next item dutil.select_index(self.dlgCtrls.listboxFiles, itemPos) logger.debug(util.funcName('end'))
def interpolate_message(message, msg_args): """ For example, given ("Hello %s", "John"), returns "Hello John". :arg message: string optionally containing values like %s to interpolate :arg msg_args: any arguments needed for interpolating the message string """ message = theLocale.getText(message) if msg_args and msg_args != ((), ): try: # for example "%d%d" % (a, b) message = message % msg_args except (TypeError, UnicodeDecodeError): # Calling logger.exception() here gets the stack trace. # However it also causes a crash during automated testing, # perhaps caused by lingttest.utils.testutil.MsgSentException # and lingt.ui.common.evt_handler.log_exceptions. raise LogicError("Message '%s' failed to interpolate arguments %r", message, msg_args) return message
def _outputList(self, wordList): headingRow = 0 # first row numberFormat = 0 # General format for colNum, heading in enumerate(self.colOrder.getTitles()): cell = self.sheet.getCellByPosition(colNum, headingRow) cell.setFormula("") cell.setPropertyValue("NumberFormat", numberFormat) cell.setString(theLocale.getText(heading)) cellFreeze = self.sheet.getCellByPosition(0, 1) self.listDoc.controller.select(cellFreeze) self.unoObjs.dispatcher.executeDispatch(self.listDoc.frame, ".uno:FreezePanes", "", 0, ()) CHUNK_SIZE = 25 # make this value bigger or smaller for optimization #CHUNK_SIZE = 1 # useful for debugging for word_i1 in range(0, len(wordList), CHUNK_SIZE): word_i2 = word_i1 + CHUNK_SIZE - 1 if word_i2 >= len(wordList): word_i2 = len(wordList) - 1 self._fillInData(wordList, word_i1, word_i2)
def fileAdd(self): logger.debug(util.funcName('begin')) newItem = WordListFileItem(self.userVars) dlgFile = DlgWordListFile(newItem, self.unoObjs, self.userVars) dlgFile.showDlg() ok = dlgFile.getResult() dlgFile.dlgDispose() if ok: logger.debug("Adding item text %s", newItem) try: self.fileItems.addItem(newItem) except exceptions.ChoiceProblem as exc: self.msgbox.displayExc(exc) return self.fileItems.storeUserVars() logger.debug("Successfully added.") dutil.fill_list_ctrl( self.dlgCtrls.listboxFiles, self.fileItems.getItemTextList(), str(newItem)) if self.disposeWhenFinished: self.dlgCtrls.btnMakeList.Label = theLocale.getText( "Make List") logger.debug("FileAdd end")
def __init__(self, genericUnoObjs, title): self.unoObjs = genericUnoObjs theLocale.loadUnoObjs(genericUnoObjs) self.titleText = theLocale.getText(title) self.progress = None self.val = 0 # needed because self.progress.Value is write-only
def display(self, message, *msg_args, **kwargs): """ :keyword arg title: dialog title :keyword arg buttonList: buttons to show on the dialog :returns: which button pressed, for example 'yes'; see DefaultButtons """ title = kwargs.get('title', "") buttonList = kwargs.get('buttonList', None) self.result = "" # create the dialog model and set the properties # create the dialog control and set the model dlgModel = self.unoObjs.smgr.createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", self.unoObjs.ctx) dlgModel.PositionX = 100 dlgModel.PositionY = 100 dlgModel.Width = 250 dlgModel.Height = 70 dlgModel.Title = theLocale.getText(title) ctrlContainer = self.unoObjs.smgr.createInstanceWithContext( "com.sun.star.awt.UnoControlDialog", self.unoObjs.ctx) # create the label model and set the properties message = exceptions.interpolate_message(message, msg_args) message += " " # padding so that it displays better lblModel = dlgModel.createInstance( "com.sun.star.awt.UnoControlFixedTextModel") lblModel.PositionX = 10 lblModel.PositionY = 10 lblModel.Width = 150 lblModel.Height = 14 lblModel.Name = "lblMessage" lblModel.TabIndex = 0 lblModel.Label = message dlgModel.insertByName("lblMessage", lblModel) # create the button models and set the properties if not buttonList: buttonList = FourButtonDialog.DefaultButtons for btn in getNamedTuples(buttonList): btnModel = dlgModel.createInstance( "com.sun.star.awt.UnoControlButtonModel") btnModel.PositionX = 10 + (btn.index * 60) btnModel.PositionY = 45 btnModel.Width = 50 btnModel.Height = 14 btnModel.Name = btn.name btnModel.TabIndex = btn.index + 1 btnModel.Label = theLocale.getText(btn.text) dlgModel.insertByName(btn.name, btnModel) ctrlContainer.setModel(dlgModel) for btn in getNamedTuples(buttonList): ctrl = ctrlContainer.getControl(btn.name) ctrl.setActionCommand(btn.action) ctrl.addActionListener(self) logger.debug("Added button %s", btn.name) # create a peer and execute the dialog toolkit = self.unoObjs.smgr.createInstanceWithContext( "com.sun.star.awt.ExtToolkit", self.unoObjs.ctx) ctrlContainer.setVisible(False) ctrlContainer.createPeer(toolkit, None) self.dlgClose = ctrlContainer.endExecute ctrlContainer.execute() # dispose the dialog ctrlContainer.dispose() return self.result