Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 7th, 2004, 05:12 PM
Slinky Puppet Slinky Puppet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 4 Slinky Puppet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
wxPython:Automatic generation of menu

I am currently working on my first GUI, using wxPython, and would like to implement an idea but I'm not sure how to proceed.

In addition to the basic functions of the GUI I have a number of little scripts in a subdirectory that do some simple tasks. The idea is that users can add any new scripts to the directory and then run them from the GUI. To do this the GUI needs to automatically build a menu and then associate each entry with running the script in question. I can easily build the menu but I haven't a clue how to then run the scripts. Can anyone help or is this not a practical idea?

Reply With Quote
  #2  
Old November 8th, 2004, 09:10 AM
Slinky Puppet Slinky Puppet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 4 Slinky Puppet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
solved

It's OK. Problem solved.

Reply With Quote
  #3  
Old November 8th, 2004, 11:11 AM
MBirchmeier's Avatar
MBirchmeier MBirchmeier is offline
I <3 ASCII
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Wishing i was still at... The Ohio State University
Posts: 2,268 MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 h 33 m 29 sec
Reputation Power: 838
Send a message via AIM to MBirchmeier Send a message via Yahoo to MBirchmeier
How was it solved?

(It might be solved for you but it's always nice to post how you got it done incase someone with the same question searches for the same thing)

-MBirchmeier
__________________
My blog on programming related things. Hopefully I won't bog it down with details on my life

Apparently even computers have freudian slips.

0x4279 7465 204D 6521

Reply With Quote
  #4  
Old November 8th, 2004, 01:26 PM
Slinky Puppet Slinky Puppet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 4 Slinky Puppet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Run a loop through the list of macros which generates a new ID for each macro, creates the menu entry, binds it to an event/function then adds the macro name to a dictionary with the ID as a key.

Code:
self.MacroDict= {} 

menu5 = wxMenu()	
for macro in self.MacroList:
     ID = wxNewId()  
     menu5.Append(ID,macro) 
     self.Bind(wx.EVT_MENU, self.OnExecuteMacro,id=ID) 
     self.MacroDict[ID]= macro 		
menubar.Append(menu5,"UserMacros")


The function then extracts the ID of the event that triggered it and uses that to obtain the macro name from the dictionary and passes it to the command line.

Code:
def OnExecuteMacro(self, event):
     eID = event.GetId()
     MacroName = os.path.join(self.UserMacroDirectory,self.MacroDict[eID])
     os.system('python '+MacroName)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > wxPython:Automatic generation of menu


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT