Пример #1
0
class MyPanel1(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.wred = ColWin(self, wx.ID_ANY, wx.RED)
        self.wblue = ColWin(self, wx.ID_ANY, wx.BLUE)

        b1 = wx.Button(self, wx.ID_ANY, 'Show / Hide wred', wx.DefaultPosition,
                       wx.DefaultSize)
        b2 = wx.Button(self, wx.ID_ANY, 'Show / Hide wblue',
                       wx.DefaultPosition, wx.DefaultSize)

        b1.Bind(wx.EVT_BUTTON, self.OnClick1)
        b2.Bind(wx.EVT_BUTTON, self.OnClick2)

        hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
        b = 8
        hsizer1.Add(b1, 0, wx.RIGHT, b)
        hsizer1.Add(b2, 0, border=b)

        b = 4
        hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer2.Add(self.wred, 1, wx.EXPAND | wx.RIGHT, b)
        hsizer2.Add(self.wblue, 1, wx.EXPAND | wx.LEFT, b)

        b = 4
        vsizer1 = wx.BoxSizer(wx.VERTICAL)
        vsizer1.Add(hsizer1, 0, wx.ALL, b)
        vsizer1.Add(hsizer2, 1, wx.ALL | wx.EXPAND, b)

        self.SetSizer(vsizer1)

    def OnClick1(self, event):
        if self.wred.IsShown():
            self.wred.Show(False)
            self.Layout()
        elif not self.wred.IsShown():
            self.wred.Show(True)
            self.Layout()
        else:
            pass

    def OnClick2(self, event):
        if self.wblue.IsShown():
            self.wblue.Show(False)
            self.Layout()
        elif not self.wblue.IsShown():
            self.wblue.Show(True)
            self.Layout()
        else:
            pass
class MyPanel1(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.parent = parent

        self.wred = ColWin(self, wx.ID_ANY, wx.RED)
        self.wgreen = ColWin(self, wx.ID_ANY, wx.GREEN)

        b1 = wx.Button(self, wx.ID_ANY, 'detach / insert wred',
                       wx.DefaultPosition, wx.DefaultSize)
        b2 = wx.Button(self, wx.ID_ANY, 'detach / insert wgreen',
                       wx.DefaultPosition, wx.DefaultSize)
        b3 = wx.Button(self, wx.ID_ANY, 'swap wrec / wgreen',
                       wx.DefaultPosition, wx.DefaultSize)
        b4 = wx.Button(self, wx.ID_ANY, '4', wx.DefaultPosition,
                       wx.DefaultSize)

        b1.Bind(wx.EVT_BUTTON, self.OnClick1)
        b2.Bind(wx.EVT_BUTTON, self.OnClick2)
        b3.Bind(wx.EVT_BUTTON, self.OnClick3)
        b4.Bind(wx.EVT_BUTTON, self.OnClick4)

        #toolbar
        hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
        b = 8
        hsizer1.Add(b1, 0, wx.RIGHT, b)
        hsizer1.Add(b2, 0, wx.RIGHT, b)
        hsizer1.Add(b3, 0, wx.RIGHT, b)
        hsizer1.Add(b4, 0, border=b)

        #A horizontal sizer holding the green and red windows. Both windows
        #are visible at start.
        #note the same flag border for both windows (swapping)
        self.bb = 5
        self.hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        self.hsizer2.Add(self.wred, 1, wx.EXPAND | wx.ALL, self.bb)
        self.hsizer2.Add(self.wgreen, 1, wx.EXPAND | wx.ALL, self.bb)

        b = 5
        self.vsizer1 = wx.BoxSizer(wx.VERTICAL)
        self.vsizer1.Add(hsizer1, 0, wx.ALL, b)
        self.vsizer1.Add(self.hsizer2, 1, wx.ALL | wx.EXPAND, b)

        self.SetSizer(self.vsizer1)

        self.parent.SetClientSize((500, 300))
        self.parent.CentreOnScreen()

        #the two windows are shown
        assert self.wred.IsShown() == True
        assert self.wgreen.IsShown() == True

    # note: wred or wgreen win is always insert at "position 0" even if swapped.

    #wred
    def OnClick1(self, event):
        if self.wred.IsShown():
            #~ print 'wred is shown'
            self.hsizer2.Detach(self.wred)
            self.wred.Show(False)
            self.Layout()
        elif not self.wred.IsShown():
            #~ print 'wred is not shown'
            self.wred.Show(True)
            #same flag as in __init__
            self.hsizer2.Insert(0, self.wred, 1, wx.EXPAND | wx.ALL, self.bb)
            self.Layout()
        else:
            pass

    #wgreen
    def OnClick2(self, event):
        if self.wgreen.IsShown():
            #~ print 'wgreen is shown'
            self.hsizer2.Detach(self.wgreen)
            self.wgreen.Show(False)
            self.Layout()
        elif not self.wgreen.IsShown():
            #~ print 'wgreen is not shown'
            self.wgreen.Show(True)
            #same flag as in __init__
            self.hsizer2.Insert(0, self.wgreen, 1, wx.EXPAND | wx.ALL, self.bb)
            self.Layout()
        else:
            pass

    #swap
    def OnClick3(self, event):
        if not self.wred.IsShown() or not self.wgreen.IsShown():
            #~ print 'wred *or* wgreen is/are not shown'
            return

        item0 = self.hsizer2.GetItem(0).GetWindow()
        item1 = self.hsizer2.GetItem(1).GetWindow()

        self.hsizer2.Detach(item0)
        self.hsizer2.Detach(item1)
        item0.Show(False)
        item1.Show(False)

        item1.Show(True)
        self.hsizer2.Insert(0, item1, 1, wx.EXPAND | wx.ALL, self.bb)
        self.Layout()

        item0.Show(True)
        self.hsizer2.Insert(1, item0, 1, wx.EXPAND | wx.ALL, self.bb)
        self.Layout()

    def OnClick4(self, event):
        pass
Пример #3
0
class MyPanel2(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.wred = ColWin(self, wx.ID_ANY, wx.RED)
        self.wwhite = ColWin(self, wx.ID_ANY, wx.WHITE)
        self.wgreen = ColWin(self, wx.ID_ANY, wx.GREEN)

        b1 = wx.Button(self, wx.ID_ANY, 'Show / Hide wred', wx.DefaultPosition,
                       wx.DefaultSize)
        b2 = wx.Button(self, wx.ID_ANY, 'Show / Hide wwhite',
                       wx.DefaultPosition, wx.DefaultSize)
        b3 = wx.Button(self, wx.ID_ANY, 'Show / Hide wgreen',
                       wx.DefaultPosition, wx.DefaultSize)

        b1.Bind(wx.EVT_BUTTON, self.OnClick1)
        b2.Bind(wx.EVT_BUTTON, self.OnClick2)
        b3.Bind(wx.EVT_BUTTON, self.OnClick3)

        vsizer1 = wx.BoxSizer(wx.VERTICAL)
        b = 8
        vsizer1.Add(b1, 0, wx.BOTTOM, b)
        vsizer1.Add(b2, 0, wx.BOTTOM, b)
        vsizer1.Add(b3, 0, border=b)

        b = 4
        hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        hsizer2.Add(self.wred, 1, wx.EXPAND | wx.ALL, b)
        hsizer2.Add(self.wwhite, 2, wx.EXPAND | wx.ALL, b)
        hsizer2.Add(self.wgreen, 3, wx.EXPAND | wx.ALL, b)
        hsizer2.Add(vsizer1, 0, wx.ALL, b)

        self.SetSizer(hsizer2)

    def OnClick1(self, event):
        if self.wred.IsShown():
            self.wred.Show(False)
            self.Layout()
            self.Refresh()  #does not work properly without this !?
        elif not self.wred.IsShown():
            self.wred.Show(True)
            self.Layout()
            self.Refresh()
        else:
            pass

    def OnClick2(self, event):
        if self.wwhite.IsShown():
            self.wwhite.Show(False)
            self.Layout()
            self.Refresh()
        elif not self.wwhite.IsShown():
            self.wwhite.Show(True)
            self.Layout()
            self.Refresh()
        else:
            pass

    def OnClick3(self, event):
        if self.wgreen.IsShown():
            self.wgreen.Show(False)
            self.Layout()
            self.Refresh()
        elif not self.wgreen.IsShown():
            self.wgreen.Show(True)
            self.Layout()
            self.Refresh()
        else:
            pass