Learning GUI programming & OOP

I'm a noob when it comes to classes and inheritance and I'm looking
for a good example-based tutorial to learn from.

I've written a wxpython GUI application using notebook tabs which is
now full of global statements and I'd like to learn how to properly
use classes and objects to pass data around.

Any suggestions most welcome.

Jonno.

Hi Jonno,

···

On Fri, Jan 13, 2012 at 10:07 PM, Jonno jonnojohnson@gmail.com wrote:

I’m a noob when it comes to classes and inheritance and I’m looking

for a good example-based tutorial to learn from.

I’ve written a wxpython GUI application using notebook tabs which is

now full of global statements and I’d like to learn how to properly

use classes and objects to pass data around.

Any suggestions most welcome.

Jonno.

Welcome to the wxPython world and our user list. I would recommend http://zetcode.com/wxpython/ and the wxPython wiki. The wiki isn’t very organized, but there’s lots of good stuff in it. The zetcode website is pretty good for an overview. I also have a bunch of articles on my blog about wxPython and other Python stuff. Between that stuff and the mailing list, I think you’ll find everything you need. There are also two wxPython books that you can acquire that are both good.


Mike Driscoll

Blog: http://blog.pythonlibrary.org

Thanks Mike,

I've been using the wxPython wiki quite a bit and in fact it's how I
got started using the notepads.
However I'm still looking for some guidance how to properly handle
data without having to resort to globals.
Here is my example:
In my current code I have 2 notepad tabs/pages which means that all
the buttons, text entries etc are defined in 2 different classes
(wx.Panels). I also define a number of functions within those 2
classes which do things like fetch data and process it.
I need certain data that I'm operating on to be accessible from both
notepad panels. How should I handle this with classes/objects?

···

On Fri, Jan 13, 2012 at 10:21 PM, Mike Driscoll <mike@pythonlibrary.org> wrote:

Hi Jonno,

On Fri, Jan 13, 2012 at 10:07 PM, Jonno <jonnojohnson@gmail.com> wrote:

I'm a noob when it comes to classes and inheritance and I'm looking
for a good example-based tutorial to learn from.

I've written a wxpython GUI application using notebook tabs which is
now full of global statements and I'd like to learn how to properly
use classes and objects to pass data around.

Any suggestions most welcome.

Jonno.

Welcome to the wxPython world and our user list. I would recommend
wxPython tutorial - Python GUI programming in wxPython and the wxPython wiki. The wiki isn't very
organized, but there's lots of good stuff in it. The zetcode website is
pretty good for an overview. I also have a bunch of articles on my blog
about wxPython and other Python stuff. Between that stuff and the mailing
list, I think you'll find everything you need. There are also two wxPython
books that you can acquire that are both good.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

A good general rule is very like that for good functional programming:
    "If you are about to copy and paste more than 2 lines of code then
consider abstracting instead"
So if you have just a couple of basic data fetch methods then start with
a couple of base classes that do things like fetch/set and build up from
there the nice thing with OOP is the possibility of having derived
classes the override some methods.

To answer your last bit there are a couple of ways of doing this but
possibly the best is to have a separate data object that is owned by the
parent level and handles the data initialisation, access, etc., and your
panels can access this via a parent.dataobject references.

Gadget/Steve

···

On 14/01/2012 4:48 AM, Jonno wrote:

Thanks Mike,

I've been using the wxPython wiki quite a bit and in fact it's how I
got started using the notepads.
However I'm still looking for some guidance how to properly handle
data without having to resort to globals.
Here is my example:
In my current code I have 2 notepad tabs/pages which means that all
the buttons, text entries etc are defined in 2 different classes
(wx.Panels). I also define a number of functions within those 2
classes which do things like fetch data and process it.
I need certain data that I'm operating on to be accessible from both
notepad panels. How should I handle this with classes/objects?

Google is your friend. Try searching for "OOP tutorial python". This is one of the results that looks like what you are looking for, a short simple introduction to the basic concepts: http://www.voidspace.org.uk/python/articles/OOP.shtml

Here is one where somebody asked a similar question and the answers he got: http://stackoverflow.com/questions/3332454/oop-python-oriented-tutorials

This is an online book that I encouraged my boys to read: How to Think Like a Computer Scientist — How to Think Like a Computer Scientist: Learning with Python 2nd Edition documentation The chapters on OOP related things are pretty good.

···

On 1/13/12 8:07 PM, Jonno wrote:

I'm a noob when it comes to classes and inheritance and I'm looking
for a good example-based tutorial to learn from.

I've written a wxpython GUI application using notebook tabs which is
now full of global statements and I'd like to learn how to properly
use classes and objects to pass data around.

Any suggestions most welcome.

--
Robin Dunn
Software Craftsman

Thanks Robin,

At a brief glance I like the voidspace article. Trust me I've been
googling OOP and Python but for some reason I never found something
simple and clear like that.

···

On 1/14/12, Robin Dunn <robin@alldunn.com> wrote:

On 1/13/12 8:07 PM, Jonno wrote:

I'm a noob when it comes to classes and inheritance and I'm looking
for a good example-based tutorial to learn from.

I've written a wxpython GUI application using notebook tabs which is
now full of global statements and I'd like to learn how to properly
use classes and objects to pass data around.

Any suggestions most welcome.

Google is your friend. Try searching for "OOP tutorial python". This is
one of the results that looks like what you are looking for, a short
simple introduction to the basic concepts:
http://www.voidspace.org.uk/python/articles/OOP.shtml

Here is one where somebody asked a similar question and the answers he
got:
http://stackoverflow.com/questions/3332454/oop-python-oriented-tutorials

This is an online book that I encouraged my boys to read:
How to Think Like a Computer Scientist — How to Think Like a Computer Scientist: Learning with Python 2nd Edition documentation The chapters on
OOP related things are pretty good.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Sent from my mobile device

Steve,

This morning while driving I came to that conclusion. The only thing
I'm not sure about is that I won't know the size of an array when I
create the data object in the parent.

···

On 1/14/12, Gadget/Steve <GadgetSteve@live.co.uk> wrote:

On 14/01/2012 4:48 AM, Jonno wrote:

Thanks Mike,

I've been using the wxPython wiki quite a bit and in fact it's how I
got started using the notepads.
However I'm still looking for some guidance how to properly handle
data without having to resort to globals.
Here is my example:
In my current code I have 2 notepad tabs/pages which means that all
the buttons, text entries etc are defined in 2 different classes
(wx.Panels). I also define a number of functions within those 2
classes which do things like fetch data and process it.
I need certain data that I'm operating on to be accessible from both
notepad panels. How should I handle this with classes/objects?

A good general rule is very like that for good functional programming:
    "If you are about to copy and paste more than 2 lines of code then
consider abstracting instead"
So if you have just a couple of basic data fetch methods then start with
a couple of base classes that do things like fetch/set and build up from
there the nice thing with OOP is the possibility of having derived
classes the override some methods.

To answer your last bit there are a couple of ways of doing this but
possibly the best is to have a separate data object that is owned by the
parent level and handles the data initialisation, access, etc., and your
panels can access this via a parent.dataobject references.

Gadget/Steve

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Sent from my mobile device

Luckily enough since you are programming in python that is not a
problem, you can either create it as an empty array and append to it
when you do know, create it as an object of type None initially and then
create it as an array when you know the size or assuming it is currently
created by one of the child frames during it's initialisation you can
still create it in the same place but as a member of the parent. If you
do either of the first two then you need to make sure that the methods
that access it can cope with the possibility that they might be called
before the array is populated.

If it is not naturally a resizeable array then you can probably also
move the method that determines the size of the array to the parent as well.

You might also like to take a look at some of the discussions in this
newsgroup, the python newsgroup, and several others about the benefits
of separation of the user interface from the data and methods, while it
seems like an obtuse subject at times it is actually very good practice,
[blasphemy warning] allows for the possibility that you may have to use
a different user interface model, e.g. command line, QT, gtk, etc., at
some time in the future if necessary because of customer or other
requirements [end blasphemy], gives a clear separation between the data,
the processing and the user interface and will often result in a better
design.

Sorry to be preaching this early on a Sunday morning, (thinking about it
what better time), but I have found that the benefits are enormous from
following these principles. To give you an example the current
Python/wxPython based project that I am working on has multiple user
interfaces, (32), as multiple uses of the code but 95% of the code is
common across the applications, there are 296 source files totalling 2.5
Megabytes but less than 60 import wx and several of those only do so to
provide unit test interfaces.

