Float Slider

Do you have questions about writing plugins or scripts in Python? Meet the coders here.

Float Slider

Postby kgschlosser » Thu Oct 27, 2016 7:20 pm

ok Ladies & Gents

I made this really cool slider control. it allows for using floats for one. but you can also use it for an Int it's just going to display and return a float and you would have the do the conversion afterwards

FS1.jpg
FS1.jpg (3.7 KiB) Viewed 348 times

FS2.jpg
FS2.jpg (3.92 KiB) Viewed 348 times



but this is how it works. Now i think you should be able to just download the file and drop it right into your eventghost\eg\Classes folder. tho I have not tested this. and if not you would have to put it somewhere accessible and do an import. now because it has not been added to the ControlProviderMixin for config dialogs you will not be able to do panel.FloatSliderCtrl(). You will always have to call it from eg and pass the instance of panel to it. like so eg.FloatSliderCtrl(panel......)

this is the use of the control

Code: Select all
eg.FloatSliderCtrl(
    self,
    parent,
    id=-1,
    value=-1,
    minValue=-1,
    maxValue=100.0,
    pos=wx.DefaultPosition,
    size=wx.DefaultSize,
    style=wx.SL_HORIZONTAL,
    validator=wx.DefaultValidator,
    name=wx.SliderNameStr,
    **kwargs
)


parent = the controlling wx.Window class
id = a wx id, -1 being a new Id and it is defaulted to that
value = the startup value you want the slider to default to. if you provide a minValue and do not provide a value it will automatically set the value at the minValue.
minValue = the lowest you want the slider to go. if you do not set the minValue it defaults to 0.0
maxValue = the highest you want the slider to go. if you do not set the maxValue it defaults to 100.0
pos = the position you want the widget to be placed
size = the size of the widget. I have found that if you have the value and min/max labels turned on in Horizontal display mode you will need to set the height to 80 (depending on the font you set for the widget) and for vertical you will need to set the width to 110 if you leave the size as a default it will automatically set the sizes to fit the entire control
style = uses the standard wx.SliderCtrl styles. and they are

wx.SL_HORIZONTAL, will automatically display tick marks on the bottom if tick marks are turned on
wx.SL_VERTICAL, will automatically display tick marks on the right if tick marks are turned on

all below are which way to have the gripper on the slider point as well as where to display the tick marks if turned on
wx.SL_TOP
wx.SL_BOTTOM
wx.SL_RIGHT
wx.SL_LEFT

wx.SL_AUTOTICKS, display the tick marks
wx.SL_LABELS, display the min/max labels as well as the value labels
wx.SL_MIN_MAX_LABELS, display only the min/max labels
wx.SL_VALUE_LABEL, display only the value label

wx.SL_INVERSE, reverse the slider control direction

if you add the keyword increment=0.01 this will move the slider at "steps" of 0.01
if you do not use the increment keyword it will use a formula to come up with one.

to get events from this control you would do as follows (this is pseudo code)

Code: Select all
def Configure(self, val):
    panel = eg.ConfigPanel()
    sliderCtrl = eg.FloatSliderCtrl(
        panel,
        value=val,
        minValue=1.0,
        maxValue=100.0,
        increment=0.1,
        style=(
            wx.SL_HORIZONTAL |
            wx.SL_BOTTOM |
            wx.SL_LABELS |
            wx.SL_AUTOTICKS
        )
    )
   
    panel.sizer.Add(sliderCtrl, 0, wx.EXPAND)
    sliderCtrl.Bind(wx.EVT_SCROLL, self.OnScroll)
   
    while panel.Affirmed():
        panel.SetResult(sliderCtrl.GetValue())
       
def OnScroll(self, event):
    sliderCtrl = event.GetEventObject()
    value = sliderCtrl.GetValue()
    event.Skip()



available methods
GetValue()
GetMin()
GetMax()
GetIncrement()
GetSelStart()
GetSelEnd()
GetLineSize()
GetPageSize()
GetThumbLength()
GetTickFreq()

IsInverse()
IsMinMaxLabel()
IsValueLabel()

SetLineSize(lineSize)
SetPageSize(pageSize)
SetSelection(startPos, endPos)
SetThumbLength(len)
SetTick(tickPos)
SetTickFreq(n)
SetValue(value)
SetMin(min)
SetMax(max)
SetIncrement(increment)
SetRange(min, max)
SetMinMaxLabel(flag=True)
SetValueLabel(flag=True)


the file is attached
Attachments
FloatSliderCtrl.py
(12.02 KiB) Downloaded 32 times
A loved one and Time, The 2 things that can never be replaced.

Family, The only thing you don't get to choose in life.
User avatar
kgschlosser
Site Admin
 
Posts: 1378
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Return to Coding Corner

Who is online

Users browsing this forum: No registered users and 2 guests