Problem with wxSplitterWindow

Hi, I just discovered this GUI dev tool and so far I
like it better than TCL/TK. However, I am having a
problem with the wxSplitterWindow class

I typed in a simple program that I found on IBM's web
site
http://www-106.ibm.com/developerworks/library/l-wxpy/listing2.html

It splits a window into two text editors, but it will
not run this line one line

splitter =wxSplitterWindow (self, -1,
style=wxNO_3D|wxSP_3D)

I get "nameerror: name 'self' not defined"
I don't see how self cannot be defined.
I looked at the docs but that didn't provide any
inspiration. I did change self to parent, but no help
there.

I looked at the demo code, but it does it differently
than in this program. It creates a class derived from
wxSplitterWindow class instead of calling it
directly(?), but calling it directly should work
shouldn't it?

Is there a typo in the program example that I am
missing?
Thanks
Daryl

···

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

It is most likely an indentation problem. Did you by chance paste this
code into the interactive interpreter? The indentation rules are a
little different in that environment (I don't believe you are allowed to
have blank lines within indentation blocks)

The first thing I would check is that the splitter = etc. line is at the
same indentation level as the stuff above it.

-Mark

···

On Wed, 2003-07-23 at 18:02, Daryl G wrote:

I typed in a simple program that I found on IBM's web
site
IBM Developer

It splits a window into two text editors, but it will
not run this line one line

splitter =wxSplitterWindow (self, -1,
style=wxNO_3D|wxSP_3D)

I get "nameerror: name 'self' not defined"
I don't see how self cannot be defined.
I looked at the docs but that didn't provide any
inspiration. I did change self to parent, but no help
there.

Daryl G wrote:

Hi, I just discovered this GUI dev tool and so far I
like it better than TCL/TK. However, I am having a
problem with the wxSplitterWindow class

I typed in a simple program that I found on IBM's web
site
IBM Developer

It splits a window into two text editors, but it will
not run this line one line

splitter =wxSplitterWindow (self, -1,
style=wxNO_3D|wxSP_3D)

I get "nameerror: name 'self' not defined"
I don't see how self cannot be defined.
I looked at the docs but that didn't provide any
inspiration. I did change self to parent, but no help
there.

I looked at the demo code, but it does it differently
than in this program. It creates a class derived from
wxSplitterWindow class instead of calling it
directly(?), but calling it directly should work
shouldn't it?

Is there a typo in the program example that I am
missing?

There are several. There are a couple indent problems, and they left out several menu item texts...

I've attached a fixed version. You will also probably want to read through http://wiki.wxpython.org/

ibmex.py (10.6 KB)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

ARghh! yes it was idention. I've only been bit by that
multiple times before. Thought I checked that.

Thanks!

> I typed in a simple program that I found on IBM's
web
> site
>

···

--- "Roach, Mark R." <mrroach@cimplify.net> wrote:

On Wed, 2003-07-23 at 18:02, Daryl G wrote:
>
> It splits a window into two text editors, but it
will
> not run this line one line
>
> splitter =wxSplitterWindow (self, -1,
> style=wxNO_3D|wxSP_3D)
>
> I get "nameerror: name 'self' not defined"
> I don't see how self cannot be defined.
> I looked at the docs but that didn't provide any
> inspiration. I did change self to parent, but no
help
> there.

It is most likely an indentation problem. Did you by
chance paste this
code into the interactive interpreter? The
indentation rules are a
little different in that environment (I don't
believe you are allowed to
have blank lines within indentation blocks)

The first thing I would check is that the splitter =
etc. line is at the
same indentation level as the stuff above it.

-Mark

---------------------------------------------------------------------

To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwindows.org

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

yes, I discovered the menu text items.
Looks like it was just an idention error on my part in
this case. ARrgh. I'll just go and kill myself now

Thanks for the fixed file

Daryl G wrote:
> Hi, I just discovered this GUI dev tool and so far
I
> like it better than TCL/TK. However, I am having a
> problem with the wxSplitterWindow class
>
> I typed in a simple program that I found on IBM's
web
> site
>

>
> It splits a window into two text editors, but it
will
> not run this line one line
>
> splitter =wxSplitterWindow (self, -1,
> style=wxNO_3D|wxSP_3D)
>
> I get "nameerror: name 'self' not defined"
> I don't see how self cannot be defined.
> I looked at the docs but that didn't provide any
> inspiration. I did change self to parent, but no
help
> there.
>
> I looked at the demo code, but it does it
differently
> than in this program. It creates a class derived
from
> wxSplitterWindow class instead of calling it
> directly(?), but calling it directly should work
> shouldn't it?
>
> Is there a typo in the program example that I am
> missing?

There are several. There are a couple indent
problems, and they left
out several menu item texts...

I've attached a fixed version. You will also
probably want to read
through http://wiki.wxpython.org/

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax
with wxPython!

> #!/bin/python
import sys, os
from wxPython.wx import *
from string import *

# Process the command line. Not much to do;
# just get the name of the project file if it's
given. Simple.
projfile = 'Unnamed'
if len(sys.argv) > 1:
   projfile = sys.argv[1]

def MsgBox (window, string):
    dlg=wxMessageDialog(window, string, 'wxProject',
wxOK)
    dlg.ShowModal()
    dlg.Destroy()

