Skip to content

Commit

Permalink
Forms getvaluewindow slider (#1247)
Browse files Browse the repository at this point in the history
* fixed host adder and added 2020.2.3

* added 2020.1.1 to hosts

* Added slider panel with number display to GetValueWindow class in pyrevit.forms with new forms function ask_for_number_slider

Co-authored-by: Ehsan Iran-Nejad <eirannejad@gmail.com>
  • Loading branch information
alexdaversa and eirannejad authored Jun 21, 2021
1 parent 71df181 commit e0d28b3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pyrevitlib/pyrevit/forms/GetValueWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@
Style="{DynamicResource CustomDatePickerStyle}" />
</StackPanel>
</DockPanel>
<DockPanel x:Name="sliderPanel_sp" Margin="10" Visibility="Collapsed">
<TextBlock x:Name="sliderPrompt" Text="Pick a number" DockPanel.Dock="Top"/>
<StackPanel DockPanel.Dock="Top">
<TextBox Text="{Binding ElementName=numberPicker, Path=Value, UpdateSourceTrigger=PropertyChanged}"
DockPanel.Dock="Right" TextAlignment="Center" Width="60"
FontFamily="Courier New" FontSize="24" FontWeight="Bold"
BorderThickness="0" Margin="0 10 0 0" />
<Slider x:Name="numberPicker"
Height="36"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
FontFamily="Courier New" FontSize="24" FontWeight="Bold"
Value="50" Minimum="0" Maximum="200"
SmallChange="5" LargeChange="10"
TickPlacement="None" TickFrequency="5" IsSnapToTickEnabled="True"
Margin="0 10 0 0"
Padding="10,0,10,0" />
</StackPanel>
</DockPanel>
<Button x:Name="okayButton" Content="OK" Margin="10" Click="select" IsDefault="True" Height="24"/>
</StackPanel>
</Window>
44 changes: 44 additions & 0 deletions pyrevitlib/pyrevit/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,8 @@ def _setup(self, **kwargs):
value_prompt = kwargs.get('prompt', None)
value_default = kwargs.get('default', None)
self.reserved_values = kwargs.get('reserved_values', [])
value_max = kwargs.get('max', 100)
value_min = kwargs.get('min', 0)

# customize window based on type
if self.value_type == 'string':
Expand All @@ -1213,6 +1215,12 @@ def _setup(self, **kwargs):
self.show_element(self.datePanel_dp)
self.datePrompt.Text = \
value_prompt if value_prompt else 'Pick date:'
elif self.value_type == 'slider':
self.show_element(self.sliderPanel_sp)
self.sliderPrompt.Text = value_prompt
self.numberPicker.Minimum = value_min
self.numberPicker.Maximum = value_max
self.numberPicker.Value = value_default if value_default else self.numberPicker.Value.MaximizeValue

def string_value_changed(self, sender, args): #pylint: disable=unused-argument
"""Handle string vlaue update event."""
Expand Down Expand Up @@ -1247,6 +1255,8 @@ def select(self, sender, args): #pylint: disable=W0613
self.response = datetime.datetime.strptime(datestr, r'%m/%d/%Y')
else:
self.response = None
elif self.value_type == 'slider':
self.response = self.numberPicker.Value


class TemplatePromptBar(WPFWindow):
Expand Down Expand Up @@ -3200,6 +3210,40 @@ def ask_for_date(default=None, prompt=None, title=None, **kwargs):
)


def ask_for_number_slider(default=None, prompt=None, title=None, **kwargs):
"""Ask user to select a number value.
This is a shortcut function that configures :obj:`GetValueWindow` for
numbers. kwargs can be used to pass on other arguments.
Args:
default (str): default unique string. must not be in reserved_values
prompt (str): prompt message
title (str): title message
kwargs (type): other arguments to be passed to :obj:`GetValueWindow`
Returns:
str: selected string value
Example:
>>> forms.ask_for_string(
... default=50,
... min = 0
... max = 100
... prompt='Select a number:',
... title='test title')
... '50'
"""
return GetValueWindow.show(
None,
value_type='slider',
default=default,
prompt=prompt,
title=title,
**kwargs
)


def ask_to_use_selected(type_name, count=None, multiple=True):
"""Ask user if wants to use currently selected elements.
Expand Down

0 comments on commit e0d28b3

Please sign in to comment.