LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-30-2010, 09:50 AM   #1
Mohtek
Member
 
Registered: Dec 2004
Location: Colorado
Distribution: Kubuntu/Debian/Centos
Posts: 126

Rep: Reputation: 15
Question Trying to learn how to create refactored wx.python


I'm still a newbie, but am determined to figure this out!

I'm starting with menus, but I can easily adapt it to everything else. I just don't see the data structure yet.

Here is my base file:

Code:
#!/usr/bin/evy python
'''create  basic window, with a button, status/menu bar and dialog boxes'''
import wx

class App(wx.App):
    def OnInit(self):
        frame=MyFrame(None,-1,"everything so far")
        frame.Show()
        return True

class MyFrame(wx.Frame):
    def __init__(self,parent,id,name):
        wx.Frame.__init__(self,parent,id,name,size=(300,300))
        panel=wx.Panel(self)
        #panel.setBackgroundColour("White")
        button1=wx.Button(panel,label="Clicky",size=(60,20),pos=(10,10))
        '''create the statusbar and menubar, then add menu items'''
        statusBar=self.CreateStatusBar()
        menuBar=wx.MenuBar()
        menu1=wx.Menu()
        menuBar.Append(menu1,"File")
        menu1.Append(wx.NewId(),"Open","Open a file")
        self.SetMenuBar(menuBar)

if __name__=="__main__":
    app=App()
    app.MainLoop()
What I want to do is refactor the "menu1" items to make it an iterable list.
I am following a book, but the code is wrong, (Cut and paste does not turn out correctly)
I have another file that includes a function that returns a tuple:
[CODE def MenuData():
return ("File",("Open","Open a file"))
[/CODE]
not sure what to do from this point

Thank you,
Ash

Last edited by Mohtek; 05-04-2010 at 07:46 AM.
 
Old 05-01-2010, 07:47 PM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Before I peek at your code, could you please wrap it in CODE tags? Just to preserve formatting, especially since Python is indentation-sensitive.

Thanks!

Oddly enough, wxPython already has two classes to help you achieve this:
MenuItemList and MenuItemList_iterator.

Last edited by indienick; 05-04-2010 at 10:41 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What to learn?.. HuMmMm.. Python? Perl? jhyland87 Programming 20 03-04-2010 02:11 PM
LXer: Looking for Newbies that want to learn Python LXer Syndicated Linux News 0 12-12-2009 02:01 AM
book to learn Python icecubeflower Linux - Newbie 4 03-31-2009 08:18 AM
should I learn Py3k or Python 2.x texasone Programming 5 10-27-2008 01:55 AM
Documents to learn C language and Perl/python satimis Programming 5 03-19-2004 10:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration