def __init__(self, parent, **kwds): Box.__init__(self, parent, 'horizontal', **kwds) self.splitter = Splitter(self, 'horizontal') self.tree = Tree(self.splitter) self.tree.enable_drop(['grafit-object']) self.tree.connect('drop-hover', self.on_drop_hover) self.tree.connect('drop-ask', self.on_tree_drop_ask) self.tree.connect('dropped', self.on_tree_dropped) self.tree.connect('selected', self.on_tree_selected) self.list = List(self.splitter, editable=True) self.list.enable_drop(['grafit-object', 'filename']) self.list.connect('drop-hover', self.on_drop_hover) self.list.connect('dropped', self.on_dropped) self.list.connect('drop-ask', self.on_drop_ask) self.list.connect('drag-begin', self.on_begin_drag) self.list.connect('item-activated', self.on_list_item_activated) self.list.connect('right-click', self.on_list_right_click) self.list.connect('end-edit', self.on_item_edited)
class ProjectExplorer(Box): def __init__(self, parent, **kwds): Box.__init__(self, parent, 'horizontal', **kwds) self.splitter = Splitter(self, 'horizontal') self.tree = Tree(self.splitter) self.tree.enable_drop(['grafit-object']) self.tree.connect('drop-hover', self.on_drop_hover) self.tree.connect('drop-ask', self.on_tree_drop_ask) self.tree.connect('dropped', self.on_tree_dropped) self.tree.connect('selected', self.on_tree_selected) self.list = List(self.splitter, editable=True) self.list.enable_drop(['grafit-object', 'filename']) self.list.connect('drop-hover', self.on_drop_hover) self.list.connect('dropped', self.on_dropped) self.list.connect('drop-ask', self.on_drop_ask) self.list.connect('drag-begin', self.on_begin_drag) self.list.connect('item-activated', self.on_list_item_activated) self.list.connect('right-click', self.on_list_right_click) self.list.connect('end-edit', self.on_item_edited) def on_item_edited(self, item, str): item = self.list.model[item] item.name = str return True def on_list_right_click(self, item): if item == -1: return item = self.list.model[item] menu = Menu() menu.append(Command('Delete', 'delete', object, 'stock_delete.png')) menu.append(None) menu.append(Command('Preview PostScript', 'Preview PostScript', lambda: self.on_preview_ps(item), 'stock_print-preview.png')) menu.append(Command('Export...', 'Export', object, 'stock_export.png')) self.list._widget.PopupMenu(menu._menu) def on_tree_drop_ask(self, item): return True def on_preview_ps(self, item): d = tempfile.mkdtemp() f = open(d+'/preview.eps', 'wb') item.export_ascii(f) f.close() subprocess.Popen(['evince', d+'/preview.eps']) def on_tree_dropped(self, item, data): if 'grafit-object' in data.formats: for d in data.get('grafit-object').split('\n'): self.project.items[d].parent = item.folder return True else: return False def on_drop_hover(self, item): # if item != -1: return 'copy' def on_drop_ask(self, item): if item != -1 and isinstance(self.list.model[item], Folder): return True else: return True # return False def on_dropped(self, item, data): if 'grafit-object' in data.formats: parent = self.list.model[item] for d in data.get('grafit-object').split('\n'): self.project.items[d].parent = parent return True elif 'filename' in data.formats and item == -1: # import ascii for path in data.get('filename'): ws = self.project.new(Worksheet, str(os.path.basename(path).split('.')[0]), self.project.here) ws.array, ws._header = import_ascii(path) return False else: return False # else: # print 'DROPPED: ', format, data def on_begin_drag(self, item): return ItemDragData([self.list.model[i] for i in self.list.selection]) def on_tree_selected(self, item): self.list.model = FolderListData(item.folder) self.project.cd(item.folder) def on_list_item_activated(self, item): obj = self.list.model[item] if isinstance(obj, Folder): self.list.model = FolderListData(obj) self.project.cd(obj) else: self.emit('item-activated', obj) def connect_project(self, project): self.project = project root = FolderTreeNode(self.project.top, isroot=True) self.tree.append(root) self.on_tree_selected(root) def disconnect_project(self): self.project = None self.tree.clear()