def __init__(self): gtk.TreeView.__init__(self) self.dct = None self.column_name = gtk.TreeViewColumn(_('Name')) self.column_name.set_resizable(True) self.cell_name = gtk.CellRendererText() self.column_name.pack_start(self.cell_name, False) self.append_column(self.column_name) self.column_name.set_cell_data_func(self.cell_name, self.name_data_func) self.cell_name.set_property('editable', True) self.cell_name.connect('edited', self.name_edited) self.cell_name.connect('editing-started', self.editing_started, 0) self.column_value = gtk.TreeViewColumn(_('Value')) self.column_value.set_resizable(True) self.cell_value = gtk.CellRendererText() self.column_value.pack_start(self.cell_value, False) self.append_column(self.column_value) self.column_value.set_cell_data_func(self.cell_value, self.value_data_func) self.cell_value.set_property('editable', True) self.cell_value.connect('edited', self.value_edited) self.cell_value.connect('editing-started', self.editing_started, 1)
def open_project(self, window, filename): if not self.close_project(False): return f = open(filename) file = File(f.read()) f.close() if file.version != mprj.project_version: moo.error_dialog( window, _("Could not open project '%s'") % (filename, ), _("Invalid project version %s") % (file.version, )) return file.path = filename project_type = self.project_types.get(file.project_type) config_type = getattr(project_type, '__config__') config = config_type(file) self.project = project_type(window, config, file) self.project.load() self.__set_title_prefix(self.project.name) self.recent_list.add_filename(filename) moo.prefs_set_string("Plugins/Project/last", filename) close = self.window.get_action("CloseProject") options = self.window.get_action("ProjectOptions") if close: close.set_property("sensitive", True) if options: options.set_property("visible", True)
class RunOptions(Group): __items__ = { 'exe': String(name=_('Script file')), 'args': String(name=_('Arguments')), 'vars': Dict(str, xml_elm_name='var'), } __item_name__ = _('Run options')
def __call__(self, window): action = moo.MenuAction("OpenRecentProject", _("Open Recent Project")) action.set_property('display-name', _("Open Recent Project")) action.set_mgr(self.mgr.recent_list.get_menu_mgr()) moo.bind_bool_property(action, "sensitive", self.mgr.recent_list, "empty", True) return action
def rename_config_cb(self, *whatever): combo = self.xml.w_configuration iter = combo.get_active_iter() store = combo.get_model() config = store.get_value(iter, 1) name = config.name new_name = mprj.utils.entry_dialog(parent=self, label=_("Enter new name"), entry_content=name, title=_("Enter new name")) if not new_name or new_name == name: return if self.config.configurations.has_key(new_name): mprj.utils.error_dialog( parent=self, text=_("Configuration '%s' already exists") % (new_name)) return was_active = self.config.active == name self.config.rename_conf(name, new_name) store.set_value(iter, 0, new_name) if was_active: self.config.active = new_name
class RunOptions(Group): __items__ = { 'run_from' : RunFrom, 'exe' : String(name=_('Executable')), 'args' : String(name=_('Arguments')), 'vars' : Dict(str, xml_elm_name='var') } __item_name__ = _('Run options')
class BuildConfiguration(Group): __items__ = { 'build_dir' : String(name=_('Build directory')), 'configure' : ConfigureOptions } __item_name__ = _('Build configuration') def copy_from(self, other): self.name = other.name return Group.copy_from(self, other) def load(self, node): self.name = node.get_attr('name') Group.load(self, node)
class RunOptionsPage(mprj.optdialog.ConfigPage): __label__ = _('Run options') __types__ = {'vars': DictView, 'exe': Entry, 'args': Entry} def do_init(self): mprj.optdialog.ConfigPage.do_init(self) self.xml.w_vars.set_dict(self.config.run.vars) self.xml.w_exe.set_setting(self.config.run['exe']) self.xml.w_args.set_setting(self.config.run['args']) run_from = self.config.run.run_from if run_from == RUN_FROM_BUILD_DIR: self.xml.w_build_dir.set_active(True) elif run_from == RUN_FROM_EXE_DIR: self.xml.w_exe_dir.set_active(True) else: self.xml.w_custom_dir.set_active(True) self.xml.w_custom_dir_entry.set_text(run_from) moo.bind_sensitive(self.xml.w_custom_dir, self.xml.w_custom_dir_entry) def do_apply(self): mprj.optdialog.ConfigPage.do_apply(self) if self.xml.w_build_dir.get_active(): self.config.run.run_from = RUN_FROM_BUILD_DIR elif self.xml.w_exe_dir.get_active(): self.config.run.run_from = RUN_FROM_EXE_DIR else: self.config.run.run_from = self.xml.w_custom_dir_entry.get_text()
def do_create(self): label = moo.PaneLabel(icon_name=moo.STOCK_TERMINAL, label_text=_("Terminal")) self.terminal = Terminal() self.terminal.set_scrollback_lines(1000000) self.terminal.connect("child-exited", self.start) self.start() frame = gtk.Frame() hbox = gtk.HBox() frame.add(hbox) hbox.pack_start(self.terminal) scrollbar = gtk.VScrollbar(self.terminal.get_adjustment()) hbox.pack_start(scrollbar, False, False, 0) frame.show_all() self.terminal.set_size(self.terminal.get_column_count(), 10) self.terminal.set_size_request(10, 10) self.pane = self.get_window().add_pane(TERMINAL_PLUGIN_ID, frame, label, moo.PANE_POS_BOTTOM) self.icon_title_changed_cb_id = self.terminal.connect( 'icon-title-changed', self.terminal_icon_title_changed) self.terminal_icon_title_changed() return True
def __location_button_clicked(self, *whatever): path = moo.file_dialogp(self.xml.w_dialog, moo.FILE_DIALOG_OPEN_DIR, self.xml.w_location.get_text(), _("Choose Folder"), mprj.utils.prefs_key('new_project_dir')) if path: self.xml.w_location.set_text(path)
def get_build_pane(self, window): pane = window.get_pane(_BUILD_PANE_ID) if not pane: label = moo.PaneLabel(icon_name=_STOCK_BUILD, label_text=_("Build Messages")) output = moo.CmdView() window.add_stop_client(output) if 1: output.set_property("highlight-current-line", True) output.set_wrap_mode(gtk.WRAP_NONE) else: output.set_property("highlight-current-line", False) output.set_wrap_mode(gtk.WRAP_CHAR) output.set_filter(moo.command_filter_create('make')) pane = gtk.ScrolledWindow() pane.set_shadow_type(gtk.SHADOW_ETCHED_IN) pane.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) pane.add(output) pane.show_all() pane.output = output window.add_pane(_BUILD_PANE_ID, pane, label, moo.PANE_POS_BOTTOM) return pane
class MakeOptions(Group): __items__ = { 'cmd' : String(default='make'), 'args' : String(null_ok=True), 'vars' : Dict(str, xml_elm_name='var') } __item_name__ = _('Make options')
def init(self, project): editor = moo.Editor.instance() editor.set_property("allow-empty-window", True) editor.set_property("single-window", True) moo.window_class_add_action(moo.EditWindow, "NewProject", display_name=_("New Project"), label=_("New Project..."), stock_id=moo.STOCK_NEW_PROJECT, callback=self.new_project_cb) moo.window_class_add_action(moo.EditWindow, "OpenProject", display_name=_("Open Project"), label=_("Open Project"), stock_id=moo.STOCK_OPEN_PROJECT, callback=self.open_project_cb) moo.window_class_add_action(moo.EditWindow, "ProjectOptions", display_name=_("Project _Options"), label=_("Project Options"), stock_id=moo.STOCK_PROJECT_OPTIONS, callback=self.project_options_cb) moo.window_class_add_action(moo.EditWindow, "CloseProject", display_name=_("Close Project"), label=_("Close Project"), stock_id=moo.STOCK_CLOSE_PROJECT, callback=self.close_project_cb) self.__init_project_types() self.project_to_open = project self.project = None self.window = None self.recent_list = moo.HistoryList("ProjectManager") self.recent_list.connect("activate_item", self.recent_item_activated) moo.window_class_add_action(moo.EditWindow, "OpenRecentProject", factory=_OpenRecent(self)) xml = editor.get_ui_xml() self.merge_id = xml.new_merge_id() xml.insert_markup_after( self.merge_id, "Editor/Menubar", "View", """ <item name="Project" _label="%s"> <item action="NewProject"/> <item action="OpenProject"/> <item action="OpenRecentProject"/> <separator/> <item action="ProjectOptions"/> <separator/> <item action="CloseProject"/> <separator/> </item> """ % (N_("_Project"), ))
def value_data_func(self, column, cell, model, iter): data = model.get_value(iter, 0) if data[1] is None: cell.set_property('text', _('click to edit...')) cell.set_property('style', pango.STYLE_ITALIC) # cell.set_property('foreground', 'grey') else: cell.set_property('text', data[1]) cell.set_property('style', pango.STYLE_NORMAL)
def popup_menu(self, event=None): menu = gtk.Menu() item = gtk.ImageMenuItem(gtk.STOCK_COPY) item.connect('activate', lambda *whatever: self.copy_clipboard()) item.set_sensitive(self.get_has_selection()) menu.append(item) item = gtk.ImageMenuItem(gtk.STOCK_PASTE) item.connect('activate', lambda *whatever: self.paste_clipboard()) menu.append(item) item = gtk.MenuItem(_("“cd” to current file directory")) item.connect('activate', lambda *whatever: self.goto_file_dir(False)) menu.append(item) if self._support_pushd: item = gtk.MenuItem(_("“pushd” to current file directory")) item.connect('activate', lambda *whatever: self.goto_file_dir(True)) menu.append(item) menu.append(gtk.SeparatorMenuItem()) item = gtk.MenuItem(D_("Input _Methods", "gtk20")) submenu = gtk.Menu() item.set_submenu(submenu) self.im_append_menuitems(submenu) menu.append(item) menu.append(gtk.SeparatorMenuItem()) item = gtk.ImageMenuItem(gtk.STOCK_PROPERTIES) submenu = gtk.Menu() item.set_submenu(submenu) menu.append(item) self.fill_settings_menu(submenu) if event is not None: button = event.button time = event.time else: button = 0 time = 0 menu.show_all() menu.popup(None, None, None, button, time)
class BuildCommandsPage(mprj.optdialog.ConfigPage): __label__ = _('Build commands') __types__ = {'commands': GroupView} def do_init(self): mprj.optdialog.ConfigPage.do_init(self) self.xml.w_commands.set_group(self.config.commands) def do_apply(self): mprj.optdialog.ConfigPage.do_apply(self)
class Commands(Group): __items__ = { 'build' : Command(default=['$(top_builddir)', '$(make)']), 'compile' : Command(default=['$(builddir)', '$(make) $(base).lo']), 'configure' : Command(default=['$(top_builddir)', '$(configure_vars) $(top_srcdir)/configure $(configure_args)']), 'autogen' : Command(default=['$(top_builddir)', '$(configure_vars) $(top_srcdir)/autogen.sh $(configure_args)']), 'clean' : Command(default=['$(top_builddir)', '$(make) clean']), 'distclean' : Command(default=['$(top_builddir)', '$(make) distclean']), 'install' : Command(default=['$(top_builddir)', '$(make) install']), } __item_name__ = _('Build commands')
def add_config_cb(self, *whatever): name = mprj.utils.entry_dialog(parent=self, label=_("Enter configuration name"), title=_("Enter configuration name")) if not name: return if self.config.configurations.has_key(name): mprj.utils.error_dialog( parent=self, text=_("Configuration '%s' already exists") % (name)) return new_conf = self.config.add_conf(name) combo = self.xml.w_configuration store = combo.get_model() iter = store.append([name, new_conf]) combo.set_active_iter(iter)
def open_project_cb(self, window): filename = moo.file_dialogp(parent=window, title=_("Open Project"), prefs_key="Plugins/Project/last_dir") if not filename: return try: self.open_project(window, filename) except Exception, e: self.bad_project(window, filename, e)
def init_ui(self): SimpleProject.init_ui(self) self.panes.extend([_OUTPUT_PANE_ID]) commands = [ [ "Execute", _("Execute Program"), _STOCK_EXECUTE, "F9", _CMD_EXECUTE ], [ "ExecuteFile", _("Execute File"), _STOCK_EXECUTE, "<shift>F9", _CMD_EXECUTE_FILE ], ] for c in commands: self.add_action("PyProject" + c[0], display_name=c[1], label=c[1], stock_id=c[2], default_accel=c[3], callback=PyProject.DoCmd(self, c[4])) editor = moo.Editor.instance() xml = editor.get_ui_xml() xml.insert_markup_after( self.merge_id, "Editor/Menubar", "Project", """ <item name="Build" _label="%s"> <item action="PyProjectExecute"/> <item action="PyProjectExecuteFile"/> </item> """ % (N_("_Build"), )) xml.insert_markup( self.merge_id, "Editor/Toolbar/BuildToolbar", 0, """ <item action="PyProjectExecute"/> <separator/> """)
class ConfigPage(mprj.optdialog.ConfigPage): __label__ = _("General") __types__ = {'vars': DictView, 'name': Entry} def __init__(self, config): mprj.optdialog.ConfigPage.__init__( self, "page", config, os.path.join(os.path.dirname(__file__), "simple.glade")) def do_init(self): mprj.optdialog.ConfigPage.do_init(self) self.xml.w_vars.set_dict(self.config.general.vars) def do_apply(self): mprj.optdialog.ConfigPage.do_apply(self)
class RunFrom(Setting): __item_name__ = _('Run from') __item_default__ = RUN_FROM_BUILD_DIR def equal(self, value): if value is None: value = 0 return Setting.equal(self, value) def set_string(self, value): raise RuntimeError() def check_value(self, value): return value in [RUN_FROM_BUILD_DIR, RUN_FROM_EXE_DIR] or \ (isinstance(value, str) and value != '') def load(self, node): type_s = node.get_attr('type') if type_s == 'build-dir': return self.set_value(RUN_FROM_BUILD_DIR) elif type_s == 'exe-dir': return self.set_value(RUN_FROM_EXE_DIR) elif type_s == 'dir': return self.set_value(node.get()) else: raise RuntimeError() def save(self): if self.is_default(): return [] value = self.get_value() if value in [RUN_FROM_BUILD_DIR, RUN_FROM_EXE_DIR]: dir = None else: dir = value item = XMLItem(self.get_id(), dir) if value == RUN_FROM_BUILD_DIR: item.set_attr('type', 'build-dir') elif value == RUN_FROM_EXE_DIR: item.set_attr('type', 'exe-dir') else: item.set_attr('type', 'dir') return [item]
def delete_config_cb(self, *whatever): combo = self.xml.w_configuration iter = combo.get_active_iter() store = combo.get_model() config = store.get_value(iter, 1) do_delete = mprj.utils.question_dialog( parent=self, text=_("Delete configuration %s?" % (config.name, )), default_ok=False) if do_delete: self.config.delete_conf(config.name) store.remove(iter) combo.set_active(0) self.update_buttons()
def get_output_pane(self, window): pane = window.get_pane(_OUTPUT_PANE_ID) if not pane: label = moo.PaneLabel(icon_name=_STOCK_EXECUTE, label_text=_("Output")) output = moo.CmdView() window.add_stop_client(output) output.set_property("highlight-current-line", False) output.set_wrap_mode(gtk.WRAP_CHAR) pane = gtk.ScrolledWindow() pane.set_shadow_type(gtk.SHADOW_ETCHED_IN) pane.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) pane.add(output) pane.show_all() pane.output = output window.add_pane(_OUTPUT_PANE_ID, pane, label, moo.PANE_POS_BOTTOM) return pane
def __init__(self, id, name=None, description=None, visible=None, cell_types=None): object.__init__(self) self.__id = id attrs = getattr(type(self), '__item_attributes__') if not cell_types and attrs.has_key('cell_types'): cell_types = attrs['cell_types'] if not isinstance(cell_types, list) and \ not isinstance(cell_types, tuple): cell_types = [cell_types] if not cell_types: cell_types = [] if name is None: if attrs.has_key('name'): name = attrs['name'] else: name = _(id) if description is None: if attrs.has_key('description'): description = attrs['description'] else: description = name if visible is None: if attrs.has_key('visible'): visible = attrs['visible'] else: visible = True self.__config_cells = [] self.__name = name self.__description = description self.__visible = visible self.__cell_types = cell_types
def __ensure_output(self): pane = self.__get_output() if pane is None: label = self.pane_label or moo.PaneLabel( icon_name=moo.STOCK_EXECUTE, label_text=_("Python Output")) output = moo.CmdView() output.set_property("highlight-current-line", True) output.set_filter_by_id("python") pane = gtk.ScrolledWindow() pane.set_shadow_type(gtk.SHADOW_ETCHED_IN) pane.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) pane.add(output) pane.show_all() pane.output = output self.window.add_pane(self.pane_id, pane, label, moo.PANE_POS_BOTTOM) self.window.add_stop_client(output) return pane
def do_button_press_event(self, event): if event.button != 3: return gtk.TreeView.do_button_press_event(self, event) pos = self.get_path_at_pos(int(event.x), int(event.y)) if pos is None: return gtk.TreeView.do_button_press_event(self, event) model = self.get_model() if model is None: return gtk.TreeView.do_button_press_event(self, event) iter = model.get_iter(pos[0]) data = model.get_value(iter, 0) if data[0] is None: return gtk.TreeView.do_button_press_event(self, event) self.get_selection().select_iter(iter) menu = gtk.Menu() item = gtk.MenuItem(_("Delete"), False) item.show() item.connect('activate', self.delete_activated, pos[0]) menu.add(item) menu.popup(None, None, None, event.button, event.time)
def init_ui(self): SimpleProject.init_ui(self) self.panes.extend([_BUILD_PANE_ID, _OUTPUT_PANE_ID]) commands = [ ["Build", _("Build Project"), _STOCK_BUILD, "F8", _CMD_BUILD], ["Compile", _("Compile File"), _STOCK_COMPILE, "F9", _CMD_COMPILE], ["RunConfigure", _("Run Configure"), None, None, _CMD_CONFIGURE], ["RunAutogen", _("Run autogen.sh"), None, None, _CMD_AUTOGEN], ["Clean", _("Clean Project"), None, None, _CMD_CLEAN], ["Distclean", _("Distclean"), None, None, _CMD_DISTCLEAN], [ "Execute", _("Execute Program"), _STOCK_EXECUTE, "<shift>F9", _CMD_EXECUTE ], ["Install", _("Install"), None, "<shift><ctrl>I", _CMD_INSTALL], ] for c in commands: self.add_action("CProject" + c[0], display_name=c[1], label=c[1], stock_id=c[2], default_accel=c[3], callback=CProject.DoCmd(self, c[4])) self.add_action("CProjectBuildConfiguration", factory=_BuildConfigurationActionFactory(self)) editor = moo.Editor.instance() xml = editor.get_ui_xml() xml.insert_markup_after( self.merge_id, "Editor/Menubar", "Project", """ <item name="Build" _label="%s"> <item action="CProjectBuild"/> <item action="CProjectCompile"/> <item action="CProjectRunConfigure"/> <item action="CProjectRunAutogen"/> <separator/> <item action="CProjectInstall"/> <separator/> <item action="CProjectClean"/> <item action="CProjectDistclean"/> <separator/> <item action="CProjectExecute"/> </item> """ % (N_("_Build"), )) xml.insert_markup( self.merge_id, "Editor/Toolbar/BuildToolbar", 0, """ <item action="CProjectBuild"/> <item action="CProjectExecute"/> <separator/> """) xml.insert_markup_before( self.merge_id, "Editor/Menubar/Project", "ProjectOptions", """ <separator/> <item action="CProjectBuildConfiguration"/> """)
class ConfigureOptions(Group): __items__ = { 'args' : String(name=_('Configure arguments')), 'vars' : Dict(str, name=_('Environment variables'), xml_elm_name='var'), } __item_name__ = _('Configure options')
def bad_project(self, parent, filename, error): moo.error_dialog(parent, _("Could not open project '%s'") % (filename, ), str(error))