1

In widgets like the spinctrl or slider box, properties like the inital position, min and max values etc can be set to constants. Is there any way by which they can be specified as variables.

so the code

self.HDSpin = wx.SpinCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 10, 0 )

becomes

self.HDSpin = wx.SpinCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, params.minv, params.maxv, params.defaultv )

This will allow the parameters to be set at run time just before the dialog is shown.

staticd
  • 1,194
  • 9
  • 13

2 Answers2

0

Yes, just use variables like you would in a normal(non wxpython) python method.

Yoriz
  • 3,595
  • 2
  • 13
  • 20
  • wxformbuilder accepts only numers in the properties dialogs.. currently I give them constants some specific numbers for each variable.. eg `x` as `12301`. `y` as `12302` etc. Then I use a bash script with sed to add in the variables to the autogenerated file. – staticd Jul 11 '13 at 13:47
  • In that case it is a limitation of wxformbuilder, you will have to alter the code that it spits out or make a request to the developers that they add to its functionality. – Yoriz Jul 12 '13 at 12:20
0

As a workaround, in place of each variable enter a unique number: eg: 123401,123402,123403 etc. Once the "gui.py" autogenerated file is created, run a script with sed that replaces each number with the corresponding variable. I use the same to make the default strings runtime determined as opposed to hardcoded. With strvar01,strvar02 in the default string textboxes

#!/bin/bash

FILE="gui.py"

sed -i 's/123401/HDMin/g' "$FILE"
sed -i 's/123402/HDDefault/g' "$FILE"
sed -i 's/123403/HDMax/g' "$FILE"
sed -i 's/u"strvar01"/DefaultStr1/g' "$FILE"

so the auto-generated code self.Label1 = wx.StaticText(..., u"strvar01", ... )

becomes: self.Label1 = wx.StaticText(...,DefaultStr1, ... )

where the value of DefaultStr1 is set at runtime

staticd
  • 1,194
  • 9
  • 13