def OnData(self, x, y, default_drag_result): """ Called when OnDrop returns True. """ # First, if we have a source in the clipboard and the source # doesn't allow moves then change the default to copy if clipboard.drop_source is not None and \ not clipboard.drop_source.allow_move: default_drag_result = wx.DragCopy elif clipboard.drop_source is None: # This means we might be receiving a file; try to import # the right packages to nicely handle a file drop. If those # packages can't be imported, then just pass through. if self.GetData(): try: from apptools.io import File from apptools.naming.api import Binding names = self.file_data.GetFilenames() files = [] bindings = [] for name in names: f = File(name) files.append(f) bindings.append(Binding(name = name, obj = f)) clipboard.data = files clipboard.node = bindings except ImportError: pass # Pass the object on the clipboard it to the handler. # # fixme: We allow 'wx_dropped_on' and 'on_drop' because both Dave # and Martin want different things! Unify! if hasattr(self.handler, 'wx_dropped_on'): drag_result = self.handler.wx_dropped_on( x, y, clipboard.data, default_drag_result ) elif hasattr(self.handler, 'on_drop'): drag_result = self.handler.on_drop( x, y, clipboard.data, default_drag_result ) else: self.handler(x, y, clipboard.data) drag_result = default_drag_result # Let the source of the drag/drop know that the operation is complete. drop_source = clipboard.drop_source if drop_source is not None: drop_source.on_dropped(drag_result) # Clean out the drop source! clipboard.drop_source = None # The return value tells the source what to do with the original data # (move, copy, etc.). In this case we just return the suggested value # given to us. return default_drag_result
def _list_bindings(self): """ Lists the bindings in this context. """ bindings = [] for key in self.adaptee: bindings.append( Binding(name=str(key), obj=self._lookup(key), context=self)) return bindings
def explore(obj): """ View a Python object as a naming context. """ root = Binding(name='root', obj=PyContext(namespace=obj)) explorer = Explorer(root=root, size=(1200, 400)) explorer.open() return
def _list_bindings(self): """ Lists the bindings in this context. """ bindings = [] for obj in self.collection: # Bindings have to have a string name. name = self._get_name(obj) # Create the binding. bindings.append(Binding(name=name, obj=obj, context=self)) return bindings
def _list_bindings(self): """ Lists the bindings in this context. """ bindings = [] for name in self._list_names(): try: obj = self._lookup(name) bindings.append(Binding(name=name, obj=obj, context=self)) # We get attribute errors when we try to look up Event traits (they # are write-only). except AttributeError: pass return bindings
def _lookup_binding(self, name): """ Looks up the binding for a name in this context. """ return Binding(name=name, obj=self._lookup(name), context=self)
# Python lists. type_manager.register_type_adapters( ContextAdapterFactory( adaptee_class=list, adapter_class=ListContextAdapter, ), list) # Python objects. type_manager.register_type_adapters(InstanceContextAdapterFactory(), object) # Get the path to the data directory data_path = os.path.join('examples', 'naming', 'data') full_path = find_resource('AppTools', data_path, alt_path='data', return_path=True) # Create the root context. root = PyFSContext(path=full_path) root.environment[Context.TYPE_MANAGER] = type_manager # Create and open the main window. window = Explorer(root=Binding(name='Root', obj=root)) window.open() # Start the GUI event loop. gui.start_event_loop() ##### EOF #####################################################################