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
screen shot:
would appreciate any help.
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
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() |
would appreciate any help.