Python Forum
Box Sizer inside of panel managed by wx.lib.agw.aui
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Box Sizer inside of panel managed by wx.lib.agw.aui
#1
Hello,

I have been playing with AUI in wxpython phoenix.
I have managed to get a nice window with a menu, and three fully resizable
(one panel and two text controls) windows.

The AUI manager allows the widows to be individually stretched, with the other two filling
the gaps. It also (not yet implemented) will allow turning docking on and off.

(Actually docking is partially implemented by default)

So far so good.

Next I wanted to enter a ListCtrl in the Panel to allow selection from a document list.

I am having trouble getting the control to size properly (I want it to expand to the full size of the panel).
I've done this before outside of an AUI manager without issue, and I thought I was doing it properly
in this example as well, but I think I'm confusing myself (I've been playing with this for about fourteen hours,
trying all sorts of things to get to this point, and it's probably fatigue) and I can't see what I am doing wrong.

Here's the code, which will only currently work on windows (I use windows 7) until I figure how to size a window
on other platforms. I used Python 3.6.1

import wx
import wx.lib.agw.aui as aui
from win32api import GetSystemMetrics
import sys


class MainFrame(wx.Frame):
   def __init__(self, parent, id=-1, title='Document Viewer', pos=wx.DefaultPosition,
                size=(800, 600), style=wx.DEFAULT_FRAME_STYLE, 
                screen_factor=.6, local_data=True):

       self.screen_factor = screen_factor
       self.get_screen_info()

       wx.Frame.__init__(self, parent, id, title, pos,
                         size=(self.scwidth, self.scheight))

       self.create_menu()
       self._mgr = aui.AuiManager()
       self.manager_open = True

       self._mgr.SetManagedWindow(self)

       panel1 = wx.Panel(self, id=wx.ID_ANY, pos=wx.DefaultPosition,
                         size=wx.Size(400, 150),
                         style=wx.NO_BORDER | wx.TE_MULTILINE)
       panel1.SetBackgroundColour('#fcf2dc')

       text2 = wx.TextCtrl(self, -1, "Search options, etc. goes here",
                           wx.DefaultPosition, wx.Size(200,150),
                           wx.NO_BORDER | wx.TE_MULTILINE)
       text2.SetBackgroundColour('#f9e6ba')

       self.text3 = wx.TextCtrl(self, -1, "Document Goes Here",
                           wx.DefaultPosition, wx.Size(200,150),
                           wx.NO_BORDER | wx.TE_MULTILINE)
       self.text3.SetBackgroundColour('#f5d997')

       self._mgr.AddPane(panel1, aui.AuiPaneInfo().Left().Caption("Document Selector"))
       self._mgr.AddPane(text2, aui.AuiPaneInfo().Bottom().Caption("Options"))
       self._mgr.AddPane(self.text3, aui.AuiPaneInfo().CenterPane().Caption('Documemt'))

       self.lst = wx.ListCtrl(panel1, style=wx.LC_REPORT | wx.BORDER_SUNKEN)
       self.lst.SetBackgroundColour('#fcf2dc')
       self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.lst_item_selected, self.lst)

        self.horizontal = wx.BoxSizer()
        self.horizontal.Add(self.lst, proportion=1, flag=wx.EXPAND)

        self.vertical = wx.BoxSizer(wx.VERTICAL)
        self.vertical.Add(self.horizontal, proportion=1, flag=wx.EXPAND)
        panel1.SetSizerAndFit(self.vertical)

       self.Bind(wx.EVT_CLOSE, self.OnClose)

       self._mgr.Update()

   def lst_item_selected(self, evt):
       self.text3.Clear()
       item_index = self.lst.GetFirstSelected()
       print('Item: {} selected'.format(item_index))

   def OnClose(self, evt):
       self._mgr.UnInit()
       self.manager_open = False
       evt.Skip()

   def get_screen_info(self):
       self.screen_width = GetSystemMetrics(0)
       self.screen_height = GetSystemMetrics(1)
       self.scwidth = int(self.screen_width * self.screen_factor)
       self.scheight = int(self.screen_height * self.screen_factor)
       self.hoffset = int((self.screen_width * .2) / 2)
       self.voffset = int((self.screen_height * .2) / 2)

   def create_menu(self):
       menubar = wx.MenuBar()

       fileMenu = wx.Menu()
       fileMenu.Append(wx.ID_OPEN, '&Open\tCtrl+O')
       fileMenu.Append(wx.ID_SAVE, '&Save\tCtrl+S')
       fileMenu.Append(wx.ID_SAVE, 'Save As\tCtrl+Alt+S')
       fileMenu.AppendSeparator()
       fileMenu.Append(wx.ID_SAVE, '&Print\tCtrl+P')
       fileMenu.Append(wx.ID_SAVE, 'Page Set&up')
       fileMenu.Append(wx.ID_SAVE, 'Print Pre&view')
       fileMenu.AppendSeparator()

       helpMenu = wx.Menu()
       helpMenu.Append(wx.ID_ABOUT, '&About')
       helpMenu.Append(wx.ID_ABOUT, '&RFCviewer &Help')

       qmi = wx.MenuItem(fileMenu, wx.ID_EXIT, 'Quit\tCtrl+W')
       fileMenu.Append(qmi)

       self.Bind(wx.EVT_MENU, self.OnQuit, qmi)

       menubar.Append(fileMenu, '&File')
       menubar.Append(helpMenu, '&Help')
       self.SetMenuBar(menubar)

       self.Centre()
       self.Show(True)

   def OnQuit(self, evt):
       if self.manager_open:
           self._mgr.UnInit()
       sys.exit(0)


def main():
   app = wx.App(0)
   frame = MainFrame(None, pos=(50,50), screen_factor=.8)
   app.SetTopWindow(frame)
   frame.Show()
   app.MainLoop()

if __name__ == '__main__':
   main()
screen shot:
   

would appreciate any help.
Reply
#2
I updated the sizer for self.lst, and moved the manager update.

That seems to have solved the issue.

I'll know for sure once the ListCtrl is populated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Help setting text/title in dock/panel in tkinter gui FluxApex 2 4,401 Mar-18-2020, 07:15 PM
Last Post: FluxApex
  video player inside a frame/panel in python raspberry pi desktop application MATHEWS 1 2,844 Dec-12-2018, 11:42 AM
Last Post: Larz60+
  [WxPython] Help with passing arguments into a wx.Panel ? merlem 7 8,294 Jan-26-2017, 02:09 PM
Last Post: merlem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020