def _preview_cb(self, action): project = self.get_current_project() if not project.selection: return xml = project.serialize() builder = ObjectBuilder(buffer=xml) toplevel = project.selection[0].get_toplevel() widget = builder.get_widget(toplevel.get_name()) widget.show_all()
class Proxy(object): def __init__(self, gladefile=None, gladestream=None, root=None): self._wt = ObjectBuilder(filename=gladefile, buffer=gladestream, root=root) self._signal_magicconnect() def signal_autoconnect(self, dic): self._wt.signal_autoconnect(dic) def _signal_magicconnect(self): """Look for our methods to see if we need to connect any signal. This is copied from Kiwi.""" actions = [] if self._uimanager is not None: for a in [ag.list_actions() for ag in \ self._uimanager.get_action_groups()]: actions.extend(a) self._connect_methods('on_', actions) self._connect_methods('after_', actions) def _connect_methods(self, method_prefix, actions): methods = [m for m in getmembers(self) \ if ismethod(m[1]) and m[0].find(method_prefix) == 0] for name, method in methods: index = name.rfind('__') widget_name = name[len(method_prefix):index] signal_name = name[index+2:] try: # First we look in the widgets widget = self._wt.get_widget(widget_name) if not widget: raise AttributeError if method_prefix == 'on_': widget.connect(signal_name, method) elif method_prefix == 'after_': widget.connect_after(signal_name, method) except AttributeError: # Now we try to find it in the actions for action in actions: if widget_name == action.get_name(): if method_prefix == 'on_': action.connect(signal_name, method) elif method_prefix == 'after_': action.connect_after(signal_name, method) break else: print ('Warning: the widget %s is not on my widget tree ' 'neither in the action list') % widget_name def __getattr__(self, name): """Easy way to access the widgets by their name.""" return self._wt.get_widget(name) def get_widgets(self): """Returns an iterator to loop through the widgets.""" return self._wt.widgets widgets = property(get_widgets)
controller.store_current_translation() controller.save_project() def cb_next_button(self): controller.store_current_translation() controller.next() def cb_back_button(self): controller.previous() def cb_spin_change(self): newValue = wt.get_widget('spinCurrentLine').get_value_as_int() controller.go_to(newValue) def cb_export_to_srt(self): controller.export_to_srt() if __name__ == '__main__': wt.get_widget('window1').show_all() wt.signal_autoconnect(Callbacks.__dict__) wt.get_widget('Save').set_sensitive(False) wt.get_widget('SaveAs').set_sensitive(False) wt.get_widget('ExportSRT').set_sensitive(False) if ( gconf['currentFile'] ): if ( os.path.exists(gconf['currentFile'])): controller.load_sml_file(gconf['currentFile']) controller.go_to(gconf['currentLine']) gtk.main()
class PreferencesDialog: def __init__(self): self.app = get_utility(IGazpachoApp) self.plugin_manager = get_utility(IPluginManager) ui_file = environ.find_resource('glade', 'preferences.glade') app_window = self.app.get_window() self.ob = ObjectBuilder(ui_file) self.dialog = self.ob.get_widget('dialog') # dialog setup self.dialog.set_modal(True) self.dialog.set_transient_for(app_window) # this should go into the glade file as soon as we get support for it close = self.ob.get_widget('close') close.connect('clicked', self.on_close__clicked) # setup each tab self._setup_plugins_tab() def on_close__clicked(self, button): self.dialog.response(gtk.RESPONSE_CLOSE) def run(self): self.dialog.show() self.dialog.run() self.dialog.destroy() def _setup_plugins_tab(self): plugin_list = self.ob.get_widget('plugins_list') model = gtk.ListStore(bool, str, object) # fill the model for plugin_info in self.plugin_manager.get_plugins(): activated = self.plugin_manager.is_activated(plugin_info.name) model.append((activated, plugin_info.title, plugin_info)) plugin_list.set_model(model) # make the cells editable toggle = self.ob.get_widget('treeviewcolumn1-renderer1') toggle.set_property('activatable', True) toggle.connect('toggled', self.on_plugin__activated, model) # disable buttons plugin_about = self.ob.get_widget('plugin_about') plugin_about.set_sensitive(False) plugin_about.connect('clicked', self.on_plugin_about__clicked) plugin_preferences = self.ob.get_widget('plugin_preferences') plugin_preferences.set_sensitive(False) plugin_preferences.connect('clicked', self.on_plugin_prefs__clicked) selection = plugin_list.get_selection() selection.connect('changed', self.on_plugin_selection__changed) def on_plugin__activated(self, cell, path, model): row = model[path] new_value = not row[COL_ACTIVATED] row[COL_ACTIVATED] = new_value plugin = row[COL_PLUGININFO] if new_value: self.plugin_manager.activate_plugin(plugin.name, self.app) else: self.plugin_manager.deactivate_plugin(plugin.name) plugin_preferences = self.ob.get_widget('plugin_preferences') plugin_preferences.set_sensitive(new_value) config.set_plugin(plugin.name, new_value) def on_plugin_selection__changed(self, selection): model, model_iter = selection.get_selected() plugin_about = self.ob.get_widget('plugin_about') plugin_preferences = self.ob.get_widget('plugin_preferences') if model_iter: plugin_about.set_sensitive(True) activated = model.get_value(model_iter, COL_ACTIVATED) plugin_preferences.set_sensitive(activated) else: plugin_about.set_sensitive(False) plugin_preferences.set_sensitive(False) def on_plugin_about__clicked(self, button): plugin_info = self._get_selected_plugin() if plugin_info: dialog = gtk.AboutDialog() dialog.set_name(plugin_info.title) dialog.set_version(plugin_info.version) dialog.set_comments(plugin_info.description) dialog.set_authors([plugin_info.author]) dialog.set_transient_for(self.dialog) dialog.run() dialog.destroy() def on_plugin_prefs__clicked(self, button): plugin_info = self._get_selected_plugin() if plugin_info: self.plugin_manager.show_plugin_preferences(plugin_info.name, self.dialog) def _get_selected_plugin(self): plugin_list = self.ob.get_widget('plugins_list') selection = plugin_list.get_selection() model, model_iter = selection.get_selected() if model_iter: return model.get_value(model_iter, COL_PLUGININFO)