Skip to content

Commit

Permalink
ENH: gui.Dlg() - add fieldLength to control size of input display
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremygray committed Dec 15, 2013
1 parent 2649ee0 commit c40f047
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions psychopy/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ def addText(self, text, color=''):
if len(color): myTxt.SetForegroundColour(color)
self.sizer.Add(myTxt,1,wx.ALIGN_CENTER)

def addField(self, label='', initial='', color='', choices=None, tip=''):
def addField(self, label='', initial='', color='', choices=None, tip='', fieldLength=0):
"""
Adds a (labelled) input field to the dialogue box, optional text color
and tooltip. Returns a handle to the field (but not to the label).
If choices is a list or tuple, it will create a dropdown selector.
``fieldLength`` sets the size of the input box (defaults to length of ``initial``).
"""
self.inputFieldNames.append(label)
if choices:
Expand All @@ -91,7 +92,8 @@ def addField(self, label='', initial='', color='', choices=None, tip=''):
inputBox = wx.CheckBox(self, -1)
inputBox.SetValue(initial)
elif not choices:
inputLength = wx.Size(max(50, 5*len(unicode(initial))+16), 25)
chars = fieldLength or len(unicode(initial))
inputLength = wx.Size(max(50, 5 * chars + 16), 25)
inputBox = wx.TextCtrl(self,-1,unicode(initial),size=inputLength)
else:
inputBox = wx.Choice(self, -1, choices=[unicode(option) for option in list(choices)])
Expand Down Expand Up @@ -191,7 +193,7 @@ class DlgFromDict(Dlg):
See GUI.py for a usage demo, including order and tip (tooltip).
"""
def __init__(self, dictionary, title='',fixed=[], order=[], tip={}):
def __init__(self, dictionary, title='',fixed=[], order=[], tip={}, fieldLength=0):
Dlg.__init__(self, title)
self.dictionary=dictionary
keys = self.dictionary.keys()
Expand All @@ -205,11 +207,11 @@ def __init__(self, dictionary, title='',fixed=[], order=[], tip={}):
tooltip = ''
if field in tip.keys(): tooltip = tip[field]
if field in fixed:
self.addFixedField(field,self.dictionary[field], tip=tooltip)
self.addFixedField(field,self.dictionary[field], tip=tooltip, fieldLength=fieldLength)
elif type(self.dictionary[field]) in [list, tuple]:
self.addField(field,choices=self.dictionary[field], tip=tooltip)
else:
self.addField(field,self.dictionary[field], tip=tooltip)
self.addField(field,self.dictionary[field], tip=tooltip, fieldLength=fieldLength)
#show it and collect data
#tmp= wx.PySimpleApp()#this should have been done by Dlg ?
self.show()
Expand Down

0 comments on commit c40f047

Please sign in to comment.