ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
There is less than 2 hours left to vote in the 2015 LinuxQuestions.org Members Choice Awards. Click here to go to the polls. Vote now and make sure your voice is heard!
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Hi, I'm messing about with Python/wxPython, and I have a few questions. Firstly, as Python was named after Monty Python's Flying Circus, then why doesn't it use a circus tent for it's main logo, rather than a snake? (The documentation even states it was not named after a snake)...
Anyway the main question is this... I have a very basic wxPython app, which loads a window with a textbox, menubar and statusbar. How would I go about adding some script to allow python to run a command line argument, THEN display the results of the argument in the textbox? My code is as follows:
wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = ( 200,100),
self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A StatusBar in the bottom of the window
# Setting up the menu.
filemenu.Append(ID_OPEN, "&Open..."," Open a Python app to edit")
filemenu.Append(ID_SAVE, "&Save..."," Save the current document")
filemenu.Append(ID_SAVEAS, "&Save As..."," Save the current document as...")
filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
aboutmenu.Append(ID_ABOUT, "&About"," Information about this program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event ID_ABOUT to the
# method self.OnAbout
wx.EVT_MENU(self, ID_EXIT, self.OnExit) # attach the menu-event ID_EXIT to the
# method self.OnExit
wx.EVT_MENU(self, ID_OPEN, self.OnOpen)
d= wx.MessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor", wx.OK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.
self.Close(True) # Close the frame.
""" Open a file"""
self.dirname = ''
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "Sample Editor", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
I would of course need to add another textbox above for the command line argument itself, followed by a button to 'action' the argument, but basically I'm building a GUI frontend for an app I coded...
Originally posted by arpanet1969
Firstly, as Python was named after Monty Python's Flying Circus, then why doesn't it use a circus tent for it's main logo, rather than a snake? (The documentation even states it was not named after a snake)...
Don't ask me, I don't care :-)
How would I go about adding some script to allow python to run a command line argument, THEN display the results of the argument in the textbox? My code is as follows:
Here's a working example:
from wxPython.wx import *
def __init__(self, parent, title, size):
wxFrame.__init__(self, parent, wxID_ANY, title, wxDefaultPosition, size)
# Create controls
commandBoxID = wxNewId()
outputBoxID = wxNewId()
self.commandBox = wxTextCtrl(self, commandBoxID, style=wxTE_PROCESS_ENTER)
self.outputBox = wxTextCtrl(self, outputBoxID, style=wxTE_MULTILINE|wxHSCROLL)
# Basic control layout
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(self.commandBox, 1, wxEXPAND | wxALL, 10)
sizer.Add(self.outputBox, 6, wxEXPAND | wxALL | wxTE_READONLY, 10)
# Make command-box resond to ENTER:
EVT_TEXT_ENTER(self, commandBoxID, self.OnEnter)
def OnEnter(self, e):
shellCommand = e.GetString()
# Execute the command, getting output through a pipe: popen()
pipe = os.popen(shellCommand)
line = pipe.readline()
if not line:
print "Commmand exit code was:", pipe.close()
app = wxPySimpleApp()
MainWindow(None, "Command Box", (480, 320))
Yes, documentation for wxPython is a little terse, but rather complete though. The only other tutorialish thing that I know of is the demo that ships with wxPython. The code is viewable from the demo itself, and the demo shows how to use all controls with commented code.
Just play a lot with wxPython. And make sure your know enough about python itself (which does have many tutorials). After playing with modifying demo code, try to read the real doc's, which may be a little difficult as it's C++ documentation for wxWidgets, with some wxPython specific notes.
Have a lot of fun. I started Python/wxPython about 6 weeks ago, and I like it very much!
Thanks very much for your reply. The code you offered works perfectly! I'm reading more and more, just working out how to use some kinda config file for my app now, so the configuration panel can be used to save the user's preferances to a file, which can then be re-loaded back into the app at runtime. I'm using the open() and split() functions at the mo.
Originally posted by arpanet1969
I'm reading more and more, just working out how to use some kinda config file for my app now, so the configuration panel can be used to save the user's preferances to a file, which can then be re-loaded back into the app at runtime. I'm using the open() and split() functions at the mo.
Have a look overhere.
(note that the object also has a write() method)