def deactivate(self, window): """ Stop the plugin """ windowHelper = window.get_data(GrammalecteWindowHelper.DATA_TAG) if windowHelper is not None: windowHelper.deactivate() window.set_data(GrammalecteWindowHelper.DATA_TAG, None) GrammalecteConfig.terminate()
def test_analyze(self): config = GrammalecteConfig() if os.path.exists(config.get_value(GrammalecteConfig.GRAMMALECTE_CLI)): self.analyzer.add_request(self.requester) self.mainloop.run() self.assertGreaterEqual(self.requester.grammar_errors, 16) self.assertEqual(self.requester.spelling_errors, 2) else: print "WARNING: Grammalecte not found, tests skipped"
def __init__(self): """ Initialize the analyzer """ gobject.GObject.__init__(self) # Define instance data self._queue = Queue.Queue() self._input = _TempFile() self._output = _TempFile() self._error = _TempFile() self.__state = _StateWaiting(self) # Define timer config = GrammalecteConfig() gobject.timeout_add( config.get_value(GrammalecteConfig.AUTO_ANALYZE_TIMER), self.__run)
def __init__(self, view, document, windowHelper): """ Initialize the helper """ self.__view = view self.__document = document self.__windowHelper = windowHelper self.__filename = self.__document.get_uri() self.__gFile = None if self.__filename is None else \ gio.File(self.__filename) self.__config = GrammalecteConfig(self) self.__autocorrect = None if self.is_auto_checked(): self.__set_auto_analyze(True) self.__eventDocSavedId = self.__document.connect( "saved", self.on_doc_saved) self.__eventDocLoadedId = self.__document.connect( "loaded", self.on_doc_loaded)
def __init__(self, analyzer, result_action): self.config = GrammalecteConfig() self.example = "Quoi ? Racontes ! Racontes-moi ! Bon sangg, parles !" \ " Oui. Il y a des menteur partout. Je suit sidéré par la" \ " brutales arrogance de cette homme-là. Quelle salopard ! Un" \ " escrocs de la pire espece. Quant sera t’il châtiés pour ses" \ " mensonge ? Merde ! J’en aie marre." self.result_action = result_action self.grammar_errors = 0 self.spelling_errors = 0 analyzer.connect("analyze-finished", self.on_result)
def run(self): """ Execute the dialog """ config = GrammalecteConfig() if self.__viewHelper == None else \ self.__viewHelper.get_config() response = GrammalecteConfigDlg.__RESPONSE_CLEAR while response == GrammalecteConfigDlg.__RESPONSE_CLEAR: response = self.__dialog.run() if response == GrammalecteConfigDlg.__RESPONSE_CLEAR: self.__clear_config(config) self.__dialog.destroy() if response == gtk.RESPONSE_ACCEPT: forGlobal = True if self.__globalToggle == None else \ self.__globalToggle.get_active() self.__update_config(forGlobal) self.__save_config(config) return response == gtk.RESPONSE_ACCEPT
def __extract_options(self): """ Grab the options from Grammalecte """ config = GrammalecteConfig() if self.__viewHelper == None else \ self.__viewHelper.get_config() waitDlg = gtk.MessageDialog( self.__activeWindow, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, message_format = _("Preparing Grammalecte options...")) waitDlg.show() self.__flush_events() self.__set_options(self.__call_grammalecte( config.get_value(GrammalecteConfig.GRAMMALECTE_PYTHON_EXE), config.get_value(GrammalecteConfig.GRAMMALECTE_CLI), config.get_value(GrammalecteConfig.GRAMMALECTE_OPTIONS_PARAMS)), config.get_value(GrammalecteConfig.GRAMMALECTE_OPTIONS_REGEX)) self.__set_options_value( GrammalecteConfig(), GrammalecteConfigDlg.__OPTION_GVAL) self.__copy_global_in_file() self.__set_options_value(config, GrammalecteConfigDlg.__OPTION_FVAL) waitDlg.destroy() self.__flush_events()
class GrammalecteViewHelper(SelfConfigContainer): """ A helper attached to the view """ DATA_TAG = "GrammalecteViewHelper" __CONFIG_METADATA = "metadata::pluma-grammalecte" def __init__(self, view, document, windowHelper): """ Initialize the helper """ self.__view = view self.__document = document self.__windowHelper = windowHelper self.__filename = self.__document.get_uri() self.__gFile = None if self.__filename is None else \ gio.File(self.__filename) self.__config = GrammalecteConfig(self) self.__autocorrect = None if self.is_auto_checked(): self.__set_auto_analyze(True) self.__eventDocSavedId = self.__document.connect( "saved", self.on_doc_saved) self.__eventDocLoadedId = self.__document.connect( "loaded", self.on_doc_loaded) def deactivate(self): """ Disconnect the helper from the view """ self.__document.disconnect(self.__eventDocLoadedId) self.__document.disconnect(self.__eventDocSavedId) self.__set_auto_analyze(False) self.__config.close() self.__config = None self.__gFile = None self.__filename = None self.__windowHelper = None self.__document = None self.__view = None def set_auto_analyze(self, active): """ Set auto-analyze to active or not. :param active: indicate if auto-analyze must be active or not. :type active: boolean """ self.__config.set_value(GrammalecteConfig.AUTO_ANALYZE_ACTIVE, active) self.__set_auto_analyze(active) def __set_auto_analyze(self, active): """ Set auto-analyze without changing the configuration """ if active and self.__autocorrect == None: self.__autocorrect = GrammalecteAutoCorrector(self) elif not active and self.__autocorrect != None: self.__autocorrect.deactivate() self.__autocorrect = None def refresh_analyze(self): """ Execute the analyze as it may be obsolete """ if self.__autocorrect != None: self.__autocorrect.ask_request() def on_doc_saved(self, document, error): """ Manage the document saved event """ if error == None: self.__filename = self.__document.get_uri() self.__gFile = None if self.__filename is None else \ gio.File(self.__filename) def on_doc_loaded(self, document, error): """ Manage the document loaded event """ if error == None and (self.__document != document or \ self.__filename != document.get_uri() or \ (self.__autocorrect != None) != self.is_auto_checked()): view = self.__view windowHelper = self.__windowHelper self.deactivate() self.__init__(view, document, windowHelper) self.__windowHelper.update_ui() def get_self_config(self): """ Get the configuration from metadata """ config = None if self.__gFile != None: info = self.__gFile.query_info( GrammalecteViewHelper.__CONFIG_METADATA) config = info.get_attribute_as_string( GrammalecteViewHelper.__CONFIG_METADATA) if config == None: config = SelfConfigContainer.EMPTY return config def set_self_config(self, config): """ Set the configuration in metadata """ if self.__gFile != None: self.__gFile.set_attribute_string( GrammalecteViewHelper.__CONFIG_METADATA, config) def is_auto_checked(self): """ Indicate if automatic check is on """ return self.__config.get_value(GrammalecteConfig.AUTO_ANALYZE_ACTIVE) \ and not self.is_readonly() def is_readonly(self): """ Indicate if the associated document is read-only """ return not self.__view.get_editable() def get_view(self): """ Get the (real) view attached to the helper """ return self.__view def get_config(self): """ Get the configuration of the helper """ return self.__config def get_analyzer(self): """ Get the analyzer """ return self.__windowHelper.get_analyzer()