pythonwxpythonhierarchywxformbuilder

Dividing code(as several files) for each wxscrolledWindow


Please understand that I have never written complex code, so my question may not be appropriate.

As the hierarchy as shown, I made a code(Frame.py) for the notebook containing eight wxScrolledWindows using wxFormBuilder. the code is like as below.

import wx
import wx.xrc
import wx.grid
...
class MyFrame(wx.Frmae):
  def __init__(self.parent):
    lines with wxScrolledWindow1
    lines with wxScrolledWindow2
    lines with wxScrolledWindow3
    ..
    lines with wxScrolledWindow8

  def button1(self.event):
  def ...

class frmProblem (wx.Dialog):
  ...

Here, I'd like to write the code that deals with each wxScrolledWindow separately so that I don't write too much code in one file. (main.py, window1.py, window2.py, ...)But I'm not sure how to organize the files and how to link the code together. Each wxScrolledWindow must interact with each other and get variables from other windows.

My current main.py contains the code to handle all windows, as shown below.

from Frame import MyFrame1, frmProblem
import...

class Setting(frmProblem):
  def __init__(self. parent):
    ...
  def button1_click(self, event):
    ...
  def button2_click(self, event):
    ...

class Main(MyFrame1):
  def __init__(self, parent):
    code for wxScrolledWindow1
    code for wxScrolledWindow2
    code for wxScrolledWindow3
    ...
    code for wxScrolledWindow8
    ...

  def wxScrolledWindow1_button1(self, event):
     ...
  def wxScrolledWindow1_func1(arg):
     ...
  def wxScrolledWindow1_func2(arg):
     ...
  def wxScrolledWindow2_button1(self, event):
     ...
  def wxScrolledWindow2_func1(arg):
     ...
  def wxScrolledWindow2_func2(arg):
     ...
     ...
  def wxScrolledWindow8_button1(self, event):
     ...
  def wxScrolledWindow8_func1(arg):
     ...
  def wxScrolledWindow8_func2(arg):
     ...

Any advice will help me solve this problem. =)

enter image description here


Solution

  • With the help of ChatGPT, I solved this problem.

    for main.py, I include each scrolled window file

    import wx
    from myclass1 import myclass1
    from myclass2 import myclass2
    ...
    
    class MyFrame(wx.Frame):
        def __init__(self, parent, id.ID_ANY, ...)
            super(MyFrame, self).__init__(parent, id, title, pose, size, style)
    
            notebook = wx.Notebook(self)
            Class1 = myclass1(notebook)
            Class2 = myclass2(notebook)
            ...
            
            notebook.AddPage(Class1, 'Page1')
            notebook.AddPage(Class2, 'Page2')
            notebook.AddPage(Class3, 'Page3')
    
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(notebook, 1, wx.EXPAND)
            self.SetSizer(sizer)
            self.Show()
    
    app = wx.App()
    frame = MyFrame(None, title='My Notebook example')
    app.MainLoop()
    

    Then I write the py file for each page.

    import wx
    class myclass1(wx.ScrolledwWindow):
    
        def __init__(self, parent):
            super(myclass1, self).__init__(parent)
            ...
    

    Now a days, LLM helps me a lot =)