473,503 Members | 7,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OO names/references from perspective of code

true911m
92 New Member
This gets to the core of my most frustrating lack of understanding at the moment, and now I have an example to illustrate it. It may get long-winded, but I'm trying to figure out how to describe it somewhat briefly.

I'm using Boa to reconstruct a simple VB app I'm familiar with, so some of the generated naming should be familiar.

My app has two windows. The first opens to ask for user information. Fill it in, and press a button for generated password results, which pop up in a second window.

As I understand it, in code:

Filename is App1.py
Class is BoaApp
Instance of BoaApp is 'application'
application creates first window:
Expand|Select|Wrap|Line Numbers
  1. class BoaApp(wx.App):
  2.     def OnInit(self):
  3.         wx.InitAllImageHandlers()
  4.         self.main = Frame1.create(None)        
  5.         self.main.Show()
  6.         self.SetTopWindow(self.main)
  7.         return True
Now, the user fills in info and presses btnGenerate, an event in Frame1.py (now instantiated as 'main')

My btnGenerate handler (inside Frame1) hides the input window, and creates the 'results' window:
Expand|Select|Wrap|Line Numbers
  1. def OnBtnGenerateButton(self, event):
  2.         self.Hide()
  3.         results = Frame2.create(None)
  4.         results.Show()
The results window has another button, btnAnother, to allow the user to go back and enter info for another user.

I know what I want to do at this point. I want to hide 'results', show 'main', and destroy 'results' (because 'main' creates a new 'results' each time its button is pressed).

What I can't figure out, from the perspective of the event handler in 'results', is how to reference the name of the hidden Frame1/'main' window to tell it to Show().

My understanding of the hierarchy of the instantiated classes would have me use 'application.main.Show()', based on the names of the instantiated classes, but that doesn't work; nor do dozens of combinations of "self, App1, main, BoaApp, results, parent" or any other pertinent labels I can come up with in my desperation.

I thought I understood the conceptual hierarchy of OO, but I'm either missing something really basic, or my practical interpretation is flawed, or both/worse.

I hope this is enough description to understand exactly what is my point of misunderstanding here. I've been hesitating posting because I didn't want to start a very long back-and-forth of answers not pertaining to a problem I haven't described well enough.

Thanks for reading.
Dec 13 '06 #1
3 1176
bartonc
6,596 Recognized Expert Expert
This gets to the core of my most frustrating lack of understanding at the moment, and now I have an example to illustrate it. It may get long-winded, but I'm trying to figure out how to describe it somewhat briefly.

I'm using Boa to reconstruct a simple VB app I'm familiar with, so some of the generated naming should be familiar.

My app has two windows. The first opens to ask for user information. Fill it in, and press a button for generated password results, which pop up in a second window.

As I understand it, in code:

Filename is App1.py
Class is BoaApp
Instance of BoaApp is 'application'
application creates first window:
Expand|Select|Wrap|Line Numbers
  1. class BoaApp(wx.App):
  2.     def OnInit(self):
  3.         wx.InitAllImageHandlers()
  4.         self.main = Frame1.create(None)        
  5.         self.main.Show()
  6.         self.SetTopWindow(self.main)
  7.         return True
Now, the user fills in info and presses btnGenerate, an event in Frame1.py (now instantiated as 'main')

My btnGenerate handler (inside Frame1) hides the input window, and creates the 'results' window:
Expand|Select|Wrap|Line Numbers
  1. def OnBtnGenerateButton(self, event):
  2.         self.Hide()
  3.         results = Frame2.create(None)
  4.         results.Show()
The results window has another button, btnAnother, to allow the user to go back and enter info for another user.

I know what I want to do at this point. I want to hide 'results', show 'main', and destroy 'results' (because 'main' creates a new 'results' each time its button is pressed).

What I can't figure out, from the perspective of the event handler in 'results', is how to reference the name of the hidden Frame1/'main' window to tell it to Show().

My understanding of the hierarchy of the instantiated classes would have me use 'application.main.Show()', based on the names of the instantiated classes, but that doesn't work; nor do dozens of combinations of "self, App1, main, BoaApp, results, parent" or any other pertinent labels I can come up with in my desperation.

I thought I understood the conceptual hierarchy of OO, but I'm either missing something really basic, or my practical interpretation is flawed, or both/worse.

