def __init__(self, filename=None): if isinstance(filename, unicode): filename = filename.encode(sys.getfilesystemencoding()) self.filename = filename if self.filename is None: # We initially create an in-memory database. # When we save to a file, we will reopen the database from the file. self.db = metakit.storage() # self.filename = 'defau.gt' # self.db = metakit.storage(self.filename, 1) # for desc in storage_desc.values(): # self.db.getas(desc) # self.db.commit() else: self.db = metakit.storage(self.filename, 1) self.cleanup() # self.aside = metakit.storage('grafity-storage.mka', 1) # self.db.aside(self.aside) # print >>sys.stderr, "project created" self._modified = False action_list.connect('added', self.on_action_added) self.items = {} self.deleted = {} self._dict = {} self.save_dict = {} # Create top folder. # - it must be created before all other items # - it must be created with _isroot=True, to set itself as its parent folder try: fv = self.db.getas(storage_desc[Folder]) row = fv.select(name='top')[0] self.top = self.items[row.id] = Folder(self, location=(fv, row, row.id), _isroot=True) except IndexError: # can't find it in the database, create a new one. self.top = Folder(self, 'top', _isroot=True) self.here = self.top self.this = None # create objects for cls, desc in [(i, storage_desc[i]) for i in (Folder, grafity.worksheet.Worksheet, grafity.graph.Graph)]: view = self.db.getas(desc) for i, row in enumerate(view): if row.id != self.top.id: if not row.id.startswith('-'): # print 'loading', cls, row.id, self.items[row.id] = cls(self, location=(view, row, row.id)) # print 'end' else: self.deleted[row.id] = cls(self, location=(view, row, row.id))
def __init__(self, parent): QListView.__init__(self, parent) self.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding) self.setMinimumSize(QSize(150,0)) self.header().hide() self.addColumn ('Object', 145) self.setSelectionMode(QListView.Extended) self.setSorting(-1) QObject.connect(self, SIGNAL("doubleClicked(QListViewItem *, const QPoint &, int)"), self.on_doubleclick) # QObject.connect(self, SIGNAL("contextMenuRequested (QListViewItem *, const QPoint &, int)"), # self.on_context_menu_requested) action_list.connect('added', self.on_added) action_list.connect('removed', self.on_removed) action_list.connect('done', self.on_done) action_list.connect('undone', self.on_undone)
def __init__(self): # print >>sys.stderr, "creating main window" Window.__init__(self, statusbar=True, size=(800, 600)) self.title = 'Grafit' # for example self.main = MainPanel(self) self.shell = ScriptWindow(self.main.bottom_panel, page_label='console', page_pixmap='console.png') self.shell.locals['mainwin'] = self try: self.shell._widget.history = settings.get('script', 'history').split('\n') except: self.shell._widget.history = [] pass self.explorer = ProjectExplorer(self.main.left_panel, page_label='project', page_pixmap='stock_navigator.png') self.actionlist = ActionList(action_list, self.main.left_panel, page_label='actions', page_pixmap='stock_undo.png') self.explorer.connect('item-activated', self.on_item_activated) self.project = Project() self.open_project(self.project) self.book = Notebook(self.main) # self.book.connect('page-changed', self.on_page_changed) self.main.left_panel.open(self.explorer) global_connect('status-message', self.on_status_message) action_list.connect('added', self.on_action) action_list.connect('removed', self.on_action) action_list.connect('modified', self.on_action) self.actions = actions = { 'file-new': Command('New', 'Create a new project', self.on_project_new, 'new.png', 'Ctrl+N'), 'file-open': Command('Open...', 'Open a project', self.on_project_open, 'open.png', 'Ctrl+O'), 'file-save': Command('Save', 'Save the project', self.on_project_save, 'save.png', 'Ctrl+S'), 'file-saveas': Command('Save As...', 'Save the project with a new name', self.on_project_saveas, 'saveas.png'), 'file-quit': Command('Quit', 'Quit grafity', self.on_quit, 'stock_exit.png', 'Ctrl+Q'), 'edit-undo': Command('Undo', 'Undo the last action', undo, 'stock_undo.png', 'Ctrl+Z'), 'edit-redo': Command('Redo', 'Redo the last action', redo, 'stock_redo.png', 'Shift+Ctrl+Z'), 'edit-copy': Command('Copy', 'Undo the last action', object, 'stock_copy.png', 'Ctrl+C'), 'edit-cut': Command('Cut', 'Undo the last action', object, 'stock_cut.png', 'Ctrl+X'), 'edit-paste': Command('Paste', 'Undo the last action', 'stock_paste.png', None, 'Ctrl+V'), 'edit-delete': Command('Delete', 'Undo the last action', 'stock_delete.png', None), 'import-ascii': Command('Import ASCII...', 'Import and ASCII file', self.on_import_ascii, 'import_ascii.png', 'Ctrl+I'), 'object-new-worksheet': Command('New Worksheet', 'Create a new worksheet', self.on_new_worksheet, 'new-worksheet.png'), 'object-new-graph': Command('New Graph', 'Create a new worksheet', self.on_new_graph, 'new-graph.png'), 'object-new-folder': Command('New Folder', 'Create a new worksheet', self.on_new_folder, 'new-folder.png'), 'functions': Command('Functions...', '', object), 'filters': Command('Filters...', '', object), 'scripts': Command('Scripts...', '', object), 'run-script': Command('Run script...', '', self.on_run_script), 'integrate': Command('Integrate', '', self.on_integrate), 'close-active-page': Command('Close', 'Close this worksheet', lambda: self.book.active_page.on_close(), 'close.png', 'Ctrl+W'), None: None } self.menubar = Menubar(self) for title, items in [ ('&File', ['file-new', 'file-open', None, 'file-save', 'file-saveas', None, 'file-quit']), ('&Edit', ['edit-undo', 'edit-redo', None, 'edit-cut', 'edit-copy', 'edit-paste', None, 'edit-delete']), ('&Tools', ['functions', 'filters', 'scripts', None, 'run-script']), ('&Analysis', ['integrate']), ('&Help', []), ]: menu = Menu(self.menubar, title) for item in items: menu.append(actions[item]) self.toolbar = Toolbar(self) for item in [ 'file-new', 'file-open', 'file-save', 'file-saveas', None, 'object-new-folder', 'object-new-worksheet', 'object-new-graph', None, 'edit-undo', 'edit-redo', None, 'import-ascii', None, 'close-active-page', ]: self.toolbar.append(actions[item]) self.toolbar._widget.Realize() self.connect('close', self.on_quit) self.main.bottom_panel._widget.toolbar.Realize() self.main.left_panel._widget.toolbar.Realize() self.main.right_panel._widget.toolbar.Realize() # preload wx.xrc.XmlResource(os.path.join(DATADIR, 'data', 'resources.xrc')) self.on_action() self.on_project_modified(False) if len(self.args) > 0: name = self.args[0] if ':' in name: prj, obj = name.split(':') self.open_project(Project(prj)) self.on_item_activated(self.project.top[obj]) else: self.open_project(Project(name))