#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    44
    Rep Power
    11

    My first 'real' program


    Sorry for posting this... this is the first time i make a program that really looks like a program(well.. not really) so I need a little advice or comment.. there's may be a mistake in the program..please say something so I can make an improvement... this program just convert a number to either CM or INCH( I'm sure about accuracy)... if you put the number on CM box it'll conver to inch and vice versa... comment please.. thanx

    the code

    Code:
    from wxPython.wx import *
    
    class testdialog(wxDialog):
        def __init__(self,parent,ID,title,pos,size):
            id = wxNewId()
            wxDialog.__init__(self,parent,id,title,pos,size)
            panel = self
    	#Label
            wxStaticBox(panel,-1,'Cm Value',(3,3),(120,43))
    	wxStaticBox(panel,-1,'Inch Value',(3,48),(120,43))
    	#Text Entry
            self.cm = wxTextCtrl(panel,-1,'',(14,18))
            self.inch = wxTextCtrl(panel,-1,'',(14,63))
    	#Buttons
            wxButton(panel,10,'Count',(3,100),(120,25))
            wxButton(panel,11,'Clear',(3,125),(120,25))
    
            EVT_BUTTON(self,10,self.Count)
    	EVT_BUTTON(self,11,self.Clear)
    
        def Count(self,event):
            cm = self.cm.GetValue()
            inch = self.inch.GetValue()
    	try :        
                if cm=='' and inch=='':
                    warning = wxMessageDialog(self,'Cannot process empty string','Error',
                                              wxOK|wxICON_INFORMATION)
                    warning.ShowModal()
                    warning.Destroy()
                elif cm !='' and inch!='':
                    warning3 = wxMessageDialog(self,'Enter singe value only','Error',
                                              wxOK|wxICON_INFORMATION)
                    warning3.ShowModal()
                    warning3.Destroy()
                    self.cm.Clear()
                    self.inch.Clear()
                    
                elif inch == '':
                    inch_1 = float(cm)/2.54
                    inch_a = round(inch_1,2)
                    self.inch.WriteText(str(inch_a))
                elif cm == '':
                    cm_1 = float(inch)*2.54
                    cm_a = round(cm_1,2)
                    self.cm.WriteText(str(cm_a))
            except ValueError:
                warning2 = wxMessageDialog(self,'Please enter numerical value(s) only','Error',
                                           wxOK|wxICON_INFORMATION)
                warning2.ShowModal()
                warning2.Destroy()
                self.cm.Clear()
                self.inch.Clear()           
                
    	
        def Clear(self,event):
    	self.cm.Clear()
    	self.inch.Clear()
           	
               
    class okrun(wxApp):
        def OnInit(self):
            return True
    
    app = okrun(0)
    dlg = testdialog(NULL,-1,'MIGHTconv v1(b)',(200,200),(132,180))
    dlg.ShowModal()       
    dlg.Destroy()
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    543
    Rep Power
    24
    Note: In order to use this program, you need Python and wxPython.

    I can't really offer any advice, because I haven't really used wxPython yet.

    Well, lets go through a list of things:

    1. The box was successfully made.
    2. The labels are there.
    3. When I click on 'Count' without any data, I get the correct error message: "Cannot process empty string"
    4. When I click on 'Count' with data in both fields, I get the correct error message: "Enter single value only"
    5. When I enter letters into one of the fields, I get the correct error message: "Please enter numerical value(s) only"
    6. When I click on 'Clear', it deletes all data in both fields.
    7. The correct title is in the title bar.

    So far, everything is working. The only thing that wasn't quite right, was the math. The math was close, though. Maybe your math is right. Hopefully a mathematician can help us out with this one. If your math is wrong, maybe try using the math module.

    Anyways, nice program!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    44
    Rep Power
    11
    My math sucks!!!
  6. #4
  7. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    Pretty good, considering I never achieved anything using wxPython If its docs were as good as Python's... *sighs*

    But, more on topic, your math is OK. 1 inch == 2.54 cm.
    Time is the greatest of teachers ; sadly, it kills all of its students.
    - Hector Berlioz

IMN logo majestic logo threadwatch logo seochat tools logo