The other nice point that often arises late in a project is when they
say something along the lines of "Very nice GUI but we now need the main
processing to run in a background/batch/scheduled/remote task and just
control it from/get the results via the GUI" if the code and data are
tightly bound together this is a major task if they are not it is
usually (almost) trivial.

Gadget/Steve

···

On 15/01/2012 2:27 AM, Jonno wrote:

Steve,

This morning while driving I came to that conclusion. The only thing
I'm not sure about is that I won't know the size of an array when I
create the data object in the parent.

Werner and I created the MediaLocker project to show one way to separate out the Model-View-Controller paradigm for wxPython users. We use pubsub a lot too. You can check it out here: http://www.medialocker.pythonlibrary.org/

···

On Sun, Jan 15, 2012 at 3:49 AM, Gadget/Steve GadgetSteve@live.co.uk wrote:

On 15/01/2012 2:27 AM, Jonno wrote:

Steve,

This morning while driving I came to that conclusion. The only thing

I’m not sure about is that I won’t know the size of an array when I

create the data object in the parent.

Luckily enough since you are programming in python that is not a

problem, you can either create it as an empty array and append to it

when you do know, create it as an object of type None initially and then

create it as an array when you know the size or assuming it is currently

created by one of the child frames during it’s initialisation you can

still create it in the same place but as a member of the parent. If you

do either of the first two then you need to make sure that the methods

that access it can cope with the possibility that they might be called

before the array is populated.

If it is not naturally a resizeable array then you can probably also

move the method that determines the size of the array to the parent as well.

You might also like to take a look at some of the discussions in this

newsgroup, the python newsgroup, and several others about the benefits

of separation of the user interface from the data and methods, while it

seems like an obtuse subject at times it is actually very good practice,

[blasphemy warning] allows for the possibility that you may have to use

a different user interface model, e.g. command line, QT, gtk, etc., at

some time in the future if necessary because of customer or other

requirements [end blasphemy], gives a clear separation between the data,

the processing and the user interface and will often result in a better

design.

Sorry to be preaching this early on a Sunday morning, (thinking about it

what better time), but I have found that the benefits are enormous from

following these principles. To give you an example the current

Python/wxPython based project that I am working on has multiple user

interfaces, (32), as multiple uses of the code but 95% of the code is

common across the applications, there are 296 source files totalling 2.5

Megabytes but less than 60 import wx and several of those only do so to

provide unit test interfaces.

The other nice point that often arises late in a project is when they

say something along the lines of "Very nice GUI but we now need the main

processing to run in a background/batch/scheduled/remote task and just

control it from/get the results via the GUI" if the code and data are

tightly bound together this is a major task if they are not it is

usually (almost) trivial.

Gadget/Steve

Mike Driscoll

Blog: http://blog.pythonlibrary.org

I’ve been able to get my list boxes to use a horizontal scrollbar when the containing window is too small, but once the window gets really small (relative to the width of the list box’s content), the scrollbar disappears, and the list box expands out to full width, pushing everything else to the right.

I do not get this behaviour with wxListCtrl, and at the moment I believe this to be a bug in wxListBox, although obviously it’s possible I’m doing something wrong.

A longer explanation, along with screenshots and a code sample, can be found here: http://stackoverflow.com/questions/8812957/when-its-containing-panel-or-frame-becomes-too-small-wxlistbox-stops-using-its

Any answers you can provide here or on Stack Overflow would be much appreciated.

Cheers,

Cam

Cameron Jackson
Engineering Intern
Air Operations

Thales Australia
Thales Australia Centre, WTC Northbank Wharf, Concourse Level,
Siddeley Street, Melbourne, VIC 3005, Australia
Tel: +61 3 8630 4591
cameron.jackson@thalesgroup.com.au | www.thalesgroup.com.au

···

