⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foldpanelbar.py

📁 Wxpython Implemented on Windows CE, Source code
💻 PY
📖 第 1 页 / 共 5 页
字号:
                                         FPB_ALIGN_WIDTH, FPB_DEFAULT_SPACING, 20)

        """
        
        try:
            item = self._panels.index(panel)
        except:
            raise "ERROR: Invalid Panel Passed To AddFoldPanelWindow: " + repr(panel)
        
        panel.AddWindow(window, flags, Spacing, leftSpacing, rightSpacing)

        # TODO: Take old and new height, and if difference, reposition all the lower
        # panels this is because the user can add new wxWindow controls somewhere in
        # between when other panels are already present.
    
        return 0


    def AddFoldPanelSeparator(self, panel, colour=wx.BLACK,
                              Spacing=FPB_DEFAULT_SPACING,
                              leftSpacing=FPB_DEFAULT_LEFTLINESPACING,
                              rightSpacing=FPB_DEFAULT_RIGHTLINESPACING):
        """
        Adds a separator line to the current FoldPanel.
        
        The seperator is a simple line which is drawn and is no real
        component.  It can be used to separate groups of controls
        which belong to each other.  The colour is adjustable, and it
        takes the same Spacing, leftSpacing and rightSpacing as
        `AddFoldPanelWindow`.
        """
        
        try:
            item = self._panels.index(panel)
        except:
            raise "ERROR: Invalid Panel Passed To AddFoldPanelSeparator: " + repr(panel)
        
        panel.AddSeparator(colour, Spacing, leftSpacing, rightSpacing)
        return 0


    def OnSizePanel(self, event):
        """ Handles the EVT_SIZE event for the FoldPanelBar. """

        # skip all stuff when we are not initialised yet

        if not self._controlCreated:
            event.Skip()
            return

        foldrect = self.GetRect()

        # fold panel itself. If too little space,
        # don't show it

        foldrect.SetX(0)
        foldrect.SetY(0)

        self._foldPanel.SetSize(foldrect[2:])
        
        if self._extraStyle & FPB_COLLAPSE_TO_BOTTOM or self._extraStyle & FPB_EXCLUSIVE_FOLD:
            rect = self.RepositionCollapsedToBottom()
            vertical = self.IsVertical()
            if vertical and rect.GetHeight() > 0 or not vertical and rect.GetWidth() > 0:
                self.RefreshRect(rect)

        # TODO: A smart way to check wether the old - new width of the
        # panel changed, if so no need to resize the fold panel items

        self.RedisplayFoldPanelItems()
    

    def OnPressCaption(self, event):
        """ Handles the EVT_CAPTIONBAR event in the FoldPanelBar. """

        # act upon the folding or expanding status of the bar
        # to expand or collapse the panel(s)

        if event.GetFoldStatus():
            self.Collapse(event.GetTag())
        else:
            self.Expand(event.GetTag())

        event.Skip()
        

    def RefreshPanelsFrom(self, item):
        """ Refreshes all the panels from given index down to last one. """
        
        try:
            i = self._panels.index(item)
        except:
            raise "ERROR: Invalid Panel Passed To RefreshPanelsFrom: " + repr(item)
        
        self.Freeze()

        # if collapse to bottom is on, the panels that are not expanded
        # should be drawn at the bottom. All panels that are expanded
        # are drawn on top. The last expanded panel gets all the extra space

        if self._extraStyle & FPB_COLLAPSE_TO_BOTTOM or self._extraStyle & FPB_EXCLUSIVE_FOLD:
        
            offset = 0

            for panels in self._panels:
            
                if panels.IsExpanded():
                    offset = offset + panels.Reposition(offset)
        
            # put all non collapsed panels at the bottom where there is space, 
            # else put them right behind the expanded ones

            self.RepositionCollapsedToBottom()
        
        else:
        
            pos = self._panels[i].GetItemPos() + self._panels[i].GetPanelLength()
            for j in range(i+1, len(self._panels)):
                pos = pos + self._panels[j].Reposition(pos)
        
        self.Thaw()
        

    def RedisplayFoldPanelItems(self):
        """ Resizes the fold panels so they match the width. """
        # resize them all. No need to reposition
        for panels in self._panels:
            panels.ResizePanel()
            panels.Refresh()


    def RepositionCollapsedToBottom(self):
        """
        Repositions all the collapsed panels to the bottom.

        When it is not possible to align them to the bottom, stick
        them behind the visible panels. The Rect holds the slack area
        left between last repositioned panel and the bottom
        panels. This needs to get a refresh.
        """

        value = wx.Rect(0,0,0,0)
        vertical = self.IsVertical()

        # determine wether the number of panels left
        # times the size of their captions is enough
        # to be placed in the left over space

        expanded = 0
        collapsed = 0
        collapsed, expanded, values = self.GetPanelsLength(collapsed, expanded)

        # if no room stick them behind the normal ones, else
        # at the bottom

        if (vertical and [self.GetSize().GetHeight()] or \
            [self.GetSize().GetWidth()])[0] - expanded - collapsed < 0:
            offset = expanded
        else:

            # value is the region which is left unpainted
            # I will send it back as 'slack' so it does not need to
            # be recalculated.

            value.SetHeight(self.GetSize().GetHeight())
            value.SetWidth(self.GetSize().GetWidth())

            if vertical:
                value.SetY(expanded)
                value.SetHeight(value.GetHeight() - expanded)
            else:
                value.SetX(expanded)
                value.SetWidth(value.GetWidth() - expanded)

            offset = (vertical and [self.GetSize().GetHeight()] or \
                      [self.GetSize().GetWidth()])[0] - collapsed


        # go reposition

        for panels in self._panels:
            if not panels.IsExpanded():
                offset = offset + panels.Reposition(offset)

        return value


    def GetPanelsLength(self, collapsed, expanded):
        """
        Returns the length of the panels that are expanded and
        collapsed.

        This is useful to determine quickly what size is used to
        display, and what is left at the bottom (right) to align the
        collapsed panels.
        """
        
        value = 0

        # assumed here that all the panels that are expanded
        # are positioned after each other from 0,0 to end.

        for j in range(0, len(self._panels)):
            offset = self._panels[j].GetPanelLength()
            value = value + offset
            if self._panels[j].IsExpanded():
                expanded = expanded + offset
            else:
                collapsed = collapsed + offset

        return collapsed, expanded, value


    def Collapse(self, foldpanel):
        """
        Collapses the given FoldPanel reference, and updates the
        foldpanel bar.

        In the FPB_COLLAPSE_TO_BOTTOM style, all collapsed captions
        are put at the bottom of the control. In the normal mode, they
        stay where they are.
        """
        
        try:
            item = self._panels.index(foldpanel)
        except:
            raise "ERROR: Invalid Panel Passed To Collapse: " + repr(foldpanel)
        
        foldpanel.Collapse()
        self.RefreshPanelsFrom(foldpanel)


    def Expand(self, foldpanel):
        """
        Expands the given FoldPanel reference, and updates the
        foldpanel bar.
        
        In the FPB_COLLAPSE_TO_BOTTOM style, they will be removed from
        the bottom and the order where the panel originally was placed
        is restored.
        """

        fpbextrastyle = 0
        
        if self._extraStyle & FPB_SINGLE_FOLD or self._extraStyle & FPB_EXCLUSIVE_FOLD:
            fpbextrastyle = 1
            for panel in self._panels:
                panel.Collapse()

        foldpanel.Expand()
        
        if fpbextrastyle:
            if self._extraStyle & FPB_EXCLUSIVE_FOLD:
                self.RepositionCollapsedToBottom()
            self.RefreshPanelsFrom(self._panels[0])
        else:
            self.RefreshPanelsFrom(foldpanel)


    def ApplyCaptionStyle(self, foldpanel, cbstyle):
        """
        Sets the style of the caption bar (`CaptionBar`) of the
        FoldPanel.

        The changes are applied immediately. All styles not set in the
        CaptionBarStyle class are not applied. Use the CaptionBar
        reference to indicate what captionbar you want to apply the
        style to. To apply one style to all CaptionBar items, use
        `ApplyCaptionStyleAll`
        """        
        foldpanel.ApplyCaptionStyle(cbstyle)
        

    def ApplyCaptionStyleAll(self, cbstyle):
        """
        Sets the style of all the caption bars of the FoldPanel.

        The changes are applied immediately.
        """ 
        for panels in self._panels:
            self.ApplyCaptionStyle(panels, cbstyle)
            

    def GetCaptionStyle(self, foldpanel):
        """
        Returns the currently used caption style for the FoldPanel.

        It is returned as a CaptionBarStyle class. After modifying it,
        it can be set again.
        """        
        return foldpanel.GetCaptionStyle()


    def IsVertical(self):
        """
        Returns whether the CaptionBar has default orientation or not.

        Default is vertical.
        """        
        return self._isVertical


    def GetFoldPanel(self, item):
        """
        Returns the panel associated with the index "item".

        See the example at the bottom of the module, especially the events
        for the "Collapse Me" and "Expand Me" buttons.
        """
        try:
            ind = self._panels[item]
            return self._panels[item]
        except:
            raise "ERROR: List Index Out Of Range Or Bad Item Passed: " + repr(item) + \
                  ". Item Should Be An Integer Between " + repr(0) + " And " + \
                  repr(len(self._panels))


    def GetCount(self):
        """ Returns the number of panels in the FoldPanelBar. """

        try:
            return len(self._panels)
        except:
            raise "ERROR: No Panels Have Been Added To FoldPanelBar"

        

# --------------------------------------------------------------------------------- #
# class FoldPanelItem
# --------------------------------------------------------------------------------- #

class FoldPanelItem(wx.Panel):
    """
    This class is a child sibling of the `FoldPanelBar` class. It will
    contain a `CaptionBar` class for receiving of events, and a the
    rest of the area can be populated by a `wx.Panel` derived class.
    """
    # Define Empty CaptionBar Style
    EmptyCaptionBarStyle = CaptionBarStyle()
    
    def __init__(self, parent, id=wx.ID_ANY, caption="", foldIcons=None,
                 collapsed=False, cbstyle=EmptyCaptionBarStyle):
        """ Default Class Constructor. """
        
        wx.Panel.__init__(self, parent, id, wx.Point(0,0), style=wx.CLIP_CHILDREN)
        self._controlCreated = False
        self._UserSize = 0
        self._PanelSize = 0
        self._LastInsertPos = 0
        self._itemPos = 0
        self._userSized = False

        if foldIcons is None:
            foldIcons = wx.ImageList(16, 16)

            bmp = GetExpandedIconBitmap()
            foldIcons.Add(bmp)
            bmp = GetCollapsedIconBitmap()
            foldIcons.Add(bmp)
        
        self._foldIcons = foldIcons

        # create the caption bar, in collapsed or expanded state
         
        self._captionBar = CaptionBar(self, wx.ID_ANY, wx.Point(0,0),
                                      size=wx.DefaultSize, caption=caption,
                                      foldIcons=foldIcons, cbstyle=cbstyle)

        if collapsed:
            self._captionBar.Collapse()

        self._controlCreated = True

        # make initial size for component, if collapsed, the
        # size is determined on the panel height and won't change
    
        size = self._captionBar.GetSize()

        self._PanelSize = (self.IsVertical() and [size.GetHeight()] or \
                           [size.GetWidth()])[0]
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -