import gedit, gtk from gettext import gettext as _ # guenther: you just need to set the wrap-mode property on the # textview: in code something like # window.get_active_view().set_property("wrap-mode", gtk.WRAP_NONE) # guenther: with this http://live.gnome.org/Gedit/PythonPluginHowTo # and the line I pasted above you should have your plugin up and running in # about 5 minutes :) # Menu item example, insert a new item in the Tools menu ui_str = """ """ class LinewrapPluginInstance: def __init__(self, plugin, window): print "Plugin created for", window self._window = window self._plugin = plugin # Insert menu items self._insert_menu() def stop(self): # Remove any installed menu items self._remove_menu() print "Plugin stopped for", self._window self._window = None self._plugin = None self._action_group = None def _insert_menu(self): # Get the GtkUIManager manager = self._window.get_ui_manager() # Create a new action group self._action_group = gtk.ActionGroup("LinewrapPluginActions") # toggle = gtk.ToggleAction("Linewrap", _("Text _Wrapping"), # _("Toggle Text Wrapping for the current Document"), None) # self._action_goup.add_toggle_actions( # [( toggle, # lambda a: self.on_toggle_linewrap_activate() )] ) # self._action_group.add_actions( self._action_group.add_toggle_actions( [( "Linewrap", None, _("Text _Wrapping"), None, _("Toggle Text Wrapping for the current Document"), lambda a: self.on_toggle_linewrap_activate() )] ) # Insert the action group manager.insert_action_group(self._action_group, -1) # Merge the UI self._ui_id = manager.add_ui_from_string(ui_str) def _remove_menu(self): # Get the GtkUIManager manager = self._window.get_ui_manager() # Remove the ui manager.remove_ui(self._ui_id) # Remove the action group manager.remove_action_group(self._action_group) # Make sure the manager updates manager.ensure_update() def update(self): print "Plugin update" self._action_group.set_sensitive( self._window.get_active_document() != None) view = self._window.get_active_view() if not view: return print "Update" self._action_group.get_action("Linewrap").set_active( view.get_property("wrap-mode") != gtk.WRAP_NONE) # Menu activate handlers def on_toggle_linewrap_activate(self): doc = self._window.get_active_document() if not doc: return view = self._window.get_active_view() wrap = self._action_group.get_action("Linewrap").get_active() print "Toggle" if wrap: view.set_property("wrap-mode", gtk.WRAP_WORD) else: view.set_property("wrap-mode", gtk.WRAP_NONE) # if view.get_property("wrap-mode") == gtk.WRAP_NONE: # view.set_property("wrap-mode", gtk.WRAP_WORD) # print " wrap WORD" # else: # view.set_property("wrap-mode", gtk.WRAP_NONE) # print " wrap NONE" class LinewrapPlugin(gedit.Plugin): DATA_TAG = "LinewrapPluginInstance" def __init__(self): gedit.Plugin.__init__(self) def _get_instance(self, window): return window.get_data(self.DATA_TAG) def _set_instance(self, window, instance): window.set_data(self.DATA_TAG, instance) def activate(self, window): self._set_instance(window, LinewrapPluginInstance(self, window)) def deactivate(self, window): self._get_instance(window).stop() self._set_instance(window, None) def update_ui(self, window): self._get_instance(window).update()