DISCLAIMER: This e-mail transmission and any documents, files and previous e-mail messages attached to it are private and confidential. They may contain proprietary or copyright material or information that is subject to legal professional privilege. They are for the use of the intended recipient only. Any unauthorised viewing, use, disclosure, copying, alteration, storage or distribution of, or reliance on, this message is strictly prohibited. No part may be reproduced, adapted or transmitted without the written permission of the owner. If you have received this transmission in error, or are not an authorised recipient, please immediately notify the sender by return email, delete this message and all copies from your e-mail system, and destroy any printed copies. Receipt by anyone other than the intended recipient should not be deemed a waiver of any privilege or protection. Thales Australia does not warrant or represent that this e-mail or any documents, files and previous e-mail messages attached are error or virus free. -------------------------------------------------------------------------

Ok so to start simply I want to open a file and assign some data in it to an object. I’m opening the file from the file menu which is defined during init of the main app frame.
Here is my data class definition:
class Data(MyFrame):
def init(self, var1, var2):
MyFrame.init(self)
self.var1 = var1
self.var2 = var2

Here is the start of the main frame class definition and the line I’m using to instantiate an instance of the Data class:
class MyFrame(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, id, title)
def OnOpen(self,event):
# skip code to open file and assign var1,var2
self.Data(var1,var2)

And here is the line to create the instance of MyFrame:
frame = MyFrame(none, wx.ID_ANY, ‘App Name’)

I’m getting: MyFrame object has no instance of attribute Data when the line self.Data(var1,var2) is called. What am I doing wrong?

···

On Sun, Jan 15, 2012 at 5:22 PM, Mike Driscoll mike@pythonlibrary.org wrote:

On Sun, Jan 15, 2012 at 3:49 AM, Gadget/Steve GadgetSteve@live.co.uk > wrote:

On 15/01/2012 2:27 AM, Jonno wrote:

Steve,

This morning while driving I came to that conclusion. The only thing
I’m not sure about is that I won’t know the size of an array when I
create the data object in the parent.

Luckily enough since you are programming in python that is not a
problem, you can either create it as an empty array and append to it
when you do know, create it as an object of type None initially and then
create it as an array when you know the size or assuming it is currently
created by one of the child frames during it’s initialisation you can
still create it in the same place but as a member of the parent. If you
do either of the first two then you need to make sure that the methods
that access it can cope with the possibility that they might be called
before the array is populated.

If it is not naturally a resizeable array then you can probably also
move the method that determines the size of the array to the parent as
well.

You might also like to take a look at some of the discussions in this
newsgroup, the python newsgroup, and several others about the benefits
of separation of the user interface from the data and methods, while it
seems like an obtuse subject at times it is actually very good practice,
[blasphemy warning] allows for the possibility that you may have to use
a different user interface model, e.g. command line, QT, gtk, etc., at
some time in the future if necessary because of customer or other
requirements [end blasphemy], gives a clear separation between the data,
the processing and the user interface and will often result in a better
design.

Sorry to be preaching this early on a Sunday morning, (thinking about it
what better time), but I have found that the benefits are enormous from
following these principles. To give you an example the current
Python/wxPython based project that I am working on has multiple user
interfaces, (32), as multiple uses of the code but 95% of the code is
common across the applications, there are 296 source files totalling 2.5
Megabytes but less than 60 import wx and several of those only do so to
provide unit test interfaces.

The other nice point that often arises late in a project is when they
say something along the lines of “Very nice GUI but we now need the main
processing to run in a background/batch/scheduled/remote task and just
control it from/get the results via the GUI” if the code and data are
tightly bound together this is a major task if they are not it is
usually (almost) trivial.

Gadget/Steve

Werner and I created the MediaLocker project to show one way to separate out
the Model-View-Controller paradigm for wxPython users. We use pubsub a lot
too. You can check it out here: http://www.medialocker.pythonlibrary.org/

Figured it out! Syntax error in my code.

···

On Fri, Jan 20, 2012 at 3:49 PM, Jonno jonnojohnson@gmail.com wrote:

On Sun, Jan 15, 2012 at 5:22 PM, Mike Driscoll mike@pythonlibrary.org wrote:

On Sun, Jan 15, 2012 at 3:49 AM, Gadget/Steve GadgetSteve@live.co.uk > > > > wrote:

On 15/01/2012 2:27 AM, Jonno wrote:

Steve,

This morning while driving I came to that conclusion. The only thing
I’m not sure about is that I won’t know the size of an array when I

create the data object in the parent.

Luckily enough since you are programming in python that is not a
problem, you can either create it as an empty array and append to it

when you do know, create it as an object of type None initially and then
create it as an array when you know the size or assuming it is currently
created by one of the child frames during it’s initialisation you can

still create it in the same place but as a member of the parent. If you
do either of the first two then you need to make sure that the methods
that access it can cope with the possibility that they might be called

before the array is populated.

If it is not naturally a resizeable array then you can probably also
move the method that determines the size of the array to the parent as
well.

You might also like to take a look at some of the discussions in this
newsgroup, the python newsgroup, and several others about the benefits
of separation of the user interface from the data and methods, while it

seems like an obtuse subject at times it is actually very good practice,
[blasphemy warning] allows for the possibility that you may have to use
a different user interface model, e.g. command line, QT, gtk, etc., at

some time in the future if necessary because of customer or other
requirements [end blasphemy], gives a clear separation between the data,
the processing and the user interface and will often result in a better

design.

Sorry to be preaching this early on a Sunday morning, (thinking about it
what better time), but I have found that the benefits are enormous from
following these principles. To give you an example the current

Python/wxPython based project that I am working on has multiple user
interfaces, (32), as multiple uses of the code but 95% of the code is
common across the applications, there are 296 source files totalling 2.5

Megabytes but less than 60 import wx and several of those only do so to
provide unit test interfaces.

The other nice point that often arises late in a project is when they

say something along the lines of "Very nice GUI but we now need the main

processing to run in a background/batch/scheduled/remote task and just
control it from/get the results via the GUI" if the code and data are
tightly bound together this is a major task if they are not it is

usually (almost) trivial.

Gadget/Steve

Werner and I created the MediaLocker project to show one way to separate out
the Model-View-Controller paradigm for wxPython users. We use pubsub a lot

too. You can check it out here: http://www.medialocker.pythonlibrary.org/

Ok so to start simply I want to open a file and assign some data in it to an object. I’m opening the file from the file menu which is defined during init of the main app frame.
Here is my data class definition:
class Data(MyFrame):
def init(self, var1, var2):
MyFrame.init(self)
self.var1 = var1
self.var2 = var2

Here is the start of the main frame class definition and the line I’m using to instantiate an instance of the Data class:
class MyFrame(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, id, title)
def OnOpen(self,event):
# skip code to open file and assign var1,var2
self.Data(var1,var2)

And here is the line to create the instance of MyFrame:
frame = MyFrame(none, wx.ID_ANY, ‘App Name’)

I’m getting: MyFrame object has no instance of attribute Data when the line self.Data(var1,var2) is called. What am I doing wrong?

So my next question is:

If I create an object containing a set of data each time I open a file, how do I keep track of these objects? Do I need to assign them a unique name somehow?

···

On Fri, Jan 20, 2012 at 9:33 PM, Jonno jonnojohnson@gmail.com wrote:

On Fri, Jan 20, 2012 at 3:49 PM, Jonno jonnojohnson@gmail.com wrote:

On Sun, Jan 15, 2012 at 5:22 PM, Mike Driscoll mike@pythonlibrary.org wrote:

On Sun, Jan 15, 2012 at 3:49 AM, Gadget/Steve GadgetSteve@live.co.uk > > > > > > > > > wrote:

On 15/01/2012 2:27 AM, Jonno wrote:

Steve,

This morning while driving I came to that conclusion. The only thing
I’m not sure about is that I won’t know the size of an array when I

create the data object in the parent.

Luckily enough since you are programming in python that is not a
problem, you can either create it as an empty array and append to it

when you do know, create it as an object of type None initially and then
create it as an array when you know the size or assuming it is currently
created by one of the child frames during it’s initialisation you can

still create it in the same place but as a member of the parent. If you
do either of the first two then you need to make sure that the methods
that access it can cope with the possibility that they might be called

before the array is populated.

If it is not naturally a resizeable array then you can probably also
move the method that determines the size of the array to the parent as
well.

You might also like to take a look at some of the discussions in this
newsgroup, the python newsgroup, and several others about the benefits
of separation of the user interface from the data and methods, while it

seems like an obtuse subject at times it is actually very good practice,
[blasphemy warning] allows for the possibility that you may have to use
a different user interface model, e.g. command line, QT, gtk, etc., at

