# _*_ coding: utf-8 _*_
import wx
import load
import convert
import string
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, u"Конвертер валют по курсу ПриватБанку",
size=(800, 270), pos=(20,20),
style=wx.DEFAULT_FRAME_STYLE^wx.MINIMIZE_BOX^wx.MAXIMIZE_BOX^wx.RESIZE_BORDER)
# panel
self.panel = wx.Panel(self, -1)
# StaticTexts
self.main_label = wx.StaticText(self.panel, -1,
u"КОНВЕРТЕР ВАЛЮТ ПО СЬОГОДНІШНЬОМУ КУРСУ ПРИВАТБАНКУ",
pos=(10,10))
self.convert_label1 = wx.StaticText(self.panel, -1,
u"Конвертуємо ", pos=(10,138))
self.convert_label2 = wx.StaticText(self.panel, -1,
u"Конвертуємо ", pos=(10,182))
self.convert_label3 = wx.StaticText(self.panel, -1,
u" в 0 гривень.", pos=(335,138))
self.convert_label4 = wx.StaticText(self.panel, -1,
u"гривень в 0", pos=(180,183))
# RadioBoxs
self.type_crn_RB = wx.RadioBox(self.panel, -1, u"Тип валюти:", (10,40),
wx.DefaultSize, [u"готівка", u"не готівка"], 1,
wx.RA_SPECIFY_COLS)
self.type_oper_RB = wx.RadioBox(self.panel, -1, u"Тип операції:", (110,40),
wx.DefaultSize, [u"купівля", u"продаж"], 1,
wx.RA_SPECIFY_COLS)
self.kind_crn1_RB = wx.RadioBox(self.panel, -1, u"", (180,120),
wx.DefaultSize, [u"RUB", u"USD", u"EUR"], 3,
wx.RA_SPECIFY_COLS)
self.kind_crn2_RB = wx.RadioBox(self.panel, -1, u"", (320,165),
wx.DefaultSize, [u"RUB", u"USD", u"EUR"], 3,
wx.RA_SPECIFY_COLS)
# TextCtrls
self.value1_TC = wx.TextCtrl(self.panel, -1, "1", size=(80,20), pos=(90, 136))
self.value2_TC = wx.TextCtrl(self.panel, -1, "1", size=(80,20), pos=(90, 182))
# loading information from server
self.values = load.load_currency()
# table of currency
string = self.string_format()
self.table = wx.StaticText(self.panel, -1, string, pos=(400,20))
# converting at start
self.converting1()
self.converting2()
# Binds
self.Bind(wx.EVT_RADIOBOX, self.OnConvert, self.type_crn_RB)
self.Bind(wx.EVT_RADIOBOX, self.OnConvert, self.type_oper_RB)
self.Bind(wx.EVT_RADIOBOX, self.OnInput1, self.kind_crn1_RB)
self.Bind(wx.EVT_RADIOBOX, self.OnInput2, self.kind_crn2_RB)
self.Bind(wx.EVT_TEXT, self.OnInput1, self.value1_TC)
self.Bind(wx.EVT_TEXT, self.OnInput2, self.value2_TC)
def string_format(self):
return u""" %s%s\n %s%s%s%s\n%s %15.5f %15.5f %15.5f %15.5f\n%s%15.5f%15.5f %15.5f %15.5f\n%s%15.5f%15.5f %15.5f %15.5f""" % (u"ГОТІВКА".center(46),
u"НЕ ГОТІВКА".center(22),
u'купівля'.rjust(21), u'продаж'.rjust(15),
u'купівля'.rjust(15), u'продаж'.rjust(15),
u'RUB', self.values['RUR_cash_buy'],self.values['RUR_cash_sale'],self.values['RUR_ncash_buy'],self.values['RUR_ncash_sale'],
u'USD', self.values['USD_cash_buy'],self.values['USD_cash_sale'],self.values['USD_ncash_buy'],self.values['USD_ncash_sale'],
u'EUR', self.values['EUR_cash_buy'],self.values['EUR_cash_sale'],self.values['EUR_ncash_buy'],self.values['EUR_ncash_sale'])
def OnInput1(self, event):
value = self.value1_TC.GetValue()
if value=="":
pass
else:
if (len(value)>1) and ("." in value[:-1]) and (value[-1]=="."):
self.value1_TC.Clear()
self.value1_TC.AppendText(value[:-1])
self.converting1()
if (value=="."):
self.value1_TC.Clear()
self.value1_TC.AppendText("0.")
if value[-1]==',':
self.value1_TC.Clear()
self.value1_TC.AppendText(value[:-1]+".")
if len(value)==1:
self.value1_TC.Clear()
else:
self.converting1()
else:
if not(value[-1] in string.digits+"."):
if len(value)==1:
self.value1_TC.Clear()
else:
self.value1_TC.Clear()
self.value1_TC.AppendText(value[:-1])
self.converting1()
else:
self.converting1()
def OnInput2(self, event):
value = self.value2_TC.GetValue()
if value=="":
pass
else:
if (len(value)>1) and ("." in value[:-1]) and (value[-1]=="."):
self.value2_TC.Clear()
self.value2_TC.AppendText(value[:-1])
self.converting2()
if (value=="."):
self.value2_TC.Clear()
self.value2_TC.AppendText("0.")
if value[-1]==',':
self.value2_TC.Clear()
self.value2_TC.AppendText(value[:-1]+".")
if len(value)==1:
self.value2_TC.Clear()
else:
self.converting2()
else:
if not(value[-1] in string.digits+"."):
#print not(value[-1] in string.digits)
if len(value)==1:
self.value2_TC.Clear()
else:
self.value2_TC.Clear()
self.value2_TC.AppendText(value[:-1])
self.converting2()
else:
self.converting2()
def OnConvert(self, event):
self.converting1()
self.converting2()
def converting1(self):
list_ccr = {0:"RUR", 1:"USD", 2:"EUR"}
ccr1 = list_ccr[self.kind_crn1_RB.GetSelection()]
ccr1_value = float(self.value1_TC.GetValue())
if self.type_crn_RB.GetSelection()==0:
ccr_type = "cash"
else:
ccr_type = "ncash"
if self.type_oper_RB.GetSelection()==0:
ccr_oper = "buy"
else:
ccr_oper = "sale"
temp1 = convert.ccr_to_uan(ccr1_value, ccr1, ccr_type,
ccr_oper, self.values)
self.convert_label3.SetLabel(u" в %.2f гривень." % (temp1))
def converting2(self):
list_ccr = {0:"RUR", 1:"USD", 2:"EUR"}
ccr2 = list_ccr[self.kind_crn2_RB.GetSelection()]
ccr2_value = float(self.value2_TC.GetValue())
if self.type_crn_RB.GetSelection()==0:
ccr_type = "cash"
else:
ccr_type = "ncash"
if self.type_oper_RB.GetSelection()==0:
ccr_oper = "buy"
else:
ccr_oper = "sale"
temp2 = convert.uan_to_ccr(ccr2_value, ccr2, ccr_type,
ccr_oper, self.values)
self.convert_label4.SetLabel(u"гривень в %.2f" % (temp2))
class MyApp(wx.App):
def OnInit(self):
self.main_frame = Frame()
self.SetTopWindow(self.main_frame)
self.main_frame.Show()
return True
if __name__=="__main__":
app = MyApp()
app.MainLoop()