forms
Reusable WPF forms for pyRevit.
Examples:
Attributes
mlogger = get_logger(__name__)
module-attribute
DEFAULT_CMDSWITCHWND_WIDTH = 600
module-attribute
DEFAULT_SEARCHWND_WIDTH = 600
module-attribute
DEFAULT_SEARCHWND_HEIGHT = 100
module-attribute
DEFAULT_INPUTWINDOW_WIDTH = 500
module-attribute
DEFAULT_INPUTWINDOW_HEIGHT = 600
module-attribute
DEFAULT_RECOGNIZE_ACCESS_KEY = False
module-attribute
WPF_HIDDEN = framework.Windows.Visibility.Hidden
module-attribute
WPF_COLLAPSED = framework.Windows.Visibility.Collapsed
module-attribute
WPF_VISIBLE = framework.Windows.Visibility.Visible
module-attribute
XAML_FILES_DIR = op.dirname(__file__)
module-attribute
ParamDef = namedtuple('ParamDef', ['name', 'istype', 'definition', 'isreadonly'])
module-attribute
Parameter definition tuple.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
parameter name |
istype |
bool
|
true if type parameter, otherwise false |
definition |
Definition
|
parameter definition object |
isreadonly |
bool
|
true if the parameter value can't be edited |
Classes
reactive(getter)
Bases: property
Decorator for WPF bound properties.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Functions
setter(setter)
Property setter.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Reactive
Bases: INotifyPropertyChanged
WPF property updator base mixin.
Functions
add_PropertyChanged(value)
remove_PropertyChanged(value)
OnPropertyChanged(prop_name)
Called when a property is changed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prop_name
|
str
|
property name |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
WindowToggler(window)
WPFWindow(xaml_source, literal_string=False, handle_esc=True, set_owner=True)
Bases: Window
WPF Window base class for all pyRevit forms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
xaml source filepath or xaml content |
required |
literal_string
|
bool
|
xaml_source contains xaml content, not filepath |
False
|
handle_esc
|
bool
|
handle Escape button and close the window |
True
|
set_owner
|
bool
|
set the owner of window to host app window |
True
|
Examples:
from pyrevit import forms
layout = '<Window ' \
'xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ' \
'xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ' \
'ShowInTaskbar="False" ResizeMode="NoResize" ' \
'WindowStartupLocation="CenterScreen" ' \
'HorizontalContentAlignment="Center">' \
'</Window>'
w = forms.WPFWindow(layout, literal_string=True)
w.show()
Initialize WPF window and resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
pyrevit_version
property
Active pyRevit formatted version e.g. '4.9-beta'.
Functions
load_xaml(xaml_source, literal_string=False, handle_esc=True, set_owner=True)
Load the window XAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
The XAML content or file path to load. |
required |
literal_string
|
bool
|
True if |
False
|
handle_esc
|
bool
|
Whether the ESC key should be handled. Defaults to True. |
True
|
set_owner
|
bool
|
Whether to se the window owner. Defaults to True. |
True
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
merge_resource_dict(xaml_source)
Merge a ResourceDictionary xaml file with this window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
xaml file with the resource dictionary |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
get_locale_string(string_name)
Get localized string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_name
|
str
|
string name |
required |
Returns:
Type | Description |
---|---|
str
|
localized string |
setup_owner()
setup_resources(wpf_ctrl)
staticmethod
Sets the WPF resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
setup_default_handlers()
handle_input_key(sender, args)
set_icon(icon_path)
setup_icon()
hide()
show(modal=False)
show_dialog()
set_image_source_file(wpf_element, image_file)
staticmethod
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
set_image_source(wpf_element, image_file)
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
dispatch(func, *args, **kwargs)
Runs the function in a new thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
function to run |
required |
*args
|
Any
|
positional arguments to pass to func |
()
|
**kwargs
|
Any
|
keyword arguments to pass to func |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
conceal()
hide_element(*wpf_elements)
staticmethod
Collapse elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be collaped |
()
|
show_element(*wpf_elements)
staticmethod
Show collapsed elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be set to visible. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
toggle_element(*wpf_elements)
staticmethod
Toggle visibility of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be toggled. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
disable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
enable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
handle_url_click(sender, args)
Callback for handling click on package website url.
WPFPanel()
Bases: Page
WPF panel base class for all pyRevit dockable panels.
panel_id (str) must be set on the type to dockable panel uuid panel_source (str): xaml source filepath
Examples:
from pyrevit import forms
class MyPanel(forms.WPFPanel):
panel_id = "181e05a4-28f6-4311-8a9f-d2aa528c8755"
panel_source = "MyPanel.xaml"
forms.register_dockable_panel(MyPanel)
# then from the button that needs to open the panel
forms.open_dockable_panel("181e05a4-28f6-4311-8a9f-d2aa528c8755")
Initialize WPF panel and resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
panel_id = None
class-attribute
instance-attribute
panel_source = None
class-attribute
instance-attribute
thread_id = framework.get_current_thread_id()
instance-attribute
Functions
set_image_source(wpf_element, image_file)
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
hide_element(*wpf_elements)
staticmethod
Collapse elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be collaped |
()
|
show_element(*wpf_elements)
staticmethod
Show collapsed elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be set to visible. |
()
|
toggle_element(*wpf_elements)
staticmethod
Toggle visibility of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be toggled. |
()
|
disable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
enable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list
|
WPF framework elements to be enabled |
()
|
handle_url_click(sender, args)
Callback for handling click on package website url.
TemplateUserInputWindow(context, title, width, height, **kwargs)
Bases: WPFWindow
Base class for pyRevit user input standard forms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
any
|
window context element(s) |
required |
title
|
str
|
window title |
required |
width
|
int
|
window width |
required |
height
|
int
|
window height |
required |
**kwargs
|
Any
|
other arguments to be passed to :func: |
{}
|
Initialize user input window.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
pyrevit_version
property
Active pyRevit formatted version e.g. '4.9-beta'.
xaml_source = 'BaseWindow.xaml'
class-attribute
instance-attribute
Title = title or 'pyRevit'
instance-attribute
Width = width
instance-attribute
Height = height
instance-attribute
response = None
instance-attribute
Owner = owner
instance-attribute
WindowStartupLocation = framework.Windows.WindowStartupLocation.CenterOwner
instance-attribute
Functions
load_xaml(xaml_source, literal_string=False, handle_esc=True, set_owner=True)
Load the window XAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
The XAML content or file path to load. |
required |
literal_string
|
bool
|
True if |
False
|
handle_esc
|
bool
|
Whether the ESC key should be handled. Defaults to True. |
True
|
set_owner
|
bool
|
Whether to se the window owner. Defaults to True. |
True
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
merge_resource_dict(xaml_source)
Merge a ResourceDictionary xaml file with this window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
xaml file with the resource dictionary |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
get_locale_string(string_name)
Get localized string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_name
|
str
|
string name |
required |
Returns:
Type | Description |
---|---|
str
|
localized string |
setup_owner()
setup_resources(wpf_ctrl)
staticmethod
Sets the WPF resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
setup_default_handlers()
handle_input_key(sender, args)
set_icon(icon_path)
setup_icon()
hide()
show_dialog()
set_image_source_file(wpf_element, image_file)
staticmethod
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
set_image_source(wpf_element, image_file)
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
dispatch(func, *args, **kwargs)
Runs the function in a new thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
function to run |
required |
*args
|
Any
|
positional arguments to pass to func |
()
|
**kwargs
|
Any
|
keyword arguments to pass to func |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
conceal()
hide_element(*wpf_elements)
staticmethod
Collapse elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be collaped |
()
|
show_element(*wpf_elements)
staticmethod
Show collapsed elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be set to visible. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
toggle_element(*wpf_elements)
staticmethod
Toggle visibility of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be toggled. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
disable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
enable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
handle_url_click(sender, args)
Callback for handling click on package website url.
show(context, title='User Input', width=DEFAULT_INPUTWINDOW_WIDTH, height=DEFAULT_INPUTWINDOW_HEIGHT, **kwargs)
classmethod
Show user input window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
any
|
window context element(s) |
required |
title
|
str
|
window title |
'User Input'
|
width
|
int
|
window width |
DEFAULT_INPUTWINDOW_WIDTH
|
height
|
int
|
window height |
DEFAULT_INPUTWINDOW_HEIGHT
|
**kwargs
|
any
|
other arguments to be passed to window |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
TemplateListItem(orig_item, checked=False, checkable=True, name_attr=None)
Bases: Reactive
Base class for checkbox option wrapping another object.
Initialize the checkbox option and wrap given obj.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
orig_item
|
any
|
Object to wrap (must have name property or be convertable to string with str() |
required |
checked
|
bool
|
Initial state. Defaults to False |
False
|
checkable
|
bool
|
Use checkbox for items |
True
|
name_attr
|
str
|
Get this attribute of wrapped object as name |
None
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
item = orig_item
instance-attribute
state = checked
instance-attribute
name
property
Name property.
checkable
property
writable
List Item CheckBox Visibility.
Functions
add_PropertyChanged(value)
remove_PropertyChanged(value)
OnPropertyChanged(prop_name)
Called when a property is changed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prop_name
|
str
|
property name |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
unwrap()
SelectFromList(context, title, width, height, **kwargs)
Bases: TemplateUserInputWindow
Standard form to select from a list of items.
Any object can be passed in a list to the context
argument. This class
wraps the objects passed to context, in TemplateListItem
.
This class provides the necessary mechanism to make this form work both
for selecting items from a list, and from a list of checkboxes. See the
list of arguments below for additional options and features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
list[str] or dict[list[str]]
|
list of items to be selected from OR dict of list of items to be selected from. use dict when input items need to be grouped e.g. List of sheets grouped by sheet set. |
required |
title
|
str
|
window title. see super class for defaults. |
required |
width
|
int
|
window width. see super class for defaults. |
required |
height
|
int
|
window height. see super class for defaults. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
button_name |
str
|
name of select button. defaults to 'Select' |
name_attr |
str
|
object attribute that should be read as item name. |
multiselect |
bool
|
allow multi-selection (uses check boxes). defaults to False |
info_panel |
bool
|
show information panel and fill with .description property of item |
return_all |
bool
|
return all items. This is handly when some input items have states and the script needs to check the state changes on all items. This options works in multiselect mode only. defaults to False |
filterfunc |
function
|
filter function to be applied to context items. |
resetfunc |
function
|
reset function to be called when user clicks on Reset button |
group_selector_title |
str
|
title for list group selector. defaults to 'List Group' |
default_group |
str
|
name of defautl group to be selected |
sort_groups |
str
|
Determines the sorting type applied to the list groups. This attribute can take one of the following values: 'sorted': This will sort the groups in standard alphabetical order 'natural': This will sort the groups in a manner that is more intuitive for human perception, especially when there are numbers involved. 'unsorted': The groups will maintain the original order in which they were provided, without any reordering. Defaults to 'sorted'. |
Examples:
from pyrevit import forms
items = ['item1', 'item2', 'item3']
forms.SelectFromList.show(items, button_name='Select Item')
['item1']
from pyrevit import forms
ops = [viewsheet1, viewsheet2, viewsheet3]
res = forms.SelectFromList.show(ops,
multiselect=False,
name_attr='Name',
button_name='Select Sheet')
from pyrevit import forms
ops = {'Sheet Set A': [viewsheet1, viewsheet2, viewsheet3],
'Sheet Set B': [viewsheet4, viewsheet5, viewsheet6]}
res = forms.SelectFromList.show(ops,
multiselect=True,
name_attr='Name',
group_selector_title='Sheet Sets',
button_name='Select Sheets',
sort_groups='sorted')
This module also provides a wrapper base class :obj:TemplateListItem
for when the checkbox option is wrapping another element,
e.g. a Revit ViewSheet. Derive from this base class and define the
name property to customize how the checkbox is named on the dialog.
from pyrevit import forms
class MyOption(forms.TemplateListItem):
@property
def name(self):
return '{} - {}{}'.format(self.item.SheetNumber,
self.item.SheetNumber)
ops = [MyOption('op1'), MyOption('op2', True), MyOption('op3')]
res = forms.SelectFromList.show(ops,
multiselect=True,
button_name='Select Item')
[bool(x) for x in res] # or [x.state for x in res]
[True, False, True]
Initialize user input window.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
pyrevit_version
property
Active pyRevit formatted version e.g. '4.9-beta'.
Title = title or 'pyRevit'
instance-attribute
Width = width
instance-attribute
Height = height
instance-attribute
response = None
instance-attribute
Owner = owner
instance-attribute
WindowStartupLocation = framework.Windows.WindowStartupLocation.CenterOwner
instance-attribute
in_check = False
class-attribute
instance-attribute
in_uncheck = False
class-attribute
instance-attribute
xaml_source = 'SelectFromList.xaml'
class-attribute
instance-attribute
use_regex
property
Is using regex?
Functions
load_xaml(xaml_source, literal_string=False, handle_esc=True, set_owner=True)
Load the window XAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
The XAML content or file path to load. |
required |
literal_string
|
bool
|
True if |
False
|
handle_esc
|
bool
|
Whether the ESC key should be handled. Defaults to True. |
True
|
set_owner
|
bool
|
Whether to se the window owner. Defaults to True. |
True
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
merge_resource_dict(xaml_source)
Merge a ResourceDictionary xaml file with this window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
xaml file with the resource dictionary |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
get_locale_string(string_name)
Get localized string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_name
|
str
|
string name |
required |
Returns:
Type | Description |
---|---|
str
|
localized string |
setup_owner()
setup_resources(wpf_ctrl)
staticmethod
Sets the WPF resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
setup_default_handlers()
handle_input_key(sender, args)
set_icon(icon_path)
setup_icon()
hide()
show(context, title='User Input', width=DEFAULT_INPUTWINDOW_WIDTH, height=DEFAULT_INPUTWINDOW_HEIGHT, **kwargs)
classmethod
Show user input window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
any
|
window context element(s) |
required |
title
|
str
|
window title |
'User Input'
|
width
|
int
|
window width |
DEFAULT_INPUTWINDOW_WIDTH
|
height
|
int
|
window height |
DEFAULT_INPUTWINDOW_HEIGHT
|
**kwargs
|
any
|
other arguments to be passed to window |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
show_dialog()
set_image_source_file(wpf_element, image_file)
staticmethod
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
set_image_source(wpf_element, image_file)
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
dispatch(func, *args, **kwargs)
Runs the function in a new thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
function to run |
required |
*args
|
Any
|
positional arguments to pass to func |
()
|
**kwargs
|
Any
|
keyword arguments to pass to func |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
conceal()
hide_element(*wpf_elements)
staticmethod
Collapse elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be collaped |
()
|
show_element(*wpf_elements)
staticmethod
Show collapsed elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be set to visible. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
toggle_element(*wpf_elements)
staticmethod
Toggle visibility of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be toggled. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
disable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
enable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
handle_url_click(sender, args)
Callback for handling click on package website url.
toggle_all(sender, args)
check_all(sender, args)
uncheck_all(sender, args)
check_selected(sender, args)
Mark selected checkboxes as checked.
Source code in pyrevitlib/pyrevit/forms/__init__.py
uncheck_selected(sender, args)
Mark selected checkboxes as unchecked.
Source code in pyrevitlib/pyrevit/forms/__init__.py
button_reset(sender, args)
button_select(sender, args)
search_txt_changed(sender, args)
Handle text change in search box.
Source code in pyrevitlib/pyrevit/forms/__init__.py
selection_changed(sender, args)
selected_item_changed(sender, args)
Handle selected item change.
Source code in pyrevitlib/pyrevit/forms/__init__.py
toggle_regex(sender, args)
Activate regex in search.
Source code in pyrevitlib/pyrevit/forms/__init__.py
CommandSwitchWindow(context, title, width, height, **kwargs)
Bases: TemplateUserInputWindow
Standard form to select from a list of command options.
Other Parameters:
Name | Type | Description |
---|---|---|
context |
list[str]
|
list of command options to choose from |
switches |
list[str]
|
list of on/off switches |
message |
str
|
window title message |
config |
dict
|
dictionary of config dicts for options or switches |
recognize_access_key |
bool
|
recognize '_' as mark of access key |
Returns:
Type | Description |
---|---|
str | tuple[str, dict]
|
name of selected option.
if |
Examples:
This is an example with series of command options:
from pyrevit import forms
ops = ['option1', 'option2', 'option3', 'option4']
forms.CommandSwitchWindow.show(ops, message='Select Option')
'option2'
A more advanced example of combining command options, on/off switches, and option or switch configuration options:
from pyrevit import forms
ops = ['option1', 'option2', 'option3', 'option4']
switches = ['switch1', 'switch2']
cfgs = {'option1': { 'background': '0xFF55FF'}}
rops, rswitches = forms.CommandSwitchWindow.show(
ops,
switches=switches
message='Select Option',
config=cfgs,
recognize_access_key=False
)
rops
'option2'
rswitches
{'switch1': False, 'switch2': True}
Initialize user input window.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
pyrevit_version
property
Active pyRevit formatted version e.g. '4.9-beta'.
Title = title or 'pyRevit'
instance-attribute
Width = width
instance-attribute
Height = height
instance-attribute
response = None
instance-attribute
Owner = owner
instance-attribute
WindowStartupLocation = framework.Windows.WindowStartupLocation.CenterOwner
instance-attribute
xaml_source = 'CommandSwitchWindow.xaml'
class-attribute
instance-attribute
Functions
load_xaml(xaml_source, literal_string=False, handle_esc=True, set_owner=True)
Load the window XAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
The XAML content or file path to load. |
required |
literal_string
|
bool
|
True if |
False
|
handle_esc
|
bool
|
Whether the ESC key should be handled. Defaults to True. |
True
|
set_owner
|
bool
|
Whether to se the window owner. Defaults to True. |
True
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
merge_resource_dict(xaml_source)
Merge a ResourceDictionary xaml file with this window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
xaml file with the resource dictionary |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
get_locale_string(string_name)
Get localized string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_name
|
str
|
string name |
required |
Returns:
Type | Description |
---|---|
str
|
localized string |
setup_owner()
setup_resources(wpf_ctrl)
staticmethod
Sets the WPF resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
setup_default_handlers()
set_icon(icon_path)
setup_icon()
hide()
show(context, title='User Input', width=DEFAULT_INPUTWINDOW_WIDTH, height=DEFAULT_INPUTWINDOW_HEIGHT, **kwargs)
classmethod
Show user input window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
any
|
window context element(s) |
required |
title
|
str
|
window title |
'User Input'
|
width
|
int
|
window width |
DEFAULT_INPUTWINDOW_WIDTH
|
height
|
int
|
window height |
DEFAULT_INPUTWINDOW_HEIGHT
|
**kwargs
|
any
|
other arguments to be passed to window |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
show_dialog()
set_image_source_file(wpf_element, image_file)
staticmethod
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
set_image_source(wpf_element, image_file)
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
dispatch(func, *args, **kwargs)
Runs the function in a new thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
function to run |
required |
*args
|
Any
|
positional arguments to pass to func |
()
|
**kwargs
|
Any
|
keyword arguments to pass to func |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
conceal()
hide_element(*wpf_elements)
staticmethod
Collapse elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be collaped |
()
|
show_element(*wpf_elements)
staticmethod
Show collapsed elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be set to visible. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
toggle_element(*wpf_elements)
staticmethod
Toggle visibility of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be toggled. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
disable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
enable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
handle_url_click(sender, args)
Callback for handling click on package website url.
handle_click(sender, args)
handle_input_key(sender, args)
Handle keyboard inputs.
Source code in pyrevitlib/pyrevit/forms/__init__.py
search_txt_changed(sender, args)
process_option(sender, args)
GetValueWindow(context, title, width, height, **kwargs)
Bases: TemplateUserInputWindow
Standard form to get simple values from user.
Examples:
from pyrevit import forms
items = ['item1', 'item2', 'item3']
forms.SelectFromList.show(items, button_name='Select Item')
['item1']
Initialize user input window.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
pyrevit_version
property
Active pyRevit formatted version e.g. '4.9-beta'.
Title = title or 'pyRevit'
instance-attribute
Width = width
instance-attribute
Height = height
instance-attribute
response = None
instance-attribute
Owner = owner
instance-attribute
WindowStartupLocation = framework.Windows.WindowStartupLocation.CenterOwner
instance-attribute
xaml_source = 'GetValueWindow.xaml'
class-attribute
instance-attribute
Functions
load_xaml(xaml_source, literal_string=False, handle_esc=True, set_owner=True)
Load the window XAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
The XAML content or file path to load. |
required |
literal_string
|
bool
|
True if |
False
|
handle_esc
|
bool
|
Whether the ESC key should be handled. Defaults to True. |
True
|
set_owner
|
bool
|
Whether to se the window owner. Defaults to True. |
True
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
merge_resource_dict(xaml_source)
Merge a ResourceDictionary xaml file with this window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
xaml file with the resource dictionary |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
get_locale_string(string_name)
Get localized string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_name
|
str
|
string name |
required |
Returns:
Type | Description |
---|---|
str
|
localized string |
setup_owner()
setup_resources(wpf_ctrl)
staticmethod
Sets the WPF resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
setup_default_handlers()
handle_input_key(sender, args)
set_icon(icon_path)
setup_icon()
hide()
show(context, title='User Input', width=DEFAULT_INPUTWINDOW_WIDTH, height=DEFAULT_INPUTWINDOW_HEIGHT, **kwargs)
classmethod
Show user input window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
any
|
window context element(s) |
required |
title
|
str
|
window title |
'User Input'
|
width
|
int
|
window width |
DEFAULT_INPUTWINDOW_WIDTH
|
height
|
int
|
window height |
DEFAULT_INPUTWINDOW_HEIGHT
|
**kwargs
|
any
|
other arguments to be passed to window |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
show_dialog()
set_image_source_file(wpf_element, image_file)
staticmethod
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
set_image_source(wpf_element, image_file)
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
dispatch(func, *args, **kwargs)
Runs the function in a new thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
function to run |
required |
*args
|
Any
|
positional arguments to pass to func |
()
|
**kwargs
|
Any
|
keyword arguments to pass to func |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
conceal()
hide_element(*wpf_elements)
staticmethod
Collapse elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be collaped |
()
|
show_element(*wpf_elements)
staticmethod
Show collapsed elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be set to visible. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
toggle_element(*wpf_elements)
staticmethod
Toggle visibility of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be toggled. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
disable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
enable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
handle_url_click(sender, args)
Callback for handling click on package website url.
string_value_changed(sender, args)
Handle string vlaue update event.
Source code in pyrevitlib/pyrevit/forms/__init__.py
select(sender, args)
Process input data and set the response.
Source code in pyrevitlib/pyrevit/forms/__init__.py
TemplatePromptBar(height=32, **kwargs)
Bases: WPFWindow
Template context-manager class for creating prompt bars.
Prompt bars are show at the top of the active Revit window and are designed for better prompt visibility.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
height
|
int
|
window height |
32
|
**kwargs
|
Any
|
other arguments to be passed to :func: |
{}
|
Initialize user prompt window.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
pyrevit_version
property
Active pyRevit formatted version e.g. '4.9-beta'.
xaml_source = 'TemplatePromptBar.xaml'
class-attribute
instance-attribute
user_height = height
instance-attribute
Functions
load_xaml(xaml_source, literal_string=False, handle_esc=True, set_owner=True)
Load the window XAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
The XAML content or file path to load. |
required |
literal_string
|
bool
|
True if |
False
|
handle_esc
|
bool
|
Whether the ESC key should be handled. Defaults to True. |
True
|
set_owner
|
bool
|
Whether to se the window owner. Defaults to True. |
True
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
merge_resource_dict(xaml_source)
Merge a ResourceDictionary xaml file with this window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
xaml file with the resource dictionary |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
get_locale_string(string_name)
Get localized string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_name
|
str
|
string name |
required |
Returns:
Type | Description |
---|---|
str
|
localized string |
setup_owner()
setup_resources(wpf_ctrl)
staticmethod
Sets the WPF resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
setup_default_handlers()
handle_input_key(sender, args)
set_icon(icon_path)
setup_icon()
hide()
show(modal=False)
show_dialog()
set_image_source_file(wpf_element, image_file)
staticmethod
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
set_image_source(wpf_element, image_file)
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
dispatch(func, *args, **kwargs)
Runs the function in a new thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
function to run |
required |
*args
|
Any
|
positional arguments to pass to func |
()
|
**kwargs
|
Any
|
keyword arguments to pass to func |
{}
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
conceal()
hide_element(*wpf_elements)
staticmethod
Collapse elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be collaped |
()
|
show_element(*wpf_elements)
staticmethod
Show collapsed elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be set to visible. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
toggle_element(*wpf_elements)
staticmethod
Toggle visibility of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be toggled. |
()
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
disable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
enable_element(*wpf_elements)
staticmethod
Enable elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*wpf_elements
|
list[UIElement]
|
WPF framework elements to be enabled |
()
|
handle_url_click(sender, args)
Callback for handling click on package website url.
update_window()
Update the prompt bar to match Revit window.
Source code in pyrevitlib/pyrevit/forms/__init__.py
WarningBar(height=32, **kwargs)
Bases: TemplatePromptBar
Show warning bar at the top of Revit window.
Other Parameters:
Name | Type | Description |
---|---|---|
title |
string
|
warning bar text |
Examples:
Initialize user prompt window.
Source code in pyrevitlib/pyrevit/forms/__init__.py
Attributes
pyrevit_version
property
Active pyRevit formatted version e.g. '4.9-beta'.
user_height = height
instance-attribute
xaml_source = 'WarningBar.xaml'
class-attribute
instance-attribute
Functions
load_xaml(xaml_source, literal_string=False, handle_esc=True, set_owner=True)
Load the window XAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
The XAML content or file path to load. |
required |
literal_string
|
bool
|
True if |
False
|
handle_esc
|
bool
|
Whether the ESC key should be handled. Defaults to True. |
True
|
set_owner
|
bool
|
Whether to se the window owner. Defaults to True. |
True
|
Source code in pyrevitlib/pyrevit/forms/__init__.py
merge_resource_dict(xaml_source)
Merge a ResourceDictionary xaml file with this window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xaml_source
|
str
|
xaml file with the resource dictionary |
required |
Source code in pyrevitlib/pyrevit/forms/__init__.py
get_locale_string(string_name)
Get localized string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_name
|
str
|
string name |
required |
Returns:
Type | Description |
---|---|
str
|
localized string |
setup_owner()
setup_resources(wpf_ctrl)
staticmethod
Sets the WPF resources.
Source code in pyrevitlib/pyrevit/forms/__init__.py
setup_default_handlers()
handle_input_key(sender, args)
set_icon(icon_path)
setup_icon()
hide()
show(modal=False)
show_dialog()
set_image_source_file(wpf_element, image_file)
staticmethod
Set source file for image element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wpf_element
|
Image
|
xaml image element |
required |
image_file
|
str
|
image file path |
required |