Modifiedvalues Main program Test

Source: Internet
Author: User

##~ #-------------------------------------------------
Class Inputframe (WX. Frame):
def __init__ (self,title= ' inputframe: ', label= ' Setting values: ', values={' int ': 1, ' string ': ' This is string ', ' float ' : 3.5},size= (400,200)):
‘‘‘‘‘
#~ >>>iframe = inputframe (title= ' inputframe: ', label= ' Setting values: ', values={' int ': 1, ' String ': ' This is String ', ' float ': 3.5},size= (400,200)):
#~>>> Rvalues=iframe.getvalue ()
‘‘‘
Wx. frame.__init__ (Self,parent=none,title = title,size=size)
Self.modifiedvalues=values.copy ()
Self. IPL = InputPanel (self,label=label,values=values)
#~ #创建FlexGridSizer
Self. Flexgridsizer=wx. Flexgridsizer (rows=9, Cols=1, vgap=5,hgap=5)
Self. Flexgridsizer.setflexibledirection (WX. BOTH)
Self. Rightpanel = wx. Panel (self,-1)
#~ #测试按钮1
Self. Button1 = wx. Button (self. Rightpanel,-1, "Testbutton", size= (100,40), pos= (10,10))
Self. Button1.bind (WX. Evt_button,self. GetValue)
#~ #加入Sizer中2881064151
Self. Flexgridsizer.add (self. Button1,proportion =0, border = 5,flag = wx. All | Wx. EXPAND)
Self. Rightpanel.setsizer (self. Flexgridsizer)
Self. Boxsizer=wx. Boxsizer (WX. Horizontal)
Self. Boxsizer.add (self. Ipl,proportion =-10, border = 2,flag = wx. All | Wx. EXPAND)
Self. Boxsizer.add (self. Rightpanel,proportion =0, border = 2,flag = wx. All | Wx. EXPAND)
Self. Setsizer (self. Boxsizer)
Self. Center (WX. BOTH)
#~ #按钮事件, for testing
def GetValue (self,event):
Self.modifiedvalues=self. Ipl. GetValue ()
#~ Print (self.modifiedvalues)
Return self.modifiedvalues
#~ #主程序测试
Def testinputframe ():
App = WX. Pysimpleapp ()
Title= ' Inputframe: '
Label= ' Setting values: '
values={' int ': 234, ' string ': ' This is String ', ' float ': 3.5}
Frame =inputframe (title,label,values)
Frame. Show ()
App. Mainloop ()
Return
if __name__ = = ' __main__ ':
App = WX. Pysimpleapp ()
Title= ' Inputframe: '
Label= ' Setting values: '
values={' int ': 234, ' string ': ' This is String ', ' float ': 3.5}
Frame =inputframe (title,label,values)
Frame. Show ()
App. Mainloop ()
#-*-Coding:utf-8-*-
#~ #--------------------------------------------------------------------------------
#~ Module:wlab
#~ filename=winput.py
#~ funciton:wx Input dialog box
#~ Author: Wu Xuping
#~ date:2013-04-28
#~ Email:[email protected]
#~ #-------------------------------------------------
Import WX
Import Wx.lib.sized_controls as Wxsc
#~ #-------------------------------------------------
#~ #set value for widgets (Statictext and Textctrl) height
Wh=30
#~ #set value for max width times
Mwt=8
#~ #set value for WH times
Wht=3
#~ #-------------------------------------------------
Class Inputdialog (WXSC. Sizeddialog):
def __init__ (self,title= ' Setting values: ', values={' int ': 1, ' string ': ' This is string ', ' float ': 3.5}):
‘‘‘
#~ using it as follow:
#~ dialog = Inputdialog (title= ' Setting values: ', values={' int ': 1, ' string ': ' This is string ', ' float ': 3.5})
#~ Just for test:
#~ dialog = Inputdialog ()
‘‘‘
style = WX. Default_dialog_style | Wx. Resize_border
Wxsc. Sizeddialog.__init__ (Self,parent=none, Id=-1, Title=title, Style=style)
Self.originvalues=values.copy ()
Self.modifiedvalues=values.copy ()
Self.pane = self. Getcontentspane ()
Self.pane.SetSizerType ("form")
Maxlen1=mwt*max ([Len (key) for key in values])
If MAXLEN1<WH*WHT:
Maxlen1=wh*wht
Maxlen2=mwt*max ([Len (Values[key]) for key in values])
If MAXLEN2<WH*WHT:
Maxlen2=wh*wht
For key in Self.modifiedvalues:
KEYSTR=STR (Key)
label=keystr+ ': '
Statictext = wx. Statictext (parent=self.pane,id=-1,label=label,style=wx. Align_right)
Statictext.setinitialsize ((MAXLEN1,WH))
Value=str (Self.modifiedvalues[key])
Textctrl = wx. Textctrl (Parent=self.pane, Id=-1,value=value)
Textctrl.setinitialsize ((MAXLEN2,WH))
Textctrl.setsizerprops (Expand=true)
#~set a name for textctrl,so later we can use WX. Findwindowbyname ()
Textctrl.name= ' tc_ ' +str (KEYSTR)
#StaticText. Name= ' St_ ' +str (KEYSTR)

#~ # Add Dialog buttons
Self. Setbuttonsizer (self. Createstddialogbuttonsizer (WX. OK | Wx. CANCEL))
Self. Fit ()
Self. Center ()
def getoriginvalue (self):
‘‘‘
#~ If the user select Wx.id_cancel,then return originvalues
‘‘‘
Return self.originvalues
def GetValue (self):
‘‘‘
#~ If the user select Wx.id_ok,then return self.modifiedvalues
‘‘‘
For key in Self.modifiedvalues:
KEYSTR=STR (Key)
Textctrlname= ' tc_ ' +str (KEYSTR)
Textctrl=self. Findwindowbyname (Textctrlname)
Ovk=self.modifiedvalues[key]
if (type (OVK) ==int):
Self.modifiedvalues[key]=int (Textctrl.getvalue (). Strip ())
Elif (Type (OVK) ==float):
Self.modifiedvalues[key]=float (Textctrl.getvalue (). Strip ())
Else
Self.modifiedvalues[key]=str (Textctrl.getvalue ())
Return self.modifiedvalues
#~ #-------------------------------------------------
def InputBox (title= ' Setting values ', values={' int ': 1, ' string ': ' This is string ', ' float ': 3.5}):
‘‘‘
#~ >>>values={' int ': 1, ' string ': ' This is String ', ' float ': 3.5}
#~ >>>title= ' Setting values: '
#~ >>>rvalues=inputbox (title,values)
#~ >>>print (rvalues):
‘‘‘
App = WX. Pysimpleapp ()
Dialog = Inputdialog (title=title,values=values)
If dialog. ShowModal () = = Wx.id_ok:
Values= dialog. GetValue ()
Else
Values=dialog. Getoriginvalue ()
Dialog. Destroy ()
App. Mainloop ()
Return values
##~ #测试InputBox
#if __name__ = = ' __main__ ':
#values ={' int ': 1, ' string ': ' This is String ', ' float ': 3.5}
#title = ' Setting values '
#rvalues =inputbox (title,values=values)
#print (rvalues)
##~ #-------------------------------------------------
Class InputPanel (WX. Panel):
def __init__ (self,parent,label= ' Setting values: ', values={' int ': 1, ' string ': ' This is string ', ' float ': 3.5}):
‘‘‘
#~ >>>IPL = InputPanel (parent,label= ' Setting values: ', values={' int ': 1, ' string ': ' This is string ', ' float ': 3.5 })
#~>>> RVALUES=IPL. GetValue (self)
‘‘‘
Wx. Panel.__init__ (Self,parent=parent, Id=-1)
Self.modifiedvalues=values.copy ()
box = WX. Staticbox (self,-1, Label=label)
Sbsizer = wx. Staticboxsizer (box, WX. VERTICAL)

Gridsizer = wx. Flexgridsizer (cols=2, hgap=5, vgap=5)

Maxlen1=mwt*max ([Len (key) for key in values])
If MAXLEN1<WH*WHT:
Maxlen1=wh*3
Maxlen2=mwt*max ([Len (Values[key]) for key in values])
If MAXLEN2<WH*WHT:
Maxlen2=wh*wht
For key in Self.modifiedvalues:
KEYSTR=STR (Key)
label=keystr+ ': '
Statictext = wx. Statictext (parent=self,id=-1,label=label,style=wx. Align_right)
Statictext.setinitialsize ((MAXLEN1,WH))
Gridsizer. ADD (statictext, 0, WX. Expand|wx. Align_center_vertical|wx. Left|wx. Right, 3)
Value=str (Self.modifiedvalues[key])
Textctrl = wx. Textctrl (parent=self, Id=-1,value=value)
Textctrl.setinitialsize ((MAXLEN2,WH))
Gridsizer. ADD (Textctrl, 0, WX. Expand|wx. Align_center_vertical|wx. Left|wx. Right, 3)
#~set a name for textctrl,so later we can use WX. Findwindowbyname ()
Textctrl.name= ' tc_ ' +str (KEYSTR)
Sbsizer. ADD (Gridsizer, 1, WX. EXPAND)
Gridsizer. Layout ()
Panelsizer = wx. Boxsizer (WX. VERTICAL)
Panelsizer.add (Sbsizer, 0, WX. All|wx. EXPAND, 5)
Self. Setsizer (Panelsizer)
Panelsizer.layout ()
Panelsizer.fit (self)
def GetValue (self):
‘‘‘
#~ return Self.modifiedvalues
‘‘‘
For key in Self.modifiedvalues:
KEYSTR=STR (Key)
Textctrlname= ' tc_ ' +str (KEYSTR)
Textctrl=self. Findwindowbyname (Textctrlname)
Ovk=self.modifiedvalues[key]
if (type (OVK) ==int):
Self.modifiedvalues[key]=int (Textctrl.getvalue (). Strip ())
Elif (Type (OVK) ==float):
Self.modifiedvalues[key]=float (Textctrl.getvalue (). Strip ())
Else
Self.modifiedvalues[key]=str (Textctrl.getvalue ())
Return self.modifiedvalues
##~ #-------------------------------------------------
Class Inputframe (WX. Frame):
def __init__ (self,title= ' inputframe: ', label= ' Setting values: ', values={' int ': 1, ' string ': ' This is string ', ' float ' : 3.5},size= (400,200)):
‘‘‘
#~ >>>iframe = inputframe (title= ' inputframe: ', label= ' Setting values: ', values={' int ': 1, ' String ': ' This is String ', ' float ': 3.5},size= (400,200)):
#~>>> Rvalues=iframe.getvalue ()
‘‘‘
Wx. frame.__init__ (Self,parent=none,title = title,size=size)
Self.modifiedvalues=values.copy ()
Self. IPL = InputPanel (self,label=label,values=values)
#~ #创建FlexGridSizer
Self. Flexgridsizer=wx. Flexgridsizer (rows=9, Cols=1, vgap=5,hgap=5)
Self. Flexgridsizer.setflexibledirection (WX. BOTH)

Self. Rightpanel = wx. Panel (self,-1)

#~ #测试按钮1
Self. Button1 = wx. Button (self. Rightpanel,-1, "Testbutton", size= (100,40), pos= (10,10))
Self. Button1.bind (WX. Evt_button,self. GetValue)
#~ #加入Sizer中
Self. Flexgridsizer.add (self. Button1,proportion =0, border = 5,flag = wx. All | Wx. EXPAND)
Self. Rightpanel.setsizer (self. Flexgridsizer)
Self. Boxsizer=wx. Boxsizer (WX. Horizontal)
Self. Boxsizer.add (self. Ipl,proportion =-10, border = 2,flag = wx. All | Wx. EXPAND)
Self. Boxsizer.add (self. Rightpanel,proportion =0, border = 2,flag = wx. All | Wx. EXPAND)
Self. Setsizer (self. Boxsizer)
Self. Center (WX. BOTH)
#~ #按钮事件, for testing
def GetValue (self,event):
Self.modifiedvalues=self. Ipl. GetValue ()
#~ Print (self.modifiedvalues)
Return self.modifiedvalues
#~ #主程序测试
Def testinputframe ():
App = WX. Pysimpleapp ()
Title= ' Inputframe: '
Label= ' Setting values: '
values={' int ': 234, ' string ': ' This is String ', ' float ': 3.5}
Frame =inputframe (title,label,values)
Frame. Show ()
App. Mainloop ()
Return
if __name__ = = ' __main__ ':
App = WX. Pysimpleapp ()
Title= ' Inputframe: '
Label= ' Setting values: '
values={' int ': 234, ' string ': ' This is String ', ' float ': 3.5}
Frame =inputframe (title,label,values)
Frame. Show ()
App. Mainloop ()

Modifiedvalues Main program Test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.