some time in the future if necessary because of customer or other
requirements [end blasphemy], gives a clear separation between the data,
the processing and the user interface and will often result in a better

design.

Sorry to be preaching this early on a Sunday morning, (thinking about it
what better time), but I have found that the benefits are enormous from
following these principles. To give you an example the current

Python/wxPython based project that I am working on has multiple user
interfaces, (32), as multiple uses of the code but 95% of the code is
common across the applications, there are 296 source files totalling 2.5

Megabytes but less than 60 import wx and several of those only do so to
provide unit test interfaces.

The other nice point that often arises late in a project is when they

say something along the lines of "Very nice GUI but we now need the main

processing to run in a background/batch/scheduled/remote task and just
control it from/get the results via the GUI" if the code and data are
tightly bound together this is a major task if they are not it is

usually (almost) trivial.

Gadget/Steve

Werner and I created the MediaLocker project to show one way to separate out
the Model-View-Controller paradigm for wxPython users. We use pubsub a lot

too. You can check it out here: http://www.medialocker.pythonlibrary.org/

Ok so to start simply I want to open a file and assign some data in it to an object. I’m opening the file from the file menu which is defined during init of the main app frame.
Here is my data class definition:
class Data(MyFrame):
def init(self, var1, var2):
MyFrame.init(self)
self.var1 = var1
self.var2 = var2

Here is the start of the main frame class definition and the line I’m using to instantiate an instance of the Data class:
class MyFrame(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, id, title)
def OnOpen(self,event):
# skip code to open file and assign var1,var2
self.Data(var1,var2)

And here is the line to create the instance of MyFrame:
frame = MyFrame(none, wx.ID_ANY, ‘App Name’)

I’m getting: MyFrame object has no instance of attribute Data when the line self.Data(var1,var2) is called. What am I doing wrong?

Figured it out! Syntax error in my code.

