On Fri, Feb 20, 2009 at 6:37 PM, Joe and Janine Loyzaga > <jloyzaga@bigpond.net.au <mailto:jloyzaga@bigpond.net.au>> wrote:
most of my text boxes need reducing in width - how can I make the
text box size something I decide?
When using sizers, you can give the sizer sizing the textCtrl (what you are calling a textbox, if I understand it) a proportionality value, like with any control. If you make it 0 and tell it not to expand, its size will be given by whatever you set its size at when you constructed it.
and the same goes for the label? how can I make it wrap?
I think you mean the value of the textCtrl, that is, its text? Have you tried setting the style flag wx.TE_MULTILINE ?
Lastly, when attaching a runnable sample, try to leave out if you can things like MySQL, xlrd, xlwt, etc., that don't come standard with wxPython, since it makes it more likely people can quickly test your code.
HTH,
Che
My script is attached
import wx
#import easygui
import xlwt
#import pyExcelerator
import xlrd
import MySQLdb
#import psycopg2
import os
from datetime import datetime
from datetime import date
db = MySQLdb.connect(user="root", passwd="", db="automate-cisss")
cursor = db.cursor()
cursor.execute("""SELECT DISTINCT r.`Runtype` FROM runtype r;""")
runtypes = [item[0] for item in cursor.fetchall()]
cursor.execute("""SELECT DISTINCT e.`Environment Name` FROM
environments e;""")
envs = [item[0] for item in cursor.fetchall()]
cursor.execute("""SELECT DISTINCT a.`AUT` FROM `application under
test` a;""")
AUT = [item[0] for item in cursor.fetchall()]
cursor.execute("""SELECT DISTINCT p.`Phase` FROM `phase` p;""")
phases = [item[0] for item in cursor.fetchall()]
#wb = xlrd.open_workbook('C:\Data\CISSS\Resources\UserIDPassword.xls')
#sh = wb.sheet_by_name(u'Sheet1')
#authors = [sh.cell(rowx=0,colx=1).value,
sh.cell(rowx=1,colx=1).value ]
#book =
pyExcelerator.parse_xls("C:\Data\CISSS\Resources\UserIDPassword.xls")
#data = book[0][1]
#envs = [sh.cell(rowx=0,colx=1).value, sh.cell(rowx=1,colx=1).value ]
class MyForm(wx.Frame):
def __init__(self):
self.runs =
self.input_cell = 0
self.style0 = xlwt.easyxf('font: name Times New
Roman, color-index red, bold on',
num_format_str='#,##0.00')
self.style1 = xlwt.easyxf(num_format_str='DD-MMM-YY')
#todaypieces = date.today()
#todaypieces="%02d-%02d-%s" % (todaypieces.day,
todaypieces.month, todaypieces.year)
#today = todaypieces.split("/")
#today = "%s-%s-%s" % (pieces[2], pieces[1], pieces[0])
#today= date.today.strftime('%d-%m-%Y')
#today = date.today()
#today = date.today.strftime('%d-%m-%Y')
today = date.today()
today = today.strftime("%d-%m-%Y")
self.file_path = "c:\Rundata-%s.xls"%(str(today))
# get the appropriate point to add new data
self.init_workbook()
self.frame = wx.Frame.__init__(self, None,
wx.ID_ANY, title='My Form')
font1 = wx.Font(14, wx.DECORATIVE, wx.NORMAL,
wx.BOLD, False, u'Arial')
# Add a panel so it looks correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION,
wx.ART_OTHER, (16, 16))
titleIco = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
title = wx.StaticText(self.panel, wx.ID_ANY, 'Enter
Automation Run Details')
title.SetFont(font1)
topSizer = wx.BoxSizer(wx.VERTICAL)
titleSizer = wx.BoxSizer(wx.HORIZONTAL)
self.gridSizer = wx.GridSizer(rows=7, cols=2,
hgap=5, vgap=5)
titleSizer.Add(titleIco, 0, wx.ALL, 5)
titleSizer.Add(title, 0, wx.ALL, 5)
topSizer.Add(titleSizer, 0, wx.CENTER)
topSizer.Add(wx.StaticLine(self.panel), 0,
wx.ALL|wx.EXPAND, 5)
bmp = wx.ArtProvider.GetBitmap(wx.ART_HELP,
wx.ART_OTHER, (16, 16))
# select Application under test
self.cbAUT = self.combo("Select AUT", AUT,
((wx.EVT_COMBOBOX, self.OnSelect),), bmp)
# select Run Type
self.cbruntype = self.combo("Select Run Type",
runtypes, ((wx.EVT_COMBOBOX, self.OnSelect),), bmp)
# select Run Environment
self.cbenvs = self.combo("Select Run Environment",
envs, ((wx.EVT_COMBOBOX, self.OnSelect),), bmp)
# select Release Phase
self.cbphases = self.combo("Select Release Phase",
phases, ((wx.EVT_COMBOBOX, self.OnSelect),), bmp)
# select End Point
self.inputTxtTwo = self.textbox('Ending point.
Press OK to accept or type new end point.','99', bmp)
# select Scheduled Start Time
self.inputTxtThree = self.textbox('Starting at what
hour? - e.g. for tomorrow at 6 then just enter 6, 24 hour clock.
For immediate start just accept (please note 99 should display).
Press OK to accept .','99', bmp)
# select QTP on or off
self.checkboxqtp_value = "QTP ON?"
self.checkBoxqtp = self.checkbox("Select QTP On or
Off", self.checkboxqtp_value, ((wx.EVT_CHECKBOX, self.OnSelect),),
bmp)
# select Selenium
self.checkboxselenium_value = "Selenium ON?"
self.checkBoxselenium = self.checkbox("Select
Selenium On or Off", self.checkboxselenium_value,
((wx.EVT_CHECKBOX, self.OnSelect),), bmp)
# select Selenium Grid
self.checkboxseleniumgrid_value = "Selenium Grid ON?"
self.checkBoxseleniumgrid = self.checkbox("Select
Selenium Grid On or Off", self.checkboxseleniumgrid_value,
((wx.EVT_CHECKBOX, self.OnSelect),), bmp)
# select Starting Point
self.inputTxtOne = self.textbox('Starting point.
Press OK to accept or type new start point. Include Header
Row','2', bmp)
topSizer.Add(self.gridSizer, 0, wx.ALL|wx.EXPAND, 5)
topSizer.Add(wx.StaticLine(self.panel), 0,
wx.ALL|wx.EXPAND, 5)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
okBtn = wx.Button(self.panel, wx.ID_ANY, 'OK')
cancelBtn = wx.Button(self.panel, wx.ID_ANY, 'Cancel')
self.Bind(wx.EVT_BUTTON, self.onOK, okBtn)
self.Bind(wx.EVT_BUTTON, self.onCancel, cancelBtn)
btnSizer.Add(okBtn, 0, wx.ALL, 5)
btnSizer.Add(cancelBtn, 0, wx.ALL, 5)
topSizer.Add(btnSizer, 0, wx.ALL|wx.CENTER, 5)
# SetSizeHints(minW, minH, maxW, maxH)
self.SetSizeHints(250,300,600,500)
self.panel.SetSizer(topSizer)
topSizer.Fit(self)
def combo(self, label_str, choices_list, bind_list, bmp =
None):
if bmp:
bitmap = wx.StaticBitmap(self.panel,
wx.ID_ANY, bmp)
label = wx.StaticText(self.panel, wx.ID_ANY, label_str)
combo = wx.ComboBox(self.panel, -1, pos=(50, 70),
size = (150, -1), choices= choices_list, style = wx.CB_READONLY)
for event, func in bind_list:
combo.Bind(event, func)
input_sizer = wx.BoxSizer(wx.HORIZONTAL)
input_sizer.Add((20,20), proportion=1) # this is a
spacer
if bmp:
input_sizer.Add(bitmap, 0, wx.ALL, 5)
input_sizer.Add(label, 0,
wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
self.gridSizer.Add(input_sizer, 0, wx.ALIGN_RIGHT)
self.gridSizer.Add(combo,0,wx.EXPAND)
return combo
def checkbox(self, label_str, choices_list, bind_list, bmp
= None):
if bmp:
bitmap = wx.StaticBitmap(self.panel,
wx.ID_ANY, bmp)
label = wx.StaticText(self.panel, wx.ID_ANY, label_str)
checkbox = wx.CheckBox(self.panel, -1, pos=(50,
70), size = (150, -1), style = wx.CB_READONLY)
for event, func in bind_list:
checkbox.Bind(event, func)
input_sizer = wx.BoxSizer(wx.HORIZONTAL)
input_sizer.Add((20,20), proportion=1) # this is a
spacer
if bmp:
input_sizer.Add(bitmap, 0, wx.ALL, 5)
input_sizer.Add(label, 0,
wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
self.gridSizer.Add(input_sizer, 0, wx.ALIGN_RIGHT)
self.gridSizer.Add(checkbox,0,wx.EXPAND)
return checkbox
def textbox(self, label_str, default_value = '', bmp = None):
if bmp:
bitmap = wx.StaticBitmap(self.panel,
wx.ID_ANY, bmp)
label = wx.StaticText(self.panel, wx.ID_ANY, label_str)
tbox = wx.TextCtrl(self.panel, wx.ID_ANY,default_value)
input_sizer = wx.BoxSizer(wx.HORIZONTAL)
input_sizer.Add((20,20), proportion=1) # this is a
spacer
if bmp:
input_sizer.Add(bitmap, 0, wx.ALL, 5)
input_sizer.Add(label, 0,
wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
self.gridSizer.Add(input_sizer, 0, wx.ALIGN_RIGHT)
self.gridSizer.Add(tbox, 0, wx.EXPAND)
return tbox
def init_workbook(self):
self.workbook = xlwt.Workbook()
self.worksheet =
self.workbook.add_sheet('Automation Run')
if os.path.exists(self.file_path):
print "file exists"
book = xlrd.open_workbook(self.file_path)
sheet = book.sheet_by_index(0)
cells = sheet.row(0) # first row is zero
# The following step allows for the chance
that there may be gaps
# in the data -- e.g. the user has deleted
some items
data = [cell.value for cell in cells if
cell.ctype != xlrd.XL_CELL_EMPTY]
for item in data:
self.worksheet.write(0,
self.input_cell, item, self.style0)
self.input_cell += 1
def onOK(self, event):
# we append to runs the current values of the dialog
results =
#global inputTxtOne
for dialog in self.cbAUT, self.cbruntype,
self.cbenvs, self.cbphases, self.inputTxtOne, self.inputTxtTwo,
self.inputTxtThree:
results.append(dialog.GetValue())
self.runs.append('|'.join(results))
print self.runs[-1]
#self.worksheet.write(0, self.input_cell,
str(self.runs[-1]), self.style0)
#self.input_cell += 1
#qtp = self.chkQTP.GetValue()
qtp = self.checkBoxqtp.GetValue()
selenium = self.checkBoxselenium.GetValue()
print selenium
Grid = self.checkBoxseleniumgrid.GetValue()
value = ''
if qtp:
value = 'QTP'
if Grid:
value = 'Grid'
if selenium:
value = 'selenium'
if qtp and selenium:
value = "QTP|Selenium"
if qtp and Grid:
value = 'QTP|Grid'
results.append(value)
self.runs.append('|'.join(results))
print self.runs[-1]
self.worksheet.write(0, self.input_cell,
str(self.runs[-1]), self.style0)
self.input_cell += 1
self.workbook.save(self.file_path)
def onCancel(self, event):
self.workbook.save(self.file_path)
self.closeProgram()
def closeProgram(self):
# self.runs should now have the full list of
different options for runs
self.Close()
def OnSelect(self, event):
item = event.GetSelection()
print item
#v1 = cb.GetValue()
#print item
#print v1
#win = event.GetEventObject() # call this if you
want to know which box was clicked
#for ix, item in enumerate(self.cbAUT):
# if win == item:
# break
#item = event.GetSelection()
#print "You selected item %s in combobox number %s"
% (item,ix)
#mld = "You selected '"
#for cb in self.cbs:
# v1 = cb.GetValue()
# if v1:
# mld = v1.join((mld,"', "))
# print mld[:-2]
# #easygui.msgbox(mld[:-2])
# Run the program
if __name__ == '__main__':
app = wx.PySimpleApp()
form = MyForm()
frame = form.Show()
app.MainLoop()
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
<mailto:wxpython-users@lists.wxwidgets.org>
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
------------------------------------------------------------------------
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users