class main_window(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, -1, title,
size = (500, 500),
                        

style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)

···

--- Robin Dunn <robin@alldunn.com> wrote:

        #

------------------------------------------------------------------------------------

        # Set up menu bar for the program.
        #

------------------------------------------------------------------------------------

        self.mainmenu = wxMenuBar() # Create menu
bar.
        mainwindow = self

        menu=wxMenu()
# Make a menu (will be the Project menu)

        exitID=wxNewId()
# Make a new ID for a menu entry.
        menu.Append(exitID, '&Open', 'Open project')
# Name the ID by adding it to the menu.
        EVT_MENU(self, exitID, self.OnProjectOpen)
# Create and assign a menu event.
        exitID=wxNewId()
        menu.Append(exitID, '&New', 'New project')
        EVT_MENU(self, exitID, self.OnProjectNew)
        exitID=wxNewId()
        menu.Append(exitID, 'E&xit', 'Exit program')
        EVT_MENU(self, exitID, self.OnProjectExit)

        self.mainmenu.Append (menu, '&File') #
Add the project menu to the menu bar.

        menu=wxMenu()
# Make a menu (will be the File menu)

        exitID=wxNewId()
        menu.Append(exitID, '&Add', 'Add file to
project')
        EVT_MENU(self, exitID, self.OnFileAdd)
        exitID=wxNewId()
        menu.Append(exitID, '&Remove', 'Remove file
from project')
        EVT_MENU(self, exitID, self.OnFileRemove)
        exitID=wxNewId()
        menu.Append(exitID, '&Open', 'Open file for
editing')
        EVT_MENU(self, exitID, self.OnFileOpen)
        exitID=wxNewId()
        menu.Append(exitID, '&Save', 'Save file')
        EVT_MENU(self, exitID, self.OnFileSave)

        self.mainmenu.Append (menu, '&Project')
    # Add the file menu to the menu bar.

        self.SetMenuBar (self.mainmenu)
# Attach the menu bar to the window.

        #

------------------------------------------------------------------------------------

        # Create the splitter window.
        #

------------------------------------------------------------------------------------

        splitter = wxSplitterWindow (self, -1,
style=wxNO_3D|wxSP_3D)
        splitter.SetMinimumPaneSize (1)

        #

------------------------------------------------------------------------------------

        # Create the tree on the left.
        #

------------------------------------------------------------------------------------

        tID = wxNewId()
        self.tree = wxTreeCtrl (splitter, tID,
style=wxTR_HAS_BUTTONS |
                                   wxTR_EDIT_LABELS
>
                                  
wxTR_HAS_VARIABLE_ROW_HEIGHT)
        EVT_TREE_BEGIN_LABEL_EDIT(self.tree, tID,
self.OnTreeLabelEdit)
        EVT_TREE_END_LABEL_EDIT(self.tree, tID,
self.OnTreeLabelEditEnd)
        EVT_TREE_ITEM_ACTIVATED(self.tree, tID,
self.OnTreeItemActivated)

        #

------------------------------------------------------------------------------------

        # Create the editor on the right.
        #

------------------------------------------------------------------------------------

        self.editor = wxTextCtrl(splitter, -1,
style=wxTE_MULTILINE)
        self.editor.Enable (0)

        #

------------------------------------------------------------------------------------

        # Install the tree and the editor.
        #

------------------------------------------------------------------------------------

        splitter.SplitVertically (self.tree,
self.editor, 180)

        self.Show(true)

        # Some global state variables.
        self.projectdirty = false

    #

----------------------------------------------------------------------------------------

    # Some nice little handlers.
    #

----------------------------------------------------------------------------------------

    def project_open(self, project_file):
        try:
            input = open (project_file, 'r')

            self.tree.DeleteAllItems()

            self.project_file = project_file
            name = replace (input.readline(), "\n",
"")
            self.SetTitle (name)
            self.root = self.tree.AddRoot(name)
            self.activeitem = self.root
            for line in input.readlines():
                self.tree.AppendItem (self.root,
replace(line, "\n", ""))
            input.close
            self.tree.Expand (self.root)

            self.editor.Clear()
            self.editor.Enable (false)

            self.projectdirty = false
        except IOError:
            pass

    def project_save(self):
        try:
            output = open (self.project_file, 'w+')
            output.write (self.tree.GetItemText
(self.root) + "\n")

            count = self.tree.GetChildrenCount
(self.root)
            iter = 0
            child = ''
            for i in range(count):
               if i == 0:
                  (child,iter) =
self.tree.GetFirstChild(self.root,iter)
               else:
                  (child,iter) =
self.tree.GetNextChild(self.root,iter)
               output.write
(self.tree.GetItemText(child) + "\n")
            output.close()
            self.projectdirty = false
        except IOError:
            dlg_m = wxMessageDialog (self, 'There
was an error saving the project file.',
      'Error!', wxOK)
            dlg_m.ShowModal()
            dlg_m.Destroy()

    #

----------------------------------------------------------------------------------------

    # Event handlers from here on out.
    #

----------------------------------------------------------------------------------------

    def OnProjectOpen(self, event):
        open_it = true
        if self.projectdirty:

=== message truncated ===>
---------------------------------------------------------------------

To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail:

wxPython-users-help@lists.wxwindows.org

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com