Python Forum
Looking for new example wxpython AUI code
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking for new example wxpython AUI code
#2
I should have explained that the Basic Manager window is to be used
as a template to quickly get a foundation for a new application during the development stage,
and should later be replaced with more application specific code.

Also, the screen_factor argument to __init__ determines the size of the main screen.
The default is .5 which relates to 50% of the users screen size. This can be modified as desired.
This one 'feature' limits usage (until I figure out how to do it with Linux and OS-X) to MS windows.
If you remove that code, everything should work (Unless some of the docking code is specific to MS)
on Linux and OS-X, but I haven't tested this theory.

I made some (slight ) modifications to the original:
  • Added an import of os (for path basename), which I use in the class initialization
        for name.

  • Added docstring with usage example.
        It shows how the template can be used with just 12 lines of code to create a basic AUI framework
        in which you can build your application.

New Listing:
import wx
import wx.aui
from win32api import GetSystemMetrics
import os

"""
The BasicApp can be used to set the empty Framework for an AUI application.

Usage:

import wx
import wx.aui
import BasicApp


class TryAuiFramemanager(object):
   def __init__(self):
       BasicApp.__init__(title='RFC Viewer')


def main():
   app = wx.App()
   TryAuiFramemanager()
   app.MainLoop()


if __name__ == '__main__':
   main()

"""
class BasicApp(wx.Frame):
   def __init__(self,
                parent=None,
                id=wx.ID_ANY,
                title='Basic App',
                pos=(50, 50),
                size=(400, 400),
                style=wx.DEFAULT_FRAME_STYLE,
                screen_factor=.5, name=os.path.basename(__file__)):
       program_name = os.path.basename(__file__)
       print('program_name: {}'.format(program_name))
       self.screen_factor = screen_factor
       self.get_screen_info()

       wx.Frame.__init__(
           self, parent=parent, id=id, title=title, pos=(self.hoffset, self.voffset),
           size=(self.scwidth, self.scheight), style=style, name='BasicApp'
       )

       self.initialize_components()
       self.CreateStatusBar()
       self.Show()

   def initialize_components(self):
       self._mgr = wx.aui.AuiManager()
       self._mgr.SetManagedWindow(self)

       self._perspectives = []

       self._mgr.Update()

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

   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 on_close(self, event):
       self._mgr.UnInit()
       del self._mgr
       self.Destroy()


def main():
   app = wx.App()
   BasicApp()
   # frame.Show(True)
   app.MainLoop()

if __name__ == '__main__':
   main()
and sample usage:
import wx
import wx.aui
import BasicApp


class TryAuiFramemanager(object):
   def __init__(self):
       BasicApp.__init__(title='RFC Viewer')


def main():
   app = wx.App()
   TryAuiFramemanager()
   app.MainLoop()


if __name__ == '__main__':
   main()
Reply


Messages In This Thread
RE: Looking for new example wxpython AUI code - by Larz60+ - Jun-18-2017, 04:22 PM

Forum Jump:

User Panel Messages

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