I hope this is enough description to understand exactly what is my point of misunderstanding here. I've been hesitating posting because I didn't want to start a very long back-and-forth of answers not pertaining to a problem I haven't described well enough.

Thanks for reading.
This is (roughly) how I do this:

In main
Expand|Select|Wrap|Line Numbers
  1. def __init__(self, prnt):
  2.     self.results = None
  3.  
  4. def OnBtnGenerateButton(self, event):
  5.     if self.results is None:   # update the value of self.results
  6.         self.results = Frame2.create(self)   # give Frame2 a link back to the creator
  7.     else:
  8.         self.results.InitWidgets()   # main created it ONLY main should destroy it
  9.     self.results.Show()
In Frame2
Expand|Select|Wrap|Line Numbers
  1. def __init__(self, prnt):
  2.     self.parent = prnt  # keep the link back for later
  3.  
  4. def InitWidgets(self):
  5.     pass    # put widgets in some initialized state
  6.  
  7. def OnDoneButton(self):    # the event handler
  8.     self.Hide()
  9.     self.parent.Show()
Dec 14 '06 #2
true911m
92 New Member
This is (roughly) how I do this:

In main
[code]
def __init__(self, prnt):
self.results = None
...
I played around with this a little and got my multi windows working. I see what I was doing wrong, is that where I created the frame with 'None', that is the place where you're passing the parent's identity, so use 'self' instead. Then inside the created instance, store 'parent' while in the init method for later use.

I also left the window alive instead of destroying it each time; this lets the users move it around, and it stays where they left it when it pops up again.

I didn't see a real need for the Widgets.init each time I reopened, partly because of that last paragraph. Maybe it makes sense when things get more complex -- not there yet.
Dec 15 '06 #3
bartonc
6,596 Recognized Expert Expert
I played around with this a little and got my multi windows working. I see what I was doing wrong, is that where I created the frame with 'None', that is the place where you're passing the parent's identity, so use 'self' instead. Then inside the created instance, store 'parent' while in the init method for later use.

I also left the window alive instead of destroying it each time; this lets the users move it around, and it stays where they left it when it pops up again.

I didn't see a real need for the Widgets.init each time I reopened, partly because of that last paragraph. Maybe it makes sense when things get more complex -- not there yet.
Yep. Sounds like you've got a handle on it now.
I threw in the initWidgets in case you were destroying it in order to re-create it with constructor values.
Dec 15 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1810
by: Ron_Adam | last post by:
Hi, Sometimes it just helps to see what's going on, so I've been trying to write a tool to examine what names are pointing to what objects in the current scope. This still has some glitches,...
7
1415
by: Daniel | last post by:
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string?
22
2208
by: BRIAN VICKERY | last post by:
I've heard that some compilers reserve the '_' starting a symbol for system variables/symbols. I can not find this documented anywhere (so far). I've used an '_' at the end of member variables...
1
1579
by: Neil Zanella | last post by:
Hello, Consider the following PostgreSQL or Oracle SQL DDL code: CREATE TABLE fooTable ( foo INTEGER, PRIMARY KEY (foo) ); CREATE TABLE barTable (
3
5398
by: Shailesh Humbad | last post by:
I want to set a command-line argument for a Windows service that I programmed in VB.Net. This ought to be available from the service installer classes, but I can not find any such property. What...
20
27729
by: Shawnk | last post by:
I would like to get the class INSTANCE name (not type name) of an 'object'. I can get the object (l_obj_ref.GetType()) and then get the (l_obj_typ.Name) for the class name. I there any way of...
2
2572
by: MLH | last post by:
I have a tab control named TabCtl210. It has 3 tabs. named Page211, Page212 and Page213. Each of those 3 tab-pages has a textbox control named Page1HomeSpot, Page2HomeSpot and Page3HomeSpot...
28
2150
by: Stef Mientki | last post by:
hello, I'm trying to build a simple functional simulator for JAL (a Pascal-like language for PICs). My first action is to translate the JAL code into Python code. The reason for this approach is...
2
360
by: subramanian100in | last post by:
From http://groups.google.com/group/comp.lang.c++/browse_frm/thread/d5da6e5e37fd194d/6e2e8424a1cfbd2b#6e2e8424a1cfbd2b the following portion is taken. "Mike Wahler"...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.