Python Forum

Full Version: Perfectly proportioned 3 frame wxpython application template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here is a framework for a three panel wxpython (phoenix) application. With
proper sizing. The aspect ratio of 1.779 to 1 is supposed to be the proper ratio
for visually correct window size.

All initial individual panel widths and heights are based on the size of the main wx.Frame.
If you modify this size, all panels should follow suit.

The bottom frame contains two widgets, so a vertical sizer is used to keep them in perspective.

The TextCtrl on the right panel has it's own sizer, and uses the proportion flag, and expand flag.
This sizer is needed or the TextCtrl will not expand properly.

The bottom panel also needs a vertical sizer to keep the button on the bottom (two widgets in this pane).

The AUI Manager is used, which automatically gives you docking panels and maintains pane resizing automatically.

*** Update Feb 11, 2020 ***

I had a need to use this framework, and when testing noted that some of the size code was depreciated.
wxpython now requires all sizes be integers.
Changes are in line 44 to 70 (cast to integer)
so here's corrected code:
import wx
import wx.aui as aui
import wx.lib.agw.aui as aui

class TryMethods(wx.Frame):
    Initialize - inherits from wx.Frame. Instantiates all widgets and variables for application

    :param parent: (wx.Window) The window parent. This may be, and often is, None. If it is not None, the frame
                   will be minimized when its parent is minimized and restored when it is restored (although it
                   will still be possible to minimize and restore just this frame itself).

    :param id:     (wx.WindowID) The window identifier. It may take a value of -1 to indicate a default value.

    :param title:  (string)  The caption to be displayed on the frame’s title bar.

    :param pos:    (wx.point) The window position. The value DefaultPosition indicates a default position,
                   chosen by either the windowing system or wxWidgets, depending on platform.

    :param size:   (wx.Size) – The window size. The value DefaultSize indicates a default size, chosen by either
                   the windowing system or wxWidgets, depending on platform. Here use properly proportioned
                   (according to the window size gods) width and height.

    :param style:  (long) – The window style. See wx.Frame class description.

    :param name:   (string) The name of the window. This parameter is used to associate a name with the item,
                   allowing the application user to set Motif resource values for individual windows.

    def __init__(self, parent, id=wx.ID_ANY, title="Try PuMuPDF methods", pos=wx.DefaultPosition,
                 size=(1200, 675), style=wx.DEFAULT_FRAME_STYLE, name='TryMethods'):
        # ideal size: width = height x 1.77864583 or height = width / 1.77864583
        self.main_width = size[0]
        self.main_height = size[1]

        app = wx.App()
        wx.Frame.__init__(self, parent, id, title, pos, size, style)
        # self.pnl = pnl = MainPanel(self)
        self._mgr = aui.AuiManager(self)

        # This is 30% of main width
        left_panel_width = int(self.main_width * .3)
        # This is 75% of main height
        left_panel_height = int(self.main_height * .75)
        left_panel_sz = left_panel_width, left_panel_height  # combined for widget size

        right_panel_width = self.main_width - \
            left_panel_width  # which is 70% of main width
        right_panel_height = left_panel_height  # Keep same height as left panel
        right_panel_sz = right_panel_width, right_panel_height

        bottom_panel_width = self.main_width  # full width
        bottom_panel_height = int(
            self.main_height * .20)  # 20 % of main height
        bottom_panel_sz = bottom_panel_width, bottom_panel_height

        self.left_panel = wx.Panel(self, id=wx.ID_ANY, size=left_panel_sz)
        self.right_panel = wx.Panel(self, id=wx.ID_ANY, size=right_panel_sz)
        self.bottom_panel = wx.Panel(self, id=wx.ID_ANY, size=bottom_panel_sz)

        self.pdf_selector = wx.ListCtrl(self.left_panel, id=wx.ID_ANY, style=wx.NO_BORDER | wx.TE_MULTILINE,
                                        size=left_panel_sz, name='PDF Selector')

            0, 'PDF Id', width=int(left_panel_width * .25))
            1, 'Title', width=int(left_panel_width * .75))


        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.detail_win = wx.TextCtrl(self.right_panel, id=wx.ID_ANY, value="Choose Methods",
                                      pos=wx.DefaultPosition, size=right_panel_sz,
                                      style=wx.NO_BORDER | wx.TE_MULTILINE, name='PdfSummary')

        hsizer.Add(self.detail_win, proportion=1, flag=wx.EXPAND)

        self.optionList = ['Importing the Bindings', 'Opening a Document', 'Document Methods and Attributes',
                           'Accessing Meta Data', 'Working with Outlines', 'Working with Pages',
                           'Inspecting the Links of a Page', 'Rendering a Page', 'Saving the Page Image in a File',
                           'Displaying the Image in Dialog Managers', 'Extracting Text', 'Searching Text',
                           'PDF Maintenance', 'Modifying, Creating, Re-arranging and Deleting Pages',
                           'Joining and Splitting PDF Documents', 'Saving', 'Closing']

        vsizer = wx.BoxSizer(wx.VERTICAL)
        self.method_selector = wx.RadioBox(self.bottom_panel, id=wx.ID_ANY, choices=self.optionList,
                                           majorDimension=4, style=wx.RA_SPECIFY_COLS)
        vsizer.Add(self.method_selector, 0, 0, 0)

        self.method_button = wx.Button(
            self.bottom_panel, id=wx.ID_ANY, label='Show Method')
        vsizer.Add(self.method_button, 0, 0, 0)
        self.method_button.Bind(wx.EVT_BUTTON, self.method_selected)


            self.left_panel, aui.AuiPaneInfo().Left().Caption("Left Panel"))
                          aui.AuiPaneInfo().Center().Caption("Right Panel"))
                          aui.AuiPaneInfo().Bottom().Caption("Bottom Panel"))



    def pdf_selector_load(self):

    def method_selected(self, event):
        radio_index = self.method_selector.GetSelection()
        print(f'Selected Method: {self.optionList[radio_index]}')

if __name__ == '__main__':
    tm = TryMethods(None)

Updated 27 Feb 2020 - Removed depreciated code as it was easily confused with new code
Small error here
    def method_selected(self, event):
        radio_index = self.method_selector.GetSelection()
        print(f'Selected Method: {self.optionList[radio_index]}')
comma missing
    def method_selected(self, event):
        radio_index = self.method_selector.GetSelection()
        print(f,'Selected Method: {self.optionList[radio_index]}')
Otherwise great example, thanks
:-) it's not an error but f-string, available in Python 3.6+

With comma you will get NameError, f is not defined
I think I should look at wx.

1.618 ratio?
Quote:1.618 ratio?
Or something like that
I just looked for other 3 frame wxpython examples, here's the results: