Access to other side of panel

Thank you Mike Driscoll and C M for answering my previous mail, my prevous approach was not good. I have now learnt that sizers are smart!

Still, there is one issue left, and that is related to the access of a CheckListBox in class LeftPanel from RightPanel. Below is a runnable sample. Honestly, I have tried to remove all unnecessary pieces of code... See my comment under the OnAdd method in class RightPanel - how do I add a word to the CheckListBox in class LeftPanel.

I have not yet looked into the pubsub as suggested by Mike, hopefully there are a simpler solution...

import wx
class RightPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.SetBackgroundColour('White')
        self.addBox = wx.BoxSizer(wx.HORIZONTAL)
        self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                         validator=wx.DefaultValidator)
        self.addText.SetMaxLength(12)
        self.addButton = wx.Button(self, -1, 'Add')
        self.addBox.Add(self.addText, 0, wx.ALL, 1)
        self.addBox.Add(self.addButton, 0, wx.ALL, 1)
        self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
        self.addBox.Fit(self)
        self.SetSizer(self.addBox)
        self.Layout()

    def OnAdd(self, event):
        word = self.addText.GetValue()

        #HERE IS THE CLUE: HOW DO I APPEND word TO THE CheckListBox OF
        #THE LEFT PANEL, as I do in the OnAdd method of the LeftPanel class

        #This provides a new CheckListBox on top of the previous, and that is NOT what I want
        LeftPanel(wx.GetApp().GetTopWindow()).clBox.Append(word)
       class LeftPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        #Initialization
        self.SetBackgroundColour('White')
        self.aList = []
        #Boxes
        self.mainBox = wx.BoxSizer(wx.VERTICAL)
        self.clBox = wx.CheckListBox(self, -1, pos=wx.DefaultPosition,\
                                     size=wx.DefaultSize, choices=self.aList,\
                                     style=0, validator=wx.DefaultValidator,\
                                     name='checklistBox')
               #Add box containing textctrl and add button
        self.addBox = wx.BoxSizer(wx.HORIZONTAL)
        self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                         validator=wx.DefaultValidator)
        self.addText.SetMaxLength(12)
        self.addButton = wx.Button(self, -1, 'Add')
        self.addBox.Add(self.addText, 0, wx.ALL, 1)
        self.addBox.Add(self.addButton, 0, wx.ALL, 1)
        self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
               #Adding to mainbox
        self.mainBox.Add(self.clBox, 0, wx.ALL, 1)
        self.mainBox.Add(self.addBox, 0, wx.EXPAND, 0)
        self.mainBox.Fit(self)
        self.SetSizer(self.mainBox)
        self.Layout()

    def OnAdd(self, event):
        word = self.addText.GetValue()
        self.clBox.Append(word)
        self.Layout()

class MainFrame(wx.Frame):
    def __init__(self, parent=None, id=-1, pos=wx.DefaultPosition, \
                 title='Program name here'):
        wx.Frame.__init__(self, parent, id, title, pos, (1100, 600))

        #Creating splitter with two panels
        self.initpos = 245
        self.splitter = wx.SplitterWindow(self)
        self.leftPanel = LeftPanel(self.splitter)
        self.rightPanel = RightPanel(self.splitter)
        self.splitter.Initialize(self.leftPanel)
        self.splitter.Initialize(self.rightPanel)
        self.splitter.SplitVertically(self.leftPanel, self.rightPanel, self.initpos)
        self.leftPanel.Fit()
        self.rightPanel.Fit()
        self.Centre()
        self.Layout()

class App(wx.App):
    def OnInit(self):
        self.frame = MainFrame()
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True
   def main():
    app = App()
    import wx.lib.inspection
    wx.lib.inspection.InspectionTool().Show()
    app.MainLoop()

if __name__ == '__main__':
    main()

Hi Andy,

Attached is a file that does what you need. The trick was to just
pass a reference to the left panel when you make the call to the
right panel. This way the right panel "knows about" the existence
of the left panel (and not just the class, that exact instantiation of it).

Really a more preferred way for more involved things would be to
use PubSub, but this is fine for this smaller purpose I think.

Search the code for "-Che" to find out where I've altered it.

I couldn't get your app to run without a few cleanups along the way.
Those I didn't "autograph", though.

Good luck!
Che

andy_app.py (3.58 KB)

···

On Sun, Oct 26, 2008 at 4:20 PM, andy <postinger@start.no> wrote:

Thank you Mike Driscoll and C M for answering my previous mail, my prevous
approach was not good. I have now learnt that sizers are smart!

Still, there is one issue left, and that is related to the access of a
CheckListBox in class LeftPanel from RightPanel. Below is a runnable sample.
Honestly, I have tried to remove all unnecessary pieces of code... See my
comment under the OnAdd method in class RightPanel - how do I add a word to
the CheckListBox in class LeftPanel.

I have not yet looked into the pubsub as suggested by Mike, hopefully there
are a simpler solution...

import wx
class RightPanel(wx.Panel):
  def __init__(self, parent):
      wx.Panel.__init__(self, parent)
      self.SetBackgroundColour('White')
      self.addBox = wx.BoxSizer(wx.HORIZONTAL)
      self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                       validator=wx.DefaultValidator)
      self.addText.SetMaxLength(12)
      self.addButton = wx.Button(self, -1, 'Add')
      self.addBox.Add(self.addText, 0, wx.ALL, 1)
      self.addBox.Add(self.addButton, 0, wx.ALL, 1)
      self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
      self.addBox.Fit(self)
      self.SetSizer(self.addBox)
      self.Layout()

  def OnAdd(self, event):
      word = self.addText.GetValue()

      #HERE IS THE CLUE: HOW DO I APPEND word TO THE CheckListBox OF
      #THE LEFT PANEL, as I do in the OnAdd method of the LeftPanel class

      #This provides a new CheckListBox on top of the previous, and that is
NOT what I want
      LeftPanel(wx.GetApp().GetTopWindow()).clBox.Append(word)
     class LeftPanel(wx.Panel):
  def __init__(self, parent):
      wx.Panel.__init__(self, parent)

      #Initialization
      self.SetBackgroundColour('White')
      self.aList =
      #Boxes
      self.mainBox = wx.BoxSizer(wx.VERTICAL)
      self.clBox = wx.CheckListBox(self, -1, pos=wx.DefaultPosition,\
                                   size=wx.DefaultSize, choices=self.aList,\
                                   style=0, validator=wx.DefaultValidator,\
                                   name='checklistBox')
            #Add box containing textctrl and add button
      self.addBox = wx.BoxSizer(wx.HORIZONTAL)
      self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                       validator=wx.DefaultValidator)
      self.addText.SetMaxLength(12)
      self.addButton = wx.Button(self, -1, 'Add')
      self.addBox.Add(self.addText, 0, wx.ALL, 1)
      self.addBox.Add(self.addButton, 0, wx.ALL, 1)
      self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
            #Adding to mainbox
      self.mainBox.Add(self.clBox, 0, wx.ALL, 1)
      self.mainBox.Add(self.addBox, 0, wx.EXPAND, 0)
      self.mainBox.Fit(self)
      self.SetSizer(self.mainBox)
      self.Layout()

  def OnAdd(self, event):
      word = self.addText.GetValue()
      self.clBox.Append(word)
      self.Layout()

class MainFrame(wx.Frame):
  def __init__(self, parent=None, id=-1, pos=wx.DefaultPosition, \
               title='Program name here'):
      wx.Frame.__init__(self, parent, id, title, pos, (1100, 600))

      #Creating splitter with two panels
      self.initpos = 245
      self.splitter = wx.SplitterWindow(self)
      self.leftPanel = LeftPanel(self.splitter)
      self.rightPanel = RightPanel(self.splitter)
      self.splitter.Initialize(self.leftPanel)
      self.splitter.Initialize(self.rightPanel)
      self.splitter.SplitVertically(self.leftPanel, self.rightPanel,
self.initpos)
      self.leftPanel.Fit()
      self.rightPanel.Fit()
      self.Centre()
      self.Layout()

class App(wx.App):
  def OnInit(self):
      self.frame = MainFrame()
      self.frame.Show()
      self.SetTopWindow(self.frame)
      return True
def main():
  app = App()
  import wx.lib.inspection
  wx.lib.inspection.InspectionTool().Show()
  app.MainLoop()

if __name__ == '__main__':
  main()
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Thank you Mike Driscoll and C M for answering my previous mail, my prevous
approach was not good. I have now learnt that sizers are smart!

Still, there is one issue left, and that is related to the access of a
CheckListBox in class LeftPanel from RightPanel. Below is a runnable sample.
Honestly, I have tried to remove all unnecessary pieces of code... See my
comment under the OnAdd method in class RightPanel - how do I add a word to
the CheckListBox in class LeftPanel.

I have not yet looked into the pubsub as suggested by Mike, hopefully there
are a simpler solution...

import wx
class RightPanel(wx.Panel):
  def __init__(self, parent):
      wx.Panel.__init__(self, parent)
      self.SetBackgroundColour('White')
      self.addBox = wx.BoxSizer(wx.HORIZONTAL)
      self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                       validator=wx.DefaultValidator)
      self.addText.SetMaxLength(12)
      self.addButton = wx.Button(self, -1, 'Add')
      self.addBox.Add(self.addText, 0, wx.ALL, 1)
      self.addBox.Add(self.addButton, 0, wx.ALL, 1)
      self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
      self.addBox.Fit(self)
      self.SetSizer(self.addBox)
      self.Layout()

  def OnAdd(self, event):
      word = self.addText.GetValue()

      #HERE IS THE CLUE: HOW DO I APPEND word TO THE CheckListBox OF
      #THE LEFT PANEL, as I do in the OnAdd method of the LeftPanel class

      #This provides a new CheckListBox on top of the previous, and that is
NOT what I want
      LeftPanel(wx.GetApp().GetTopWindow()).clBox.Append(word)
     class LeftPanel(wx.Panel):
  def __init__(self, parent):
      wx.Panel.__init__(self, parent)

      #Initialization
      self.SetBackgroundColour('White')
      self.aList =
      #Boxes
      self.mainBox = wx.BoxSizer(wx.VERTICAL)
      self.clBox = wx.CheckListBox(self, -1, pos=wx.DefaultPosition,\
                                   size=wx.DefaultSize, choices=self.aList,\
                                   style=0, validator=wx.DefaultValidator,\
                                   name='checklistBox')
            #Add box containing textctrl and add button
      self.addBox = wx.BoxSizer(wx.HORIZONTAL)
      self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                       validator=wx.DefaultValidator)
      self.addText.SetMaxLength(12)
      self.addButton = wx.Button(self, -1, 'Add')
      self.addBox.Add(self.addText, 0, wx.ALL, 1)
      self.addBox.Add(self.addButton, 0, wx.ALL, 1)
      self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
            #Adding to mainbox
      self.mainBox.Add(self.clBox, 0, wx.ALL, 1)
      self.mainBox.Add(self.addBox, 0, wx.EXPAND, 0)
      self.mainBox.Fit(self)
      self.SetSizer(self.mainBox)
      self.Layout()

  def OnAdd(self, event):
      word = self.addText.GetValue()
      self.clBox.Append(word)
      self.Layout()

class MainFrame(wx.Frame):
  def __init__(self, parent=None, id=-1, pos=wx.DefaultPosition, \
               title='Program name here'):
      wx.Frame.__init__(self, parent, id, title, pos, (1100, 600))

      #Creating splitter with two panels
      self.initpos = 245
      self.splitter = wx.SplitterWindow(self)
      self.leftPanel = LeftPanel(self.splitter)
      self.rightPanel = RightPanel(self.splitter)
      self.splitter.Initialize(self.leftPanel)
      self.splitter.Initialize(self.rightPanel)
      self.splitter.SplitVertically(self.leftPanel, self.rightPanel,
self.initpos)
      self.leftPanel.Fit()
      self.rightPanel.Fit()
      self.Centre()
      self.Layout()

class App(wx.App):
  def OnInit(self):
      self.frame = MainFrame()
      self.frame.Show()
      self.SetTopWindow(self.frame)
      return True
def main():
  app = App()
  import wx.lib.inspection
  wx.lib.inspection.InspectionTool().Show()
  app.MainLoop()

if __name__ == '__main__':
  main()
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Andy,

Attached is a file that does what you need. The trick was to just
pass a reference to the left panel when you make the call to the
right panel. This way the right panel "knows about" the existence
of the left panel (and not just the class, that exact instantiation of it).

Was rushing off to eat and had a weird mental block in which I could
not recall the word "instance" and instead said "instantiation". So
keep in mind, I should have said *that exact instance" of your LeftPanel class.

Really a more preferred way for more involved things would be to
use PubSub, but this is fine for this smaller purpose I think.

Also I'll add the reason: because, as written, the code for
RightPanel depends on LeftPanel being there, and in fact having the
clBox in it. If either of those facts change in later versions of your code,
it will break things. Therefore, doing it the way I've shown creates this
problem. See this thread in which others helped me out to understand
these things earlier this year:

http://www.nabble.com/pubsub-necessary-in-this-case--td17976424.html#a17976434
(check out Jurgen's comment from April 10, 2008 at 5:06am particularly for
why pubsub is often a good idea).

Lastly, in your code, I highly suggest making all indents 4 whitespaces.

Che

···

On Sun, Oct 26, 2008 at 7:20 PM, C M <cmpython@gmail.com> wrote:

On Sun, Oct 26, 2008 at 4:20 PM, andy <postinger@start.no> wrote:

C M skrev:

  

Thank you Mike Driscoll and C M for answering my previous mail, my prevous
approach was not good. I have now learnt that sizers are smart!

Still, there is one issue left, and that is related to the access of a
CheckListBox in class LeftPanel from RightPanel. Below is a runnable sample.
Honestly, I have tried to remove all unnecessary pieces of code... See my
comment under the OnAdd method in class RightPanel - how do I add a word to
the CheckListBox in class LeftPanel.

I have not yet looked into the pubsub as suggested by Mike, hopefully there
are a simpler solution...

import wx
class RightPanel(wx.Panel):
  def __init__(self, parent):
      wx.Panel.__init__(self, parent)
      self.SetBackgroundColour('White')
      self.addBox = wx.BoxSizer(wx.HORIZONTAL)
      self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                       validator=wx.DefaultValidator)
      self.addText.SetMaxLength(12)
      self.addButton = wx.Button(self, -1, 'Add')
      self.addBox.Add(self.addText, 0, wx.ALL, 1)
      self.addBox.Add(self.addButton, 0, wx.ALL, 1)
      self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
      self.addBox.Fit(self)
      self.SetSizer(self.addBox)
      self.Layout()

  def OnAdd(self, event):
      word = self.addText.GetValue()

      #HERE IS THE CLUE: HOW DO I APPEND word TO THE CheckListBox OF
      #THE LEFT PANEL, as I do in the OnAdd method of the LeftPanel class

      #This provides a new CheckListBox on top of the previous, and that is
NOT what I want
      LeftPanel(wx.GetApp().GetTopWindow()).clBox.Append(word)
     class LeftPanel(wx.Panel):
  def __init__(self, parent):
      wx.Panel.__init__(self, parent)

      #Initialization
      self.SetBackgroundColour('White')
      self.aList =
      #Boxes
      self.mainBox = wx.BoxSizer(wx.VERTICAL)
      self.clBox = wx.CheckListBox(self, -1, pos=wx.DefaultPosition,\
                                   size=wx.DefaultSize, choices=self.aList,\
                                   style=0, validator=wx.DefaultValidator,\
                                   name='checklistBox')
            #Add box containing textctrl and add button
      self.addBox = wx.BoxSizer(wx.HORIZONTAL)
      self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                       validator=wx.DefaultValidator)
      self.addText.SetMaxLength(12)
      self.addButton = wx.Button(self, -1, 'Add')
      self.addBox.Add(self.addText, 0, wx.ALL, 1)
      self.addBox.Add(self.addButton, 0, wx.ALL, 1)
      self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
            #Adding to mainbox
      self.mainBox.Add(self.clBox, 0, wx.ALL, 1)
      self.mainBox.Add(self.addBox, 0, wx.EXPAND, 0)
      self.mainBox.Fit(self)
      self.SetSizer(self.mainBox)
      self.Layout()

  def OnAdd(self, event):
      word = self.addText.GetValue()
      self.clBox.Append(word)
      self.Layout()

class MainFrame(wx.Frame):
  def __init__(self, parent=None, id=-1, pos=wx.DefaultPosition, \
               title='Program name here'):
      wx.Frame.__init__(self, parent, id, title, pos, (1100, 600))

      #Creating splitter with two panels
      self.initpos = 245
      self.splitter = wx.SplitterWindow(self)
      self.leftPanel = LeftPanel(self.splitter)
      self.rightPanel = RightPanel(self.splitter)
      self.splitter.Initialize(self.leftPanel)
      self.splitter.Initialize(self.rightPanel)
      self.splitter.SplitVertically(self.leftPanel, self.rightPanel,
self.initpos)
      self.leftPanel.Fit()
      self.rightPanel.Fit()
      self.Centre()
      self.Layout()

class App(wx.App):
  def OnInit(self):
      self.frame = MainFrame()
      self.frame.Show()
      self.SetTopWindow(self.frame)
      return True
def main():
  app = App()
  import wx.lib.inspection
  wx.lib.inspection.InspectionTool().Show()
  app.MainLoop()

if __name__ == '__main__':
  main()
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Andy,

Attached is a file that does what you need. The trick was to just
pass a reference to the left panel when you make the call to the
right panel. This way the right panel "knows about" the existence
of the left panel (and not just the class, that exact instantiation of it).
    
Was rushing off to eat and had a weird mental block in which I could
not recall the word "instance" and instead said "instantiation". So
keep in mind, I should have said *that exact instance" of your LeftPanel class.

Really a more preferred way for more involved things would be to
use PubSub, but this is fine for this smaller purpose I think.
    
Also I'll add the reason: because, as written, the code for
RightPanel depends on LeftPanel being there, and in fact having the
clBox in it. If either of those facts change in later versions of your code,
it will break things. Therefore, doing it the way I've shown creates this
problem. See this thread in which others helped me out to understand
these things earlier this year:

http://www.nabble.com/pubsub-necessary-in-this-case--td17976424.html#a17976434
(check out Jurgen's comment from April 10, 2008 at 5:06am particularly for
why pubsub is often a good idea).

Lastly, in your code, I highly suggest making all indents 4 whitespaces.

Che
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
  

I am looking forward to go into your solution in detail!
In my program I think I have full control of both my LeftPanel and my RightPanel

Hm, I am programming in IDLE on Windows with default settings, isnt 4 whitespaces default there? Anyway, my code ran fine here,
I only did a copy - paste into my Thunderbird e-mail program before sending.

/Andy

···

On Sun, Oct 26, 2008 at 7:20 PM, C M <cmpython@gmail.com> wrote:

On Sun, Oct 26, 2008 at 4:20 PM, andy <postinger@start.no> wrote:

andy wrote:

C M skrev:

Thank you Mike Driscoll and C M for answering my previous mail, my prevous
approach was not good. I have now learnt that sizers are smart!

Still, there is one issue left, and that is related to the access of a
CheckListBox in class LeftPanel from RightPanel. Below is a runnable sample.
Honestly, I have tried to remove all unnecessary pieces of code... See my
comment under the OnAdd method in class RightPanel - how do I add a word to
the CheckListBox in class LeftPanel.

I have not yet looked into the pubsub as suggested by Mike, hopefully there
are a simpler solution...

import wx
class RightPanel(wx.Panel):
  def __init__(self, parent):
      wx.Panel.__init__(self, parent)
      self.SetBackgroundColour('White')
      self.addBox = wx.BoxSizer(wx.HORIZONTAL)
      self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                       validator=wx.DefaultValidator)
      self.addText.SetMaxLength(12)
      self.addButton = wx.Button(self, -1, 'Add')
      self.addBox.Add(self.addText, 0, wx.ALL, 1)
      self.addBox.Add(self.addButton, 0, wx.ALL, 1)
      self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
      self.addBox.Fit(self)
      self.SetSizer(self.addBox)
      self.Layout()

  def OnAdd(self, event):
      word = self.addText.GetValue()

      #HERE IS THE CLUE: HOW DO I APPEND word TO THE CheckListBox OF
      #THE LEFT PANEL, as I do in the OnAdd method of the LeftPanel class

      #This provides a new CheckListBox on top of the previous, and that is
NOT what I want
      LeftPanel(wx.GetApp().GetTopWindow()).clBox.Append(word)
     class LeftPanel(wx.Panel):
  def __init__(self, parent):
      wx.Panel.__init__(self, parent)

      #Initialization
      self.SetBackgroundColour('White')
      self.aList =
      #Boxes
      self.mainBox = wx.BoxSizer(wx.VERTICAL)
      self.clBox = wx.CheckListBox(self, -1, pos=wx.DefaultPosition,\
                                   size=wx.DefaultSize, choices=self.aList,\
                                   style=0, validator=wx.DefaultValidator,\
                                   name='checklistBox')
            #Add box containing textctrl and add button
      self.addBox = wx.BoxSizer(wx.HORIZONTAL)
      self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                       validator=wx.DefaultValidator)
      self.addText.SetMaxLength(12)
      self.addButton = wx.Button(self, -1, 'Add')
      self.addBox.Add(self.addText, 0, wx.ALL, 1)
      self.addBox.Add(self.addButton, 0, wx.ALL, 1)
      self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
            #Adding to mainbox
      self.mainBox.Add(self.clBox, 0, wx.ALL, 1)
      self.mainBox.Add(self.addBox, 0, wx.EXPAND, 0)
      self.mainBox.Fit(self)
      self.SetSizer(self.mainBox)
      self.Layout()

  def OnAdd(self, event):
      word = self.addText.GetValue()
      self.clBox.Append(word)
      self.Layout()

class MainFrame(wx.Frame):
  def __init__(self, parent=None, id=-1, pos=wx.DefaultPosition, \
               title='Program name here'):
      wx.Frame.__init__(self, parent, id, title, pos, (1100, 600))

      #Creating splitter with two panels
      self.initpos = 245
      self.splitter = wx.SplitterWindow(self)
      self.leftPanel = LeftPanel(self.splitter)
      self.rightPanel = RightPanel(self.splitter)
      self.splitter.Initialize(self.leftPanel)
      self.splitter.Initialize(self.rightPanel)
      self.splitter.SplitVertically(self.leftPanel, self.rightPanel,
self.initpos)
      self.leftPanel.Fit()
      self.rightPanel.Fit()
      self.Centre()
      self.Layout()

class App(wx.App):
  def OnInit(self):
      self.frame = MainFrame()
      self.frame.Show()
      self.SetTopWindow(self.frame)
      return True
def main():
  app = App()
  import wx.lib.inspection
  wx.lib.inspection.InspectionTool().Show()
  app.MainLoop()

if __name__ == '__main__':
  main()
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Andy,

