wx formating with grid sizers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eric dexter
    New Member
    • Sep 2006
    • 46

    wx formating with grid sizers

    What can I do to this code to keep the layout from looking line

    button button button grid

    or worse

    button
    button
    button
    grid

    I need something like

    grid
    button button button

    I was trying to use the splitter example but couldn't get it to work. I am using python 2.5 and the latest wxwindows. Thanks for the help in advance




    Code:
    ):
    
            wx.Frame.__init__(self, parent, -1, "Dex Tracker Score Editor", size=(640,480))
            p = wx.Panel(self, -1, style=0)
            self.grid = WordGrid(p, log)
            b = wx.Button(p, -1, "Save Grid")            #b gets numbered per button and then description set
            b2 = wx.Button(p, 100, "Add Line")
            b3 = wx.Button(p, -1, "Insert Line")
            b4 = wx.Button(p, -1, "Delete Line")
            b5 = wx.Button(p, -1, "Play from line to line")
            
            b.SetDefault()
            self.Bind(wx.EVT_BUTTON, self.OnButton, b)    #bind to the button I am numbering them
            self.Bind(wx.EVT_BUTTON, self.OnButton2, b2)
            self.Bind(wx.EVT_BUTTON, self.OnButton3, b3)
            self.Bind(wx.EVT_BUTTON, self.OnButton4, b4)
            self.Bind(wx.EVT_BUTTON, self.OnButton5, b5)
            b.Bind(wx.EVT_SET_FOCUS, self.OnButtonFocus)  #bind button focus if needed
            #bs = wx.BoxSizer(wx.ALIGN_BOTTOM)
            #bs = wx.StaticBoxSizer(wx.
            bs = wx.BoxSizer(wx.HORIZONTAL)#(wx.VERTICAL)#|wx.ALIGN  _BOTTOM)   #(wx.HORIZONTAL_HATCH)   #(wx.VERTICAL)
            #bs.Add(self.grid, 1, wx.GROW|wx.ALL, 5)
            bs.Add(b)                                     #add the button here numbered in par
            bs.Add(b2)
            bs.Add(b3)
            bs.Add(b4)
            bs.Add(b5)
            #p.placed
            bs = wx.BoxSizer(wx.VERTICAL)
            bs.Add(self.grid, 1, wx.GROW|wx.ALL, 5)
            p.SetSizer(bs)
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    This thread will be renamed to include the word "grid sizers" for future reference.
    Originally posted by eric dexter
    I need something like

    grid
    button button button
    One sizer holds the panel. The panel gets a GridBagSizer which lets you do things like span multiple columns.
    Code:
    Boa:Frame:Frame1
    
    import wx
    import wx.grid
    
    def create(parent):
        return Frame1(parent)
    
    [wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1BUTTON3, wxID_FRAME1GRID1, 
     wxID_FRAME1PANEL1, 
    ] = [wx.NewId() for _init_ctrls in range(6)]
    
    class Frame1(wx.Frame):
        def _init_coll_gridBagSizer1_Items(self, parent):
            # generated method, don't edit
    
            parent.AddWindow(self.button1, (1, 0), border=0, flag=wx.ALIGN_CENTER, span=(1, 1))
            parent.AddWindow(self.button2, (1, 1), border=0, flag=wx.ALIGN_CENTER, span=(1, 1))
            parent.AddWindow(self.button3, (1, 2), border=0, flag=wx.ALIGN_CENTER, span=(1, 1))
            parent.AddWindow(self.grid1, (0, 0), border=0, flag=wx.GROW | wx.EXPAND, span=(1, 3))
    
        def _init_coll_boxSizer1_Items(self, parent):
            # generated method, don't edit
    
            parent.AddWindow(self.panel1, 1, border=0, flag=wx.EXPAND)
    
        def _init_sizers(self):
            # generated method, don't edit
            self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
    
            self.gridBagSizer1 = wx.GridBagSizer(hgap=0, vgap=0)
    
            self._init_coll_boxSizer1_Items(self.boxSizer1)
            self._init_coll_gridBagSizer1_Items(self.gridBagSizer1)
    
            self.SetSizer(self.boxSizer1)
            self.panel1.SetSizer(self.gridBagSizer1)
    
        def _init_ctrls(self, prnt):
            # generated method, don't edit
            wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(485, 430),
                  size=wx.Size(400, 250), style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
            self.SetClientSize(wx.Size(392, 223))
    
            self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, pos=wx.Point(0, 0),
                  size=wx.Size(392, 223), style=wx.TAB_TRAVERSAL)
    
            self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1', name='button1',
                  parent=self.panel1, pos=wx.Point(27, 201), size=wx.Size(75, 23), style=0)
    
            self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label='button2', name='button2',
                  parent=self.panel1, pos=wx.Point(157, 201), size=wx.Size(75, 23), style=0)
    
            self.button3 = wx.Button(id=wxID_FRAME1BUTTON3, label='button3', name='button3',
                  parent=self.panel1, pos=wx.Point(287, 201), size=wx.Size(75, 23), style=0)
    
            self.grid1 = wx.grid.Grid(id=wxID_FRAME1GRID1, name='grid1', parent=self.panel1,
                  pos=wx.Point(0, 0), size=wx.Size(390, 201), style=0)
    
            self._init_sizers()
    
        def __init__(self, parent):
            self._init_ctrls(parent)

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Actually, Eric, I've gotten fed up with trying to get sizers to work right. What I do is used fixed sized windows and absolute (x, y) positioning of the widgets. Of course, using a gui gernerator (like wxGlade, ect (see my post on IDE choices)) makes this much easier.

      Comment

      • eric dexter
        New Member
        • Sep 2006
        • 46

        #4
        Originally posted by bartonc
        Actually, Eric, I've gotten fed up with trying to get sizers to work right. What I do is used fixed sized windows and absolute (x, y) positioning of the widgets. Of course, using a gui gernerator (like wxGlade, ect (see my post on IDE choices)) makes this much easier.
        I saw the gui builder for sale (you know the stick figure with the big nose like mine) but I don't have the cash for such things. I was hopeing for a simple way to changing the generated code over to the format I want. What I would realy like is a way to change direction while the display is being built. I don't care if I use a sizer or another method. Using excel as an alternative method looks intresting but it isn't what I was after.

        ie from bs = wx.BoxSizer(wx. HORIZONTAL) to bs = wx.BoxSizer(wx. VERTICAL) while I am building the display.

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by eric dexter
          I saw the gui builder for sale (you know the stick figure with the big nose like mine) but I don't have the cash for such things. I was hopeing for a simple way to changing the generated code over to the format I want. What I would realy like is a way to change direction while the display is being built. I don't care if I use a sizer or another method. Using excel as an alternative method looks intresting but it isn't what I was after.

          ie from bs = wx.BoxSizer(wx. HORIZONTAL) to bs = wx.BoxSizer(wx. VERTICAL) while I am building the display.
          wx.VERTICAL and wx.HORIZONTAL are flags in the Style "constructo r" arguement. On all wx widgets that I've looked at so far, there are no commands that change the style on the fly (after it has been created). The proper technique is to put sizers inside sizers. It easy (I take back what I said earlier, after playing with this) to get good results this way. Make a vertical sizer with a horizontal box sizer in it which gets you buttons added to it. The only other item that the horizontal sizer is in charge of is your grid.

          There are lots of free tools (I don't recall any commercial products in my list).

          Comment

          Working...