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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old February 22nd, 2004, 07:24 AM
flixxer flixxer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 44 flixxer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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()

Reply With Quote
  #2  
Old February 23rd, 2004, 10:07 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
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!

Reply With Quote
  #3  
Old February 24th, 2004, 03:35 AM
flixxer flixxer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 44 flixxer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
My math sucks!!!

Reply With Quote
  #4  
Old February 24th, 2004, 10:31 AM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 7 m 43 sec
Reputation Power: 5
Send a message via ICQ to SolarBear Send a message via MSN to SolarBear
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > My first 'real' program


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 6 hosted by Hostway