0 Members and 3 Guests are viewing this topic.
import wximport mathclass MainFrame(wx.Frame): def __init__(self, parent,id): wx.Frame.__init__(self, parent,id, 'Formulum', size=(415,135)) panel=wx.Panel(self) ChooseFormulaButtonImage=wx.Image("chooseformulabutton.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap() self.ChooseFormulaButton=wx.BitmapButton(panel, -1, ChooseFormulaButtonImage, pos=(10,10)) self.Bind(wx.EVT_BUTTON, self.ChooseFormula, self.ChooseFormulaButton) AboutButtonImage=wx.Image("aboutbutton.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap() self.AboutButton=wx.BitmapButton(panel, -1, AboutButtonImage, pos=(200,10)) self.Bind(wx.EVT_BUTTON, self.About, self.AboutButton) ExitButtonImage=wx.Image("exitbutton.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap() self.ExitButton=wx.BitmapButton(panel, -1, ExitButtonImage, pos=(200,50)) self.Bind(wx.EVT_BUTTON, self.Close, self.ExitButton) HelpButtonImage=wx.Image("helpbutton.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap() self.HelpButton=wx.BitmapButton(panel, -1, HelpButtonImage, pos=(10,50)) self.Bind(wx.EVT_BUTTON, self.Help, self.HelpButton) def ChooseFormula(self, event): ChoiceBox=wx.SingleChoiceDialog(None, "Which formula do you want to use?", "Formulum", ['Circle Area', 'Square Area', 'Rectangle Area', 'Parallelogram Area', 'Trapezium Area', 'Cube Surface Area', 'Spherical Surface Area', 'Sphere Volume', 'Cylinder Volume', 'Quadrangular Prism Volume','Cone Volume', 'Cube Surface Area', 'Parallelepiped Volume', 'Parallelepiped Surface Area','Quadrangular Pyramid Volume', 'Quadrangular Pyramid Surface Area']) if ChoiceBox.ShowModal()==wx.ID_OK: Answer=ChoiceBox.GetStringSelection() if Answer == "Circle Area": RadiumInput=wx.TextEntryDialog(None, "Enter the radium:", 'Circle Area', 'Enter radium...') if RadiumInput.ShowModal()==wx.ID_OK: Radium=float(RadiumInput.GetValue()) circlearea=(Radium**2)*math.pi box = wx.MessageDialog(None, "The area of the circle which radium is " + str(Radium)+ " is:\n\n " + str(circlearea), 'Circle Area', wx.OK) varanswer1 = box.ShowModal() box.Destroy() if Answer == "Square Area": SideInput=wx.TextEntryDialog(None, "Enter the side:", 'Square Area', 'Enter side...') if SideInput.ShowModal()==wx.ID_OK: Side=float(SideInput.GetValue()) squarearea=Side*Side box = wx.MessageDialog(None, "The area of the square which side is " + str(Side)+ " is:\n\n " + str(squarearea), 'Square Area', wx.OK) varanswer2 = box.ShowModal() box.Destroy() if Answer == "Rectangle Area": LengthInput=wx.TextEntryDialog(None, "Enter the length: ", 'Rectangle Area', 'Enter lenth...') WidthInput=wx.TextEntryDialog(None, "Enter the width: ", 'Rectangle Area', 'Enter width...') if LengthInput.ShowModal()==wx.ID_OK and WidthInput.ShowModal()==wx.ID_OK: Length=float(LengthInput.GetValue()) Width=float(WidthInput.GetValue()) rectanglearea= Length * Width box = wx.MessageDialog(None, "The area of the rectangle is:\n\n " + str(rectanglearea), 'Rectangle Area', wx.OK) varanswer3 = box.ShowModal() box.Destroy() if Answer == "Parallelogram Area": BaseInput=wx.TextEntryDialog(None, "Enter the length of the base: ", 'Parallelogram Area', 'Enter base lenght...') HeightInput=wx.TextEntryDialog(None, "Enter the height: ", 'Parallelogram Area', 'Enter height...') if BaseInput.ShowModal()==wx.ID_OK and HeightInput.ShowModal()==wx.ID_OK: Base = float(BaseInput.GetValue()) Height=float(HeightInput.GetValue()) parallelogramarea = Base * Height box = wx.MessageDialog(None, "The area of the parallelogram is:\n\n " + str(parallelogramarea), 'Parallelogram Area', wx.OK) varanswer4 = box.ShowModal() box.Destroy() if Answer=="Trapezium Area": LargerBaseInput=wx.TextEntryDialog(None, "Enter the length of the larger base:", 'Trapezium Area', 'Enter length...') SmallerBaseInput=wx.TextEntryDialog(None, "Enter the length of the smaller base:", 'Trapezium Area', 'Enter length...') HeightInput=wx.TextEntryDialog(None, "Enter the height:", 'Trapezium Area', 'Enter heigth...') if LargerBaseInput.ShowModal()==wx.ID_OK and SmallerBaseInput.ShowModal()==wx.ID_OK and HeightInput.ShowModal()==wx.ID_OK: LargerBase=float(LargerBaseInput.GetValue()) SmallerBase=float(SmallerBaseInput.GetValue()) Height=float(HeightInput.GetValue()) trapeziumarea = ((LargerBase + SmallerBase) / 2) * Height box = wx.MessageDialog(None, "The area of the trapezium is:\n\n " + str(trapeziumarea), 'Trapezium Area', wx.OK) varanswer5 = box.ShowModal() box.Destroy() if Answer == "Spherical Surface Area": RadiumInput=wx.TextEntryDialog(None, "Enter the radium:", 'Spherical Surface Area', 'Enter radium...') if RadiumInput.ShowModal()==wx.ID_OK: Radium=float(RadiumInput.GetValue()) sphericalsurfacearea = (4 * math.pi * (Radium ** 2)) box = wx.MessageDialog(None, "The spherical surface area is:\n\n " + str(sphericalsurfacearea), 'Spherical Surface Area', wx.OK) varanswer6 = box.ShowModal() box.Destroy() if Answer == "Sphere Volume": RadiumInput=wx.TextEntryDialog(None, "Enter the radium:", 'Sphere Volume', 'Enter radium...') if RadiumInput.ShowModal()==wx.ID_OK: Radium=float(RadiumInput.GetValue()) spherevolume= 4 * math.pi * (Radium) ** 3/3 box = wx.MessageDialog(None, "The volume of the sphere is:\n\n " + str(spherevolume), 'Sphere Volume', wx.OK) varanswer7 = box.ShowModal() box.Destroy() if Answer=="Cylinder Volume": RadiumInput=wx.TextEntryDialog(None, "Enter the radium:", 'Cylinder Volume', 'Enter radium...') HeightInput=wx.TextEntryDialog(None, "Enter the height:", 'Cylinder Volume', 'Enter height...') if RadiumInput.ShowModal()==wx.ID_OK and HeightInput.ShowModal()==wx.ID_OK: Radium=float(RadiumInput.GetValue()) Height=float(HeightInput.GetValue()) cylindervolume = ((math.pi * (Radium ** 2)) * Height) box = wx.MessageDialog(None, "The cylinder volume is:\n\n " + str(cylindervolume), 'Cylinder Volume', wx.OK) varanswer7 = box.ShowModal() box.Destroy() if Answer=="Quadrangular Prism Volume": SideOfBaseInput=wx.TextEntryDialog(None, "Enter the side of base: ", 'Quadrangular Prism Volume', 'Enter side of base...') HeightInput=wx.TextEntryDialog(None, "Enter the height: ", 'Quandrangular Prism Volume', 'Enter height...') if HeightInput.ShowModal()==wx.ID_OK and SideOfBaseInput.ShowModal()==wx.ID_OK: SideOfBase=float(SideOfBaseInput.GetValue()) Height=float(HeightInput.GetValue()) quadrangularprismvolume = (SideOfBase**2)*Height box = wx.MessageDialog(None, "The quadrangular prism volume is:\n\n " + str(quadrangularprismvolume), 'Quadrangular Prism Volume', wx.OK) varanswer8 = box.ShowModal() box.Destroy() if Answer=="Cone Volume": RadiumInput=wx.TextEntryDialog(None, "Enter the radium:", 'Cylinder Volume', 'Enter radium...') HeightInput=wx.TextEntryDialog(None, "Enter the height:", 'Cylinder Volume', 'Enter height...') if RadiumInput.ShowModal()==wx.ID_OK and HeightInput.ShowModal()==wx.ID_OK: Radium=float(RadiumInput.GetValue()) Height=float(HeightInput.GetValue()) conevolume = (((math.pi * (Radium ** 2)) * Height) / 3) box = wx.MessageDialog(None, "The cone volume is:\n\n " + str(conevolume), 'Cone Volume', wx.OK) varanswer9 = box.ShowModal() box.Destroy() if Answer=="Cube Volume": EdgeInput=wx.TextEntryDialog(None, "Enter the edge:", 'Cube Volume', 'Enter edge...') if EdgeInput.ShowModal()==wx.ID_OK: Edge=float(EdgeInput.GetValue()) cubevolume = Edge**3 box = wx.MessageDialog(None, "The cube volume is:\n\n " + str(cubevolume), 'Cube Volume', wx.OK) varanswer10 = box.ShowModal() box.Destroy() if Answer=="Cube Surface Area": EdgeInput=wx.TextEntryDialog(None, "Enter the edge:", 'Cube Surface Area', 'Enter edge...') if EdgeInput.ShowModal()==wx.ID_OK: Edge=float(EdgeInput.GetValue()) cubesurfacearea = 6 * (Edge**2) box = wx.MessageDialog(None, "The cube surface area is:\n\n " + str(cubesurfacearea), 'Cube Surface Area', wx.OK) varanswer11 = box.ShowModal() box.Destroy() if Answer=="Parallelepiped Volume": LengthInput=wx.TextEntryDialog(None, "Enter the length:", 'Cube Volume', 'Enter length...') WidthInput=wx.TextEntryDialog(None, "Enter the width:", 'Cube Volume', 'Enter width...') HeightInput=wx.TextEntryDialog(None, "Enter the height:", 'Cube Volume', 'Enter heigth...') if LengthInput.ShowModal()==wx.ID_OK and WidthInput.ShowModal()==wx.ID_OK and HeightInput.ShowModal()==wx.ID_OK: Length=float(LengthInput.GetValue()) Width=float(WidthInput.GetValue()) Height=float(HeightInput.GetValue()) parallelepipedvolume = Length*Width*Height box = wx.MessageDialog(None, "The Parallelepiped Volume is:\n\n " + str(parallelepipedvolume), 'Parallelepiped Volume', wx.OK) varanswer12 = box.ShowModal() box.Destroy() if Answer=="Parallelepiped Surface Area": LengthInput=wx.TextEntryDialog(None, "Enter the length:", 'Parallelepiped Surface Area', 'Enter length...') WidthInput=wx.TextEntryDialog(None, "Enter the width:", 'Parallelepiped Surface Area', 'Enter width...') HeightInput=wx.TextEntryDialog(None, "Enter the height:", 'Parallelepiped Surface Area', 'Enter heigth...') if LengthInput.ShowModal()==wx.ID_OK and WidthInput.ShowModal()==wx.ID_OK and HeightInput.ShowModal()==wx.ID_OK: Length=float(LengthInput.GetValue()) Width=float(WidthInput.GetValue()) Height=float(HeightInput.GetValue()) parallelepipedsurfacearea = ((Length + Width + Length + Width)*Height) + ((Length*Width)*2) box = wx.MessageDialog(None, "The parallelepiped surface area is:\n\n " + str(parallelepipedsurfacearea), 'Parallelepiped Surface Area', wx.OK) varanswer13 = box.ShowModal() box.Destroy() if Answer=="Quadrangular Pyramid Volume": SideOfBaseInput=wx.TextEntryDialog(None, "Enter the side of base:", 'Quadrangular Pyramid Volume', 'Enter side of base...') HeightInput=wx.TextEntryDialog(None, "Enter the height:", 'Quadrangular Pyramid Volume', 'Enter height...') if SideOfBaseInput.ShowModal()==wx.ID_OK and HeightInput.ShowModal()==wx.ID_OK: SideOfBase=float(SideOfBaseInput.GetValue()) Height=float(HeightInput.GetValue()) quadrangularpyramidvolume = ((SideOfBase ** 2) * Height) / 3 box = wx.MessageDialog(None, "The Quadrangular Pyramid Volume is:\n\n " + str(quadrangularpyramidvolume), 'Quadrangular Pyramid Volume', wx.OK) varanswer14 = box.ShowModal() box.Destroy() if Answer=="Quadrangular Pyramid Surface Area": SideOfBaseInput=wx.TextEntryDialog(None, "Enter the side of base:", 'Quadrangular Pyramid Surface Area', 'Enter side of base...') HeightInput=wx.TextEntryDialog(None, "Enter the height:", 'Quadrangular Pyramid Surface Area', 'Enter height...') if SideOfBaseInput.ShowModal()==wx.ID_OK and HeightInput.ShowModal()==wx.ID_OK: SideOfBase=float(SideOfBaseInput.GetValue()) Height=float(HeightInput.GetValue()) quadrangularpyramidsurfacearea = (SideOfBase*4*Height) * (2 *(SideOfBase**2)) box = wx.MessageDialog(None, "The Quadrangular Pyramid Surface Area is:\n\n " + str(quadrangularpyramidvolume), 'Quadrangular Pyramid Surface Area', wx.OK) varanswer15 = box.ShowModal() box.Destroy() def About(self, event): aboutbox = wx.MessageDialog(None, 'Formulum v2.0 - by David Gomes', 'About Formulum', wx.OK) aboutanswer = aboutbox.ShowModal() aboutbox.Destroy() def Close(self, event): exitbox = wx.MessageDialog(None, 'Do you really want to leave?', 'Exit', wx.YES_NO) if exitbox.ShowModal()==wx.ID_YES: exitbox.Destroy() self.Destroy(); else: exitbox.Destroy() def Help(self, event): helpbox = wx.MessageDialog(None, 'Press Choose Formula to calculate areas and volumes\n\nPress About to see Info\n\nScoutDavid', 'Help', wx.OK) helpanswer = helpbox.ShowModal() helpbox.Destroy() if __name__=='__main__': app=wx.PySimpleApp() frame=MainFrame(parent=None, id= -1) frame.Show() app.MainLoop()
Python!Um, I mean, so... you trying to make a Python program with an Nspire-style interface for formula solving?
Nice, hopefully this can be greatly useful for students. I personally wouldn't use it as I am out of school since 2004 and had my last math classes in 2003, but other people might find it useful.
Well, good lucky, and I think in Nspire 2.x it won't be difficulty for you do ...but you could just write a simpler thing in nspire [working on 1.4-2.x] with many well documented functions...EDIT:if you want I can do it for you, and you will be able to look at, and see how simple it is,and then do this program using the request, which is available just for 2.x OSes
There's not much to practice in the way of Nspire BASIC. Input, disp, text, and a few math functions are all that are really useful, IMO.
Quote from: willrandship on October 21, 2010, 11:41:34 amThere's not much to practice in the way of Nspire BASIC. Input, disp, text, and a few math functions are all that are really useful, IMO. Yeah, but as long as we keep making this kind of programs to keep Nspire alive I'll be posting screenshots in a few minutes
Nice, but I wonder if it's possible to add titles in those black bars?
Good work, but i think it would be more optimized without all that request thing...Don't missunderstand me, I not saying your program isn't great,But, in my opinion just all those functions, would be better also if you need to calculate something else ...//I don't know if what you wrote is functions or prgrmbut my tip is:if it isn't a function, then convert it into one:Let me say you have a circle area, and need to find the radiusyou could easily do nsolve(circlearea(x)=40,x);and i don't know if you can use this, while using request...