def create_abbreviation(self, folder, description, abbr, contents): """ Create a text abbreviation Usage: C{engine.create_abbreviation(folder, description, abbr, contents)} When the given abbreviation is typed, it will be replaced with the given text. @param folder: folder to place the abbreviation in, retrieved using C{engine.get_folder()} @param description: description for the phrase @param abbr: the abbreviation that will trigger the expansion @param contents: the expansion text @raise Exception: if the specified abbreviation is not unique """ if not self.configManager.check_abbreviation_unique(abbr, None, None): raise Exception("The specified abbreviation is already in use") self.monitor.suspend() p = model.Phrase(description, contents) p.modes.append(model.TriggerMode.ABBREVIATION) p.abbreviations = [abbr] folder.add_item(p) p.persist() self.monitor.unsuspend() self.configManager.config_altered(False)
def on_clone(self): source_object = self.__getSelection()[0] tree_widget = self.treeWidget # type: ak_tree.AkTreeWidget parent_item = tree_widget.selectedItems()[0].parent( ) # type: ak_tree.ItemWidgetType parent = self.__extractData(parent_item) if isinstance(source_object, model.Phrase): new_obj = model.Phrase('', '') new_obj.copy(source_object) new_item = ak_tree.PhraseWidgetItem(parent_item, new_obj) else: new_obj = model.Script('', '') new_obj.copy(source_object) new_item = ak_tree.ScriptWidgetItem(parent_item, new_obj) parent.add_item(new_obj) self.window().app.monitor.suspend() new_obj.persist() self.window().app.monitor.unsuspend() tree_widget.sortItems(0, Qt.AscendingOrder) tree_widget.setCurrentItem(new_item) parent_item.setSelected(False) self.on_treeWidget_itemSelectionChanged() self.window().app.config_altered(False)
def on_copy(self): source_objects = self.__getSelection() for source in source_objects: if isinstance(source, model.Phrase): new_obj = model.Phrase('', '') else: new_obj = model.Script('', '') new_obj.copy(source) self.cutCopiedItems.append(new_obj)
def create_hotkey(self, folder, description, modifiers, key, contents, temporary=False): """ Create a text hotkey Usage: C{engine.create_hotkey(folder, description, modifiers, key, contents)} When the given hotkey is pressed, it will be replaced with the given text. Modifiers must be given as a list of strings, with the following values permitted: <ctrl> <alt> <super> <hyper> <meta> <shift> The key must be an unshifted character (i.e. lowercase) @param folder: folder to place the abbreviation in, retrieved using C{engine.get_folder()} @param description: description for the phrase @param modifiers: modifiers to use with the hotkey (as a list) @param key: the hotkey @param contents: the expansion text @param (optional) temporary: Hotkeys created with temporary=True are not persisted as .jsons, and are replaced if the description is not unique within the folder. Used for single-source rc-style scripts. @raise Exception: if the specified hotkey is not unique """ modifiers.sort() if not self.configManager.check_hotkey_unique(modifiers, key, None, None): raise Exception( "The specified hotkey and modifier combination is already in use" ) self.monitor.suspend() p = model.Phrase(description, contents) p.modes.append(model.TriggerMode.HOTKEY) p.set_hotkey(modifiers, key) folder.add_item(p) # Don't save a json if it is a temporary hotkey. Won't persist across # reloads. if not temporary: p.persist() self.monitor.unsuspend() self.configManager.config_altered(False)
def on_new_phrase(self): self.window().app.monitor.suspend() parent_item = self.treeWidget.selectedItems()[0] parent = self.__extractData(parent_item) phrase = model.Phrase("New Phrase", "Enter phrase contents") new_item = ak_tree.PhraseWidgetItem(parent_item, phrase) parent.add_item(phrase) phrase.persist() self.window().app.monitor.unsuspend() self.treeWidget.sortItems(0, Qt.AscendingOrder) self.treeWidget.setCurrentItem(new_item) self.treeWidget.setItemSelected(parent_item, False) self.on_treeWidget_itemSelectionChanged() self.on_rename()
def create_phrase(self, folder, description, contents): """ Create a text phrase Usage: C{engine.create_phrase(folder, description, contents)} A new phrase with no abbreviation or hotkey is created in the specified folder @param folder: folder to place the abbreviation in, retrieved using C{engine.get_folder()} @param description: description for the phrase @param contents: the expansion text """ self.monitor.suspend() p = model.Phrase(description, contents) folder.add_item(p) p.persist() self.monitor.unsuspend() self.configManager.config_altered(False)