def __init__(self): gedit.Plugin.__init__(self) self.action_group = None self.ui_id = None self.window = None self.analyser = DocAnalyser()
class EasyGuiCodePlugin(gedit.Plugin): def __init__(self): gedit.Plugin.__init__(self) self.action_group = None self.ui_id = None self.window = None self.analyser = DocAnalyser() def activate(self, window): self.window = window self.action_group = gtk.ActionGroup('EasyGuiCodePluginActions') self.action_group.add_actions([( 'OpenGuiFile', gtk.STOCK_PAGE_SETUP, 'Open _GUI file...', None, 'Opens the GtkBuilder .glade file being used in the code', self.on_open_gui_file_activate )]) uim = window.get_ui_manager() uim.insert_action_group(self.action_group, -1) self.ui_id = uim.add_ui_from_string( ui ) def deactivate(self, window): uim = window.get_ui_manager() uim.remove_ui(self.ui_id) uim.remove_action_group(self.action_group) uim.ensure_update() self.action_group = None self.ui_id = None self.window = None def on_open_gui_file_activate(self, *args): doc = self.window.get_active_document() view = self.window.get_active_view() self.analyser.inspect( doc, view ) doc_file = doc.get_uri() if doc_file == None: NewCode().run( parentWindow = self.window, doc = doc ) return doc_file = gio.File( doc_file ).get_path() doc_dir = os.path.dirname( doc_file ) if self.analyser.builder_file == None: NewCode().run( parentWindow = self.window, doc = doc, dir_path = doc_dir ) return glade_file = os.path.join( doc_dir, self.analyser.builder_file ) if os.path.exists( glade_file ): IDE().run( \ glade_file = glade_file, \ parentWindow = self.window, \ analyser = self.analyser ) else: alert( "Glade file being used <b>%s</b> was not found!" % glade_file, \ "Open GUI file" ) def update_ui(self, window): doc = self.window.get_active_document() self.action_group.set_sensitive(doc is not None)