Attached is a file that does what you need. The trick was to just
pass a reference to the left panel when you make the call to the
right panel. This way the right panel "knows about" the existence
of the left panel (and not just the class, that exact instantiation of it).
    
Was rushing off to eat and had a weird mental block in which I could
not recall the word "instance" and instead said "instantiation". So
keep in mind, I should have said *that exact instance" of your LeftPanel class.

Really a more preferred way for more involved things would be to
use PubSub, but this is fine for this smaller purpose I think.
    
Also I'll add the reason: because, as written, the code for
RightPanel depends on LeftPanel being there, and in fact having the
clBox in it. If either of those facts change in later versions of your code,
it will break things. Therefore, doing it the way I've shown creates this
problem. See this thread in which others helped me out to understand
these things earlier this year:

http://www.nabble.com/pubsub-necessary-in-this-case--td17976424.html#a17976434

(check out Jurgen's comment from April 10, 2008 at 5:06am particularly for
why pubsub is often a good idea).

Lastly, in your code, I highly suggest making all indents 4 whitespaces.

Che
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
  

I am looking forward to go into your solution in detail!
In my program I think I have full control of both my LeftPanel and my RightPanel

Hm, I am programming in IDLE on Windows with default settings, isnt 4 whitespaces default there? Anyway, my code ran fine here,
I only did a copy - paste into my Thunderbird e-mail program before sending.

/Andy

My IDLE on Windows XP defaults to 4 whitespaces. Thunderbird might be converting them to tabs when you paste into it though.

Mike

···

On Sun, Oct 26, 2008 at 7:20 PM, C M <cmpython@gmail.com> wrote:

On Sun, Oct 26, 2008 at 4:20 PM, andy <postinger@start.no> wrote:

I am reading this via Gmail and in my email screen your code has a mix of
indents. The classes are not indented (good), the def statements have 2
whitespaces (should be 4), the code blocks under the defs have 4 (good),
but the final def has only 1 white space (should be 4). This is part of why
I couldn't get it to run. Not sure what happened.

Che

···

On Mon, Oct 27, 2008 at 3:21 AM, andy <postinger@start.no> wrote:

C M skrev:

On Sun, Oct 26, 2008 at 7:20 PM, C M <cmpython@gmail.com> wrote:

On Sun, Oct 26, 2008 at 4:20 PM, andy <postinger@start.no> wrote:

Thank you Mike Driscoll and C M for answering my previous mail, my
prevous
approach was not good. I have now learnt that sizers are smart!

Still, there is one issue left, and that is related to the access of a
CheckListBox in class LeftPanel from RightPanel. Below is a runnable
sample.
Honestly, I have tried to remove all unnecessary pieces of code... See
my
comment under the OnAdd method in class RightPanel - how do I add a word
to
the CheckListBox in class LeftPanel.

I have not yet looked into the pubsub as suggested by Mike, hopefully
there
are a simpler solution...

import wx
class RightPanel(wx.Panel):
def __init__(self, parent):
     wx.Panel.__init__(self, parent)
     self.SetBackgroundColour('White')
     self.addBox = wx.BoxSizer(wx.HORIZONTAL)
     self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                      validator=wx.DefaultValidator)
     self.addText.SetMaxLength(12)
     self.addButton = wx.Button(self, -1, 'Add')
     self.addBox.Add(self.addText, 0, wx.ALL, 1)
     self.addBox.Add(self.addButton, 0, wx.ALL, 1)
     self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
     self.addBox.Fit(self)
     self.SetSizer(self.addBox)
     self.Layout()

def OnAdd(self, event):
     word = self.addText.GetValue()

     #HERE IS THE CLUE: HOW DO I APPEND word TO THE CheckListBox OF
     #THE LEFT PANEL, as I do in the OnAdd method of the LeftPanel class

     #This provides a new CheckListBox on top of the previous, and that
is
NOT what I want
     LeftPanel(wx.GetApp().GetTopWindow()).clBox.Append(word)
    class LeftPanel(wx.Panel):
def __init__(self, parent):
     wx.Panel.__init__(self, parent)

     #Initialization
     self.SetBackgroundColour('White')
     self.aList =
     #Boxes
     self.mainBox = wx.BoxSizer(wx.VERTICAL)
     self.clBox = wx.CheckListBox(self, -1, pos=wx.DefaultPosition,\
                                  size=wx.DefaultSize,
choices=self.aList,\
                                  style=0,
validator=wx.DefaultValidator,\
                                  name='checklistBox')
           #Add box containing textctrl and add button
     self.addBox = wx.BoxSizer(wx.HORIZONTAL)
     self.addText = wx.TextCtrl(self, -1, value='', size = (125, -1), \
                                      validator=wx.DefaultValidator)
     self.addText.SetMaxLength(12)
     self.addButton = wx.Button(self, -1, 'Add')
     self.addBox.Add(self.addText, 0, wx.ALL, 1)
     self.addBox.Add(self.addButton, 0, wx.ALL, 1)
     self.Bind(wx.EVT_BUTTON, self.OnAdd, self.addButton)
           #Adding to mainbox
     self.mainBox.Add(self.clBox, 0, wx.ALL, 1)
     self.mainBox.Add(self.addBox, 0, wx.EXPAND, 0)
     self.mainBox.Fit(self)
     self.SetSizer(self.mainBox)
     self.Layout()

def OnAdd(self, event):
     word = self.addText.GetValue()
     self.clBox.Append(word)
     self.Layout()

class MainFrame(wx.Frame):
def __init__(self, parent=None, id=-1, pos=wx.DefaultPosition, \
              title='Program name here'):
     wx.Frame.__init__(self, parent, id, title, pos, (1100, 600))

     #Creating splitter with two panels
     self.initpos = 245
     self.splitter = wx.SplitterWindow(self)
     self.leftPanel = LeftPanel(self.splitter)
     self.rightPanel = RightPanel(self.splitter)
     self.splitter.Initialize(self.leftPanel)
     self.splitter.Initialize(self.rightPanel)
     self.splitter.SplitVertically(self.leftPanel, self.rightPanel,
self.initpos)
     self.leftPanel.Fit()
     self.rightPanel.Fit()
     self.Centre()
     self.Layout()

class App(wx.App):
def OnInit(self):
     self.frame = MainFrame()
     self.frame.Show()
     self.SetTopWindow(self.frame)
     return True
def main():
app = App()
import wx.lib.inspection
wx.lib.inspection.InspectionTool().Show()
app.MainLoop()

if __name__ == '__main__':
main()
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Andy,

Attached is a file that does what you need. The trick was to just
pass a reference to the left panel when you make the call to the
right panel. This way the right panel "knows about" the existence
of the left panel (and not just the class, that exact instantiation of
it).

Was rushing off to eat and had a weird mental block in which I could
not recall the word "instance" and instead said "instantiation". So
keep in mind, I should have said *that exact instance" of your LeftPanel
class.

Really a more preferred way for more involved things would be to
use PubSub, but this is fine for this smaller purpose I think.

Also I'll add the reason: because, as written, the code for
RightPanel depends on LeftPanel being there, and in fact having the
clBox in it. If either of those facts change in later versions of your
code,
it will break things. Therefore, doing it the way I've shown creates this
problem. See this thread in which others helped me out to understand
these things earlier this year:

http://www.nabble.com/pubsub-necessary-in-this-case--td17976424.html#a17976434
(check out Jurgen's comment from April 10, 2008 at 5:06am particularly for
why pubsub is often a good idea).

Lastly, in your code, I highly suggest making all indents 4 whitespaces.

Che
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I am looking forward to go into your solution in detail!
In my program I think I have full control of both my LeftPanel and my
RightPanel

Hm, I am programming in IDLE on Windows with default settings, isnt 4
whitespaces default there? Anyway, my code ran fine here,
I only did a copy - paste into my Thunderbird e-mail program before sending.