That depends if you need to:

  1. Keep and use data from multiple files at once
  2. Keep the data and the source of that data separate
    If the answer to the first question is no then you just replace
    your data each time you read a file, if the first is yes and the
    second is no then you can just add to the data each time a file is
    read, e.g. by having a data list if the answer to both questions
    was yes then you will need to have a data object for each file
    read/loaded the keeps track of which data is from which file, one
    way of doing this would be to have a data class that holds the
    data you are concerned about and the file name that it came from
    you can then have a list of such objects, another way would be to
    have a dictionary of data objects with the file name as the key.
    If you are dealing with very large amounts of data, (potentially
    more than would fit in the available memory then consider using a
    database to store it in and then your methods would consist of
    read the file, validate the data and store it in the database and
    methods to access and manipulate the data from that database. It
    is also worth taking a look at the Virtual List control,
    UltimateListCtrl and the Data View Control, (DVC_*), samples in
    the demo. The good news is that the python methods for dealing
    with sets of data, (lists and dictionary’s of items or of
    objects), mean that you do not have to worry too much about unique
    identifiers.

Hope that is some help.

Gadget/Steve

···

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

Thanks Steve,

I actually have a couple of sources of data, one is from opening files, the other is transferring data directly from another application.

I do need to keep all the data objects separate.

I will need to limit the total number of data objects to a pretty small number (something like 4-8).

I had played around with both the list idea and dictionary ideas last night but I was struggling a bit with how to keep track of things. Since I only want to have a limited number of objects open at one time perhaps I can have a class variable for the data object class which keeps track of the objects?

···

On Sat, Jan 21, 2012 at 1:48 AM, Gadget/Steve GadgetSteve@live.co.uk wrote:

On 21/01/2012 4:15 AM, Jonno wrote:

On Fri, Jan 20, 2012 at 9:33 PM, Jonno jonnojohnson@gmail.com > > wrote:

            On Fri, Jan 20, 2012 at 3:49 PM, > > > Jonno <jonnojohnson@gmail.com> > > >                 wrote:
                  On Sun, Jan 15, 2012 at 5:22 PM, Mike Driscoll > > > > <mike@pythonlibrary.org                      > > > > > wrote:

                  >

                  >

                  > On Sun, Jan 15, 2012 at 3:49 AM, Gadget/Steve > > > > <GadgetSteve@live.co.uk> > > > >  > > > >                       > wrote:

                  >>

                  >> On 15/01/2012 2:27 AM, Jonno wrote:

                  >> > Steve,

                  >> >

                  >> > This morning while driving I came to

that conclusion. The only thing

                  >> > I'm not sure about is that I won't

know the size of an array when I

                  >> > create the data object in the

parent.

                  >> >

                  >> >

                  >> Luckily enough since you are programming

in python that is not a

                  >> problem, you can either create it as an

empty array and append to it

                  >> when you do know, create it as an object

of type None initially and then

                  >> create it as an array when you know the

size or assuming it is currently

                  >> created by one of the child frames during

it’s initialisation you can

                  >> still create it in the same place but as

a member of the parent. If you

                  >> do either of the first two then you need

to make sure that the methods

                  >> that access it can cope with the

possibility that they might be called

                  >> before the array is populated.

                  >>

                  >> If it is not naturally a resizeable array

then you can probably also

                  >> move the method that determines the size

of the array to the parent as

                  >> well.

                  >>

                  >> You might also like to take a look at

some of the discussions in this

                  >> newsgroup, the python newsgroup, and

several others about the benefits

                  >> of separation of the user interface from

the data and methods, while it

                  >> seems like an obtuse subject at times it

is actually very good practice,

                  >> [blasphemy warning] allows for the

possibility that you may have to use

                  >> a different user interface model, e.g.

command line, QT, gtk, etc., at

                  >> some time in the future if necessary

because of customer or other

                  >> requirements [end blasphemy], gives a

clear separation between the data,

                  >> the processing and the user interface and

will often result in a better

                  >> design.

                  >>

                  >> Sorry to be preaching this early on a

Sunday morning, (thinking about it

                  >> what better time), but I have found that

the benefits are enormous from

                  >> following these principles.  To give you

an example the current

                  >> Python/wxPython based project that I am

working on has multiple user

                  >> interfaces, (32), as multiple uses of the

code but 95% of the code is

                  >> common across the applications, there are

296 source files totalling 2.5

                  >> Megabytes but less than 60 import wx and

several of those only do so to

                  >> provide unit test interfaces.

                  >>

                  >> The other nice point that often arises

late in a project is when they

                  >> say something along the lines of "Very

nice GUI but we now need the main

                  >> processing to run in a

background/batch/scheduled/remote task and just

                  >> control it from/get the results via the

GUI" if the code and data are

                  >> tightly bound together this is a major

task if they are not it is

                  >> usually (almost) trivial.

                  >>

                  >> Gadget/Steve

                  >>

                  >>

                  >

                  > Werner and I created the MediaLocker project

to show one way to separate out

                  > the Model-View-Controller paradigm for

wxPython users. We use pubsub a lot

                  > too. You can check it out here: [http://www.medialocker.pythonlibrary.org/](http://www.medialocker.pythonlibrary.org/)

                  >

                  > --

                  > -----------------
              Ok so to start simply I want to open a file and assign

some data in it to an object. I’m opening the file
from the file menu which is defined during init of
the main app frame.

              Here is my data class definition:

              *class Data(MyFrame):
                     def __init__(self, var1, var2):
                         MyFrame.__init__(self)
                         self.var1 = var1
                         self.var2 = var2*

              Here is the start of the main frame class definition

and the line I’m using to instantiate an instance of
the Data class:

              *class MyFrame(wx.Frame):
                     def __init__(self, parent, id, title):
                         wx.Frame.__init__(self, parent, id, title)

                    def OnOpen(self,event):
                        # skip code to open file and assign

var1,var2
self.Data(var1,var2)*

              And here is the line to create the instance of

MyFrame:

              *                      frame = MyFrame(none,

wx.ID_ANY, ‘App Name’)*

                I'm getting: MyFrame object has no instance of

attribute Data when the line self.Data(var1,var2) is
called. What am I doing wrong?

Figured it out! Syntax error in my code.

So my next question is:

    If I create an object containing a set of data each time I

open a file, how do I keep track of these objects? Do I need to
assign them a unique name somehow?

  To unsubscribe, send email to

wxPython-users+unsubscribe@googlegroups.com

  or visit [http://groups.google.com/group/wxPython-users?hl=en](http://groups.google.com/group/wxPython-users?hl=en)

That depends if you need to:

  1. Keep and use data from multiple files at once
  2. Keep the data and the source of that data separate
    If the answer to the first question is no then you just replace
    your data each time you read a file, if the first is yes and the
    second is no then you can just add to the data each time a file is
    read, e.g. by having a data list if the answer to both questions
    was yes then you will need to have a data object for each file
    read/loaded the keeps track of which data is from which file, one
    way of doing this would be to have a data class that holds the
    data you are concerned about and the file name that it came from
    you can then have a list of such objects, another way would be to
    have a dictionary of data objects with the file name as the key.
    If you are dealing with very large amounts of data, (potentially
    more than would fit in the available memory then consider using a
    database to store it in and then your methods would consist of
    read the file, validate the data and store it in the database and
    methods to access and manipulate the data from that database. It
    is also worth taking a look at the Virtual List control,
    UltimateListCtrl and the Data View Control, (DVC_*), samples in
    the demo. The good news is that the python methods for dealing
    with sets of data, (lists and dictionary’s of items or of
    objects), mean that you do not have to worry too much about unique
    identifiers.

Hope that is some help.

Gadget/Steve

So my next question is:

If I create an object containing a set of data each time I open a file, how do I keep track of these objects? Do I need to assign them a unique name somehow?

For use of this list, I’d recommend:

  • Trim the email you are responding to, keeping only the relevant parts of the ongoing thread. This makes things easier to follow, cleaner, etc.

  • If you have a new question, post it as a new thread; don’t start new questions in an old thread. Also, give that thread a subject line that is informative and specific, such as, “How to store data in an UltimateListCtrl?” . This helps with the archive and finding helpful info via Google, etc.

  • Lastly, your questions are really Python questions, not wxPython ones (though Gadget/Steve’s points about the controls which can contain data does bring it back to wxPython a fair bit). For Python questions, the Python Google groups list or the Python Tutor List are good. Questions here are supposed to be about getting widgets to work. (Though, yes, occasionally things veer into pure Python territory).

Che

Apologies Che. I find that queries often drift from one area to another. I appreciate all the help though.

···

On Sat, Jan 21, 2012 at 9:15 AM, C M cmpython@gmail.com wrote:

For use of this list, I’d recommend:

  • Trim the email you are responding to, keeping only the relevant parts of the ongoing thread. This makes things easier to follow, cleaner, etc.

  • If you have a new question, post it as a new thread; don’t start new questions in an old thread. Also, give that thread a subject line that is informative and specific, such as, “How to store data in an UltimateListCtrl?” . This helps with the archive and finding helpful info via Google, etc.

  • Lastly, your questions are really Python questions, not wxPython ones (though Gadget/Steve’s points about the controls which can contain data does bring it back to wxPython a fair bit). For Python questions, the Python Google groups list or the Python Tutor List are good. Questions here are supposed to be about getting widgets to work. (Though, yes, occasionally things veer into pure Python territory).

Che

Looks like Jonno wants to make a donation for nice
SCSI HDz :wink:

···

On Sat, 21 Jan 2012 10:15:22 -0500 C M <cmpython@gmail.com> wrote:

--
Can I have an IMPULSE ITEM instead?

I suspect it has more to do with how the wx.FlexGridSizer is honoring the best size of the listctrl's. When it can no longer show the full size for at least one of them using the proportions specified it is switching over to giving precedence to the best size for the first one, or something like that.

BTW, switching it to a horizontal wx.BoxSizer allows your sample to work the way I think you are expecting it to work.

···

On 1/15/12 4:23 PM, Jackson, Cameron wrote:

I've been able to get my list boxes to use a horizontal scrollbar when
the containing window is too small, but once the window gets *really*
small (relative to the width of the list box's content), the scrollbar
disappears, and the list box expands out to full width, pushing
everything else to the right.

I do not get this behaviour with wxListCtrl, and at the moment I believe
this to be a bug in wxListBox, although obviously it's possible I'm
doing something wrong.

A longer explanation, along with screenshots and a code sample, can be
found here:
python - When its containing panel or frame becomes too small, wxListBox stops using its horizontal scrollbar and expands to take up too much space - Stack Overflow

Any answers you can provide here or on Stack Overflow would be much
appreciated.

--
Robin Dunn
Software Craftsman