Hi all,

I have used some forum browsing and the WxDemo to create my desired GUI and struggling to find some good reference material to add functionality to my design.

This GUI will ideally pull / send information to other programs (in python and/or c) in the future but for now am at least just looking to make the program/all the buttons stable.

I saw that the demos used some sort of self.log to record button actions and was maybe thinking of having a log just record the actions of all the buttons..I've fiddled around with it but to no avail.

Future things I'm looking to do:

How I would go about loading an xml file with the browse button to eventually have the program send the file / pull data from it.

Have the database dropdown read a file to populate the list of available databases

Have one box populated from another (i.e. reading dropdown populated from database selected, or the 'populated from xml' box pull a value from one of the .xml files)

Check boxes choose whether to reprocess just file 1, file 2, or both with the start button

Have the Quit button....quit.


Any input / suggestions appreciated,

Thank you.

import wx
import os





wildcard = "Cfg Files (*.xml)|*.xml|"     \
           "All files (*.*)|*.*"







#initialize / frame

class MyFrame(wx.Frame):
    '''info abot class | Doc string'''
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)

        
        #frame panel
        self.panel = wx.Panel(self)  

        wx.StaticText(self.panel, -1, "utility", (15, 10))
        wx.StaticText(self.panel, -1, "database 1", (15, 150), (75, -1))
        wx.StaticText(self.panel, -1, "reading from db 1:", (15, 200), (75, -1))
	wx.StaticText(self.panel, -1, "populated from reading:", (15, 253), (75, -1))

        sc = wx.SpinCtrl(self.panel, -1, "", (100, 250))
        sc.SetRange(0,999)
        sc.SetValue(1)
        
        cb1 = wx.CheckBox(self.panel, -1, "reprocess file 1", (125,55))
        cb1.SetValue(True)
        cb2 = wx.CheckBox(self.panel, -1, "reprocess file 2", (125, 105))
        cb2.SetValue(True)        





#Run Button
        
        b = wx.Button(self.panel, 10, "start reprocessing", (20, 300))
        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
        b.SetDefault()
        b.SetSize(b.GetBestSize())





#browse / open button for acq config

        b = wx.Button(self.panel, -1, "load xml file 1", (20,50))
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        
        
#browse / open button for pspec config

        b = wx.Button(self.panel, -1, "load xml file 2", (20,100))
        self.Bind(wx.EVT_BUTTON, self.OnButton2, b)
        
        
        




#Quit Button

        b = wx.Button(self.panel, 10, "Quit", (200, 300))
        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
        b.SetDefault()
        b.SetSize(b.GetBestSize())		
        
		
		
		
#Database/Reading Lists & Buttons

        dbList = ['database 1', 'database 2', 'database 3']
        readingList = ['rdg 1', 'rdg 2', 'rdg 3', 'rdg 4']
        self.ch = wx.Choice(self.panel, -1, (100, 150), choices = dbList)
        self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch)
        self.ch = wx.Choice(self.panel, -1, (100, 200), choices = readingList)
        self.Bind(wx.EVT_CHOICE, self.EvtChoice2, self.ch)	
		



#---------------

		
		

		

 
    def EvtChoice(self, event):
        a = event.GetString()      
        self.a = wx.StaticText(self.panel, -1, str(a), pos = (100,175)) 

    def EvtChoice2(self, event):
        a = event.GetString()      
        self.a = wx.StaticText(self.panel, -1, str(a), pos = (100,225)) 
        
        
    def OnClick(self, event):
        self.log.write("Click! (%d)\n" % event.GetId())        
        
        


#---------- def for browse button




    def OnButton(self, event):



        # Finally, if the directory is changed in the process of getting files, this
        # dialog is set up to change the current working directory to the path chosen.
        dlg = wx.FileDialog(
            self, message="Choose a file",
            defaultDir=os.getcwd(), 
            defaultFile="",
            wildcard=wildcard,
            style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
            )

        # Show the dialog and retrieve the user response. If it is the OK response, 
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            paths = dlg.GetPaths()

            self.log.WriteText('You selected %d files:' % len(paths))

            for path in paths:
                self.log.WriteText('           %s\n' % path)

        # Compare this with the debug above; did we change working dirs?
        self.log.WriteText("CWD: %s\n" % os.getcwd())



    def OnButton2(self, event):


        # Create the dialog. In this case the current directory is forced as the starting
        # directory for the dialog, and no default file name is forced. This can easilly
        # be changed in your program. This is an 'open' dialog, and allows multitple
        # file selections as well.
        #
        # Finally, if the directory is changed in the process of getting files, this
        # dialog is set up to change the current working directory to the path chosen.
        dlg = wx.FileDialog(
            self, message="Choose a file",
            defaultDir=os.getcwd(), 
            defaultFile="",
            wildcard=wildcard,
            style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
            )

        # Show the dialog and retrieve the user response. If it is the OK response, 
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            paths = dlg.GetPaths()

            self.log.WriteText('You selected %d files:' % len(paths))

            for path in paths:
                self.log.WriteText('           %s\n' % path)

        # Compare this with the debug above; did we change working dirs?
        self.log.WriteText("CWD: %s\n" % os.getcwd())







#----------------------




if __name__ == "__main__":
    app = wx.App()   
    mytitle = 'reproc'  
    width = 500
    height = 375
    MyFrame(None, mytitle, (width, height)).Show()
    app.MainLoop()

This site has lots of good resources :)

I have used for my quit button, although only the program closes...the stdout window stays open for some reason.

#Quit Button

        b = wx.Button(self.panel, 10, "Quit", (200, 300))
        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
        b.SetDefault()
        b.SetSize(b.GetBestSize())

.
.
.

def OnQuitButton(self, evt):
        # event handler for the Quit button click or Exit menu item
        print "See you later alligator! (goes to stdout window)"
        wx.Sleep(1)    # 1 second to look at message
        self.Close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.