[wxPython-users] Different result on different OS

Andrea amarin at mr-service.it
Thu Apr 5 10:17:25 PDT 2007


This is all my application:

--------------------------------------------------------------

import wx, os, pickle

class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
wx.Size(550, 450))
        
# Create MenuBar
        menubar = wx.MenuBar()
# Create item Menu of MenuBar        
        file = wx.Menu()
        edit = wx.Menu()
        help = wx.Menu()
#File menu items
        file.Append(103, '&New\tCtrl+N', 'New document...')
        file.Append(101, '&Open\tCtrl+O', 'Open document...')
        file.Append(102, '&Save\tCtrl+S', 'Save document...')
        file.AppendSeparator()
        quit = wx.MenuItem(file, 105, '&Quit\tCtrl+Q', 'Quit Kory
Application')
        file.AppendItem(quit)
#Edit menu ites       
        edit.Append(201, 'Wiev List', 'Wiev list mode')#,
kind=wx.ITEM_CHECK)
        edit.Append(202, 'Wiev Tree', 'Wiev tree mode')#,
kind=wx.ITEM_CHECK)
# Sub menu of edit items      
        submenu = wx.Menu()
        submenu.Append(301, 'Red', kind=wx.ITEM_RADIO)
        submenu.Append(302, 'Blue', kind=wx.ITEM_RADIO)
        submenu.Append(303, 'Yellow', kind=wx.ITEM_RADIO)
        edit.AppendMenu(203, 'Set Colors', submenu)
#Help menu items        
        help.Append(401, '&About\tCtrl+A', 'About Kory Application')
#Attach menu to the menubar        
        menubar.Append(file, '&File')
        menubar.Append(edit, '&Edit')
        menubar.Append(help, '&Help')
        self.SetMenuBar(menubar)
        self.Centre()
#Attach the menu-event to the method
        self.Bind(wx.EVT_MENU, self.OnNew, id=103)
        self.Bind(wx.EVT_MENU, self.OnOpen, id=101)       
        self.Bind(wx.EVT_MENU, self.OnSave, id=102)
        self.Bind(wx.EVT_MENU, self.OnAbout, id=401)
        self.Bind(wx.EVT_MENU, self.OnQuit, id=105)
#Create and customize StatusBar 
        self.CreateStatusBar()
        self.SetStatusText('Kory Application...')
#Add panel between menubar and statusbar        
        self.panel = wx.Panel(self)
#Create control on the panel
        nameLbl = wx.StaticText(self.panel, -1, 'Corporate Name:', pos =
(5, 15))
        numofcallsLbl = wx.StaticText(self.panel, -1, 'Number of
Calls:', pos = (5, 45))
        localLbl = wx.StaticText(self.panel, -1, 'Total local cost:',
pos = (5, 75))
        localmrLbl = wx.StaticText(self.panel, -1, 'Total local cost
MR:', pos = (5, 105))
        totaldurationLbl = wx.StaticText(self.panel, -1, 'Total Duration
Calls:', pos = (5, 135))
        costtotheminuteLbl = wx.StaticText(self.panel, -1, 'Cost to the
minute:', pos =(5, 165))
        costtotheminutewithmrLbl = wx.StaticText(self.panel, -1, 'Cost
to the minute with MR:', pos =(5, 195))
        overpricelLbl = wx.StaticText(self.panel, -1, 'Over Price MR
(%):', pos =(5, 225))
        mrcosttotheminuteLbl = wx.StaticText(self.panel, -1, 'MR Cost to
the minute:', pos = (5, 255))
        self.name = wx.TextCtrl(self.panel, -1, '', pos = (200,15), size
= (250, -1))
        self.name.SetFocus()
        self.numofcalls = wx.TextCtrl(self.panel, -1, '', pos = (200,
45))
        self.local = wx.TextCtrl(self.panel, -1, '', pos = (200, 75))
        self.localmr = wx.TextCtrl(self.panel, -1, '', pos = (200, 105),
size = (140, -1))
        self.localmr.SetBackgroundColour('#ffdf85')
        self.localmr.Disable()
        self.totalduration_h = wx.TextCtrl(self.panel, -1, '', pos =
(200, 135), size = (40, -1))
        self.totalduration_m = wx.TextCtrl(self.panel, -1, '', pos =
(245, 135), size = (40, -1))
        self.totalduration_s = wx.TextCtrl(self.panel, -1, '', pos =
(290, 135), size = (40, -1))
        self.costtotheminute = wx.TextCtrl(self.panel, -1, '', pos =
(200, 165), size = (140, -1))
        self.costtotheminute.SetBackgroundColour('#ffdf85')
        self.costtotheminute.Disable()
        self.costtotheminutewithmr = wx.TextCtrl(self.panel, -1, '', pos
= (200, 195))
        self.costtotheminutewithmr.SetBackgroundColour('#ffdf85')
        self.costtotheminutewithmr.Disable()
        self.overprice = wx.TextCtrl(self.panel, -1, '', pos = (200,
225))
        self.mrcosttotheminute = wx.TextCtrl(self.panel, -1, '0.0105',
pos = (200, 255))

#Create control buttom
        #o = wx.Button(self.panel, -1, 'Open', pos = (100, 360))
        #self.Bind(wx.EVT_BUTTON, self.OnOpen, o)
        c = wx.Button(self.panel, -1, 'Calculate', pos = (300, 255))
        self.Bind(wx.EVT_BUTTON, self.OnCalculate, c)
        #b = wx.Button(self.panel, -1, 'Save', pos = (0, 360))
        #self.Bind(wx.EVT_BUTTON, self.OnSave, b)

#Create event def section

    def OnNew(self, event):
        self.name.SetValue('')
        self.name.SetFocus()
        self.numofcalls.SetValue('')
        self.local.SetValue('')
        self.local.SetBackgroundColour('#FFFFFF')
        self.localmr.Disable()
        self.localmr.SetValue('')
        self.localmr.SetBackgroundColour('#ffdf85')
        self.totalduration_h.SetValue('')
        self.totalduration_m.SetValue('')
        self.totalduration_s.SetValue('')
        self.costtotheminute.Disable()
        self.costtotheminute.SetValue('')
        self.costtotheminute.SetBackgroundColour('#ffdf85')
        self.costtotheminutewithmr.Disable()
        self.costtotheminutewithmr.SetValue('')
        self.costtotheminutewithmr.SetBackgroundColour('#ffdf85')
        self.overprice.SetValue('')
        self.mrcosttotheminute.SetValue('0.0105')
        
    def OnOpen(self, event):
        self.data = {}
        self.dirname = ''
        dlg = wx.FileDialog(self, 'Chose a file', self.dirname, '',
'*.*', wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
                self.filename = dlg.GetFilename()
                self.dirname = dlg.GetDirectory()
                f = open(os.path.join(self.dirname, self.filename), 'r')
        dlg.Destroy()
#Load value from file
        self.data = pickle.load(f)
        self.name.SetValue(self.data['Corporate_Name'])
        self.numofcalls.SetValue(self.data['Number_of_Calls'])
        self.local.SetValue(self.data['Total_local_cost'])
        self.local.SetBackgroundColour('#FFDEAD')
        self.localmr.Enable()
        self.localmr.SetValue(self.data['Total_local_cost_MR'])
        self.localmr.SetBackgroundColour('#FFDEAD')

self.totalduration_h.SetValue(self.data['Total_Duration_Calls_H'])

self.totalduration_m.SetValue(self.data['Total_Duration_Calls_M'])

self.totalduration_s.SetValue(self.data['Total_Duration_Calls_S'])
        self.costtotheminute.Enable()
        self.costtotheminute.SetValue(self.data['Cost_to_the_minute'])
        self.costtotheminute.SetBackgroundColour('#90EE90')
        self.costtotheminutewithmr.Enable()

self.costtotheminutewithmr.SetValue(self.data['Cost_to_the_minute_with_MR'])
        self.costtotheminutewithmr.SetBackgroundColour('#90EE90')
        self.overprice.SetValue(self.data['Over_price_MR'])

self.mrcosttotheminute.SetValue(self.data['MR_Cost_to_the_minute'])       
        f.close()
        
    def OnSave(self, event):
#Get value from user
        rag_soc = self.name.GetValue()
        quantity = self.numofcalls.GetValue()
        tot_local_cost = self.local.GetValue()
        tot_mr_local_cost = self.localmr.GetValue()
        hours = self.totalduration_h.GetValue()
        minutes = self.totalduration_m.GetValue()
        seconds = self.totalduration_s.GetValue()
        minute_cost = self.costtotheminute.GetValue()
        minute_mr_cost = self.costtotheminutewithmr.GetValue()
        over_price = self.overprice.GetValue()
        mr_minute_cost = self.mrcosttotheminute.GetValue()      
        
#Create a dictionary for save data into a file
        self.data = {}
        self.data['Corporate_Name'] = rag_soc
        self.data['Number_of_Calls'] = quantity
        self.data['Total_local_cost'] = tot_local_cost
        self.data['Total_local_cost_MR'] = tot_mr_local_cost
        self.data['Total_Duration_Calls_H'] = hours
        self.data['Total_Duration_Calls_M'] = minutes
        self.data['Total_Duration_Calls_S'] = seconds
        self.data['Cost_to_the_minute'] = minute_cost
        self.data['Cost_to_the_minute_with_MR'] = minute_mr_cost
        self.data['Over_price_MR'] = over_price
        self.data['MR_Cost_to_the_minute'] = mr_minute_cost
        
        self.dirname = ''
        dlg = wx.FileDialog(self, "Chose a file", self.dirname, '',
'*.*', wx.SAVE)
        if dlg.ShowModal() == wx.ID_OK: 
                self.filename = dlg.GetFilename()
                self.dirname = dlg.GetDirectory()
                f = open(os.path.join(self.dirname, self.filename), 'w')
                pickle.dump(self.data, f)
                f.close()
        dlg.Destroy
        
    def OnCalculate(self, event):
#Get values from GUI
        h = self.totalduration_h.GetValue()
        m = self.totalduration_m.GetValue()
        s = self.totalduration_s.GetValue()
        tot_local = self.local.GetValue()
        over = self.overprice.GetValue()
        mrcost = self.mrcosttotheminute.GetValue()
#Make operation for calculate the values        
        second = (((float(h) * 60) * 60) + (float(m) * 60) + float(s))
        costminute = (float(tot_local)/float(second)) * 60
        overcostmr = (float(mrcost) + ((float(mrcost) * float(over)) /
100))
        tot_localmr = (float(overcostmr) * (float(second)) / 60)
#Set the control with new values
        self.local.SetBackgroundColour('#FFDEAD')
        self.costtotheminute.Enable()
        self.costtotheminute.SetValue(unicode(costminute))
        self.costtotheminute.SetBackgroundColour('#90EE90')
        self.costtotheminutewithmr.Enable()
        self.costtotheminutewithmr.SetValue(unicode(overcostmr))
        self.costtotheminutewithmr.SetBackgroundColour('#90EE90')
        self.localmr.Enable()
        self.localmr.SetValue(unicode(tot_localmr))
        self.localmr.SetBackgroundColour('#FFDEAD')
        
    def OnQuit(self, event):
        self.Close()

    def OnAbout(self, event):
        msg = "This is the Kory application for analisys of calls
cost.\n" + \
              "Author: Andrea Marin @ 05 Apr 2007\n" + \
              "Please report any Bug/Requests of improvements\n" + \
              "to me at the following adresses:\n\n" + \
              "Mail : amarin at mr-service.it\n" + "IM :
baba-andrea at jabber.org\n" + \
              "Skype : baba-andrea79\n\n" + "GUI with wxPython " +
wx.VERSION_STRING + " !!!"
              
        dlg = wx.MessageDialog(self, msg, "About panel Kory
application", 
                                wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
        
class MyApp(wx.App):
    def OnInit(self):
        frame = MainWindow(None, -1, 'Welcome to Kory Phone Calls
Application')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp()
app.MainLoop()
-----------------------------------------------------------------------------

I hope that this can help.
Andrea





More information about the wxpython-users mailing list