Ejemplo n.º 1
0
 def __init__(self,
              parent,
              id=-1,
              pos=wx.DefaultPosition,
              size=wx.DefaultSize,
              style=wx.TR_DEFAULT_STYLE,
              rootObject=None,
              rootLabel=None,
              rootIsNamespace=False,
              static=False):
     """Create FillingTree instance."""
     wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
     self.rootIsNamespace = rootIsNamespace
     import __main__
     if rootObject is None:
         rootObject = __main__.__dict__
         self.rootIsNamespace = True
     if rootObject is __main__.__dict__ and rootLabel is None:
         rootLabel = 'locals()'
     if not rootLabel:
         rootLabel = 'Ingredients'
     rootData = wx.TreeItemData(rootObject)
     self.item = self.root = self.AddRoot(rootLabel, -1, -1, rootData)
     self.SetItemHasChildren(self.root, self.objHasChildren(rootObject))
     wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
     wx.EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
     wx.EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
     wx.EVT_TREE_ITEM_ACTIVATED(self, self.GetId(), self.OnItemActivated)
     if not static:
         dispatcher.connect(receiver=self.push, signal='Interpreter.push')
Ejemplo n.º 2
0
    def __init__(self, parent, id=-1, path=None, style=wx.SUNKEN_BORDER):
        wx.TreeCtrl.__init__(self,
                             parent,
                             id,
                             style=style | wx.TR_DEFAULT_STYLE)
        self.path = None
        root = _DirItemInfo(_dc.get_root())
        self.imglist = wx.ImageList(16, 16)
        self.icons = {}  # dizionario delle icone presenti in imglist, con
        # chiave (location, index)
        self._added = {}  # insieme di cartelle gia' processate
        # (cioe' il contenuto delle quali e' gia'
        # stato aggiunto all'albero)
        self.AssignImageList(self.imglist)

        self._add_icons(root)

        r = self.AddRoot(root.display_name, self.icons[root.icon_info])
        self.SetPyData(r, root)
        self.SetItemImage(r, self.icons[root.open_icon_info],
                          wx.TreeItemIcon_Expanded)
        self.SetItemHasChildren(r, root.has_subfolders)
        wx.EVT_TREE_ITEM_EXPANDING(self, -1, self.on_expanding)
        wx.EVT_TREE_ITEM_COLLAPSED(self, -1, self.on_collapsed)
        wx.EVT_TREE_SEL_CHANGING(self, -1, self.on_sel_changing)

        if path is not None:
            self.SetPath(path)
        else:
            self.SelectItem(r)
    def __init__(self, parent, filename):
        # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
        wx.EVT_SIZE(self, self.OnSize)

        tID = wx.NewId()

        self.tree = MyTreeCtrl(
            self,
            tID,
            wx.DefaultPosition,
            wx.DefaultSize,
            wx.TR_HAS_BUTTONS | wx.TR_EDIT_LABELS,  #| wx.TR_MULTIPLE
            #| wx.TR_HIDE_ROOT
        )

        isz = (16, 16)
        il = wx.ImageList(isz[0], isz[1])
        # wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz) -> wx.ArtProvider.GetBitmap()/3
        self.folderIdx = il.Add(
            wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz))
        self.folderOpenIdx = il.Add(
            wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz))
        self.fileIdx = il.Add(
            wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz))
        #self.fileIdx  = self.il.Add(images.getFile1Bitmap())
        #self.smileidx = self.il.Add(images.getSmilesBitmap())

        self.tree.SetImageList(il)
        self.il = il

        # NOTE: 1 tree items have to have a data object in order to be sorted.
        #       2 Since our compare just uses the labels we don't need real data, so we'll just
        # use None below for the item data.

        wx.EVT_TREE_ITEM_EXPANDED(self, tID, self.OnItemExpanded)
        wx.EVT_TREE_ITEM_COLLAPSED(self, tID, self.OnItemCollapsed)
        wx.EVT_TREE_SEL_CHANGED(self, tID, self.OnSelChanged)
        wx.EVT_TREE_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit)
        wx.EVT_TREE_END_LABEL_EDIT(self, tID, self.OnEndEdit)
        wx.EVT_TREE_ITEM_ACTIVATED(self, tID, self.OnActivate)

        wx.EVT_LEFT_DCLICK(self.tree, self.OnLeftDClick)
        wx.EVT_RIGHT_DOWN(self.tree, self.OnRightClick)
        wx.EVT_RIGHT_UP(self.tree, self.OnRightUp)

        #?? wx.EVT_COMMAND(self, 103,103, self.OnFileOpened) # Newer wxWidgets has no EVT_COMMAND
        # load default tree
        if filename != "":
            self.reload_tree(filename)
Ejemplo n.º 4
0
    def __init__(self, parent, image_size=(16, 16), **traits):
        """ Creates a new tree viewer.

        'parent' is the toolkit-specific control that is the tree's parent.

        'image_size' is a tuple in the form (int width, int height) that
        specifies the size of the label images (if any) displayed in the tree.

        """

        # Base class constructor.
        super(TreeViewer, self).__init__(**traits)

        # Create the toolkit-specific control.
        self.control = tree = wx.TreeCtrl(parent, -1, style=self._get_style())

        # Get our actual Id.
        wxid = tree.GetId()

        # Wire up the wx tree events.
        wx.EVT_CHAR(tree, self._on_char)
        wx.EVT_LEFT_DOWN(tree, self._on_left_down)
        wx.EVT_RIGHT_DOWN(tree, self._on_right_down)
        wx.EVT_TREE_ITEM_ACTIVATED(tree, wxid, self._on_tree_item_activated)
        wx.EVT_TREE_ITEM_COLLAPSED(tree, wxid, self._on_tree_item_collapsed)
        wx.EVT_TREE_ITEM_COLLAPSING(tree, wxid, self._on_tree_item_collapsing)
        wx.EVT_TREE_ITEM_EXPANDED(tree, wxid, self._on_tree_item_expanded)
        wx.EVT_TREE_ITEM_EXPANDING(tree, wxid, self._on_tree_item_expanding)
        wx.EVT_TREE_BEGIN_LABEL_EDIT(tree, wxid,
                                     self._on_tree_begin_label_edit)
        wx.EVT_TREE_END_LABEL_EDIT(tree, wxid, self._on_tree_end_label_edit)
        wx.EVT_TREE_BEGIN_DRAG(tree, wxid, self._on_tree_begin_drag)
        wx.EVT_TREE_SEL_CHANGED(tree, wxid, self._on_tree_sel_changed)

        # The image list is a wxPython-ism that caches all images used in the
        # control.
        self._image_list = ImageList(image_size[0], image_size[1])
        if self.show_images:
            tree.AssignImageList(self._image_list)

        # Mapping from element to wx tree item Ids.
        self._element_to_id_map = {}

        # Add the root item.
        if self.input is not None:
            self._add_element(None, self.input)

        return
Ejemplo n.º 5
0
    def __init__(self, parent, image_size=(16, 16), **traits):
        """ Creates a new tree.

        'parent' is the toolkit-specific control that is the tree's parent.

        'image_size' is a tuple in the form (int width, int height) that
        specifies the size of the images (if required) displayed in the tree.

        """

        # Base class constructors.
        super(Tree, self).__init__(**traits)

        # Get our wx Id.
        wxid = wx.NewId()

        # Create the toolkit-specific control.
        self.control = tree = _Tree(self,
                                    parent,
                                    wxid,
                                    style=self._get_style())

        # Wire up the wx tree events.
        wx.EVT_CHAR(tree, self._on_char)
        wx.EVT_LEFT_DOWN(tree, self._on_left_down)
        # fixme: This is not technically correct as context menus etc should
        # appear on a right up (or right click).  Unfortunately,  if we
        # change this to 'EVT_RIGHT_UP' wx does not fire the event unless the
        # right mouse button is double clicked 8^()  Sad,  but true!
        wx.EVT_RIGHT_DOWN(tree, self._on_right_down)
        # fixme: This is not technically correct as we would really like to use
        # 'EVT_TREE_ITEM_ACTIVATED'. Unfortunately, (in 2.6 at least), it
        # throws an exception when the 'Enter' key is pressed as the wx tree
        # item Id in the event seems to be invalid. It also seems to cause
        # any child frames that my be created in response to the event to
        # appear *behind* the parent window, which is, errrr, not great ;^)
        wx.EVT_LEFT_DCLICK(tree, self._on_tree_item_activated)
        #wx.EVT_TREE_ITEM_ACTIVATED(tree, wxid, self._on_tree_item_activated)
        wx.EVT_TREE_ITEM_COLLAPSING(tree, wxid, self._on_tree_item_collapsing)
        wx.EVT_TREE_ITEM_COLLAPSED(tree, wxid, self._on_tree_item_collapsed)
        wx.EVT_TREE_ITEM_EXPANDING(tree, wxid, self._on_tree_item_expanding)
        wx.EVT_TREE_ITEM_EXPANDED(tree, wxid, self._on_tree_item_expanded)
        wx.EVT_TREE_BEGIN_LABEL_EDIT(tree, wxid,
                                     self._on_tree_begin_label_edit)
        wx.EVT_TREE_END_LABEL_EDIT(tree, wxid, self._on_tree_end_label_edit)
        wx.EVT_TREE_BEGIN_DRAG(tree, wxid, self._on_tree_begin_drag)
        wx.EVT_TREE_SEL_CHANGED(tree, wxid, self._on_tree_sel_changed)
        wx.EVT_TREE_DELETE_ITEM(tree, wxid, self._on_tree_delete_item)

        # Enable the tree as a drag and drop target.
        self.control.SetDropTarget(PythonDropTarget(self))

        # The image list is a wxPython-ism that caches all images used in the
        # control.
        self._image_list = ImageList(image_size[0], image_size[1])
        if self.show_images:
            tree.AssignImageList(self._image_list)

        # Mapping from node to wx tree item Ids.
        self._node_to_id_map = {}

        # Add the root node.
        if self.root is not None:
            self._add_root_node(self.root)

        # Listen for changes to the model.
        self._add_model_listeners(self.model)

        return