本文整理汇总了Python中toolkit.toolkit函数的典型用法代码示例。如果您正苦于以下问题:Python toolkit函数的具体用法?Python toolkit怎么用?Python toolkit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toolkit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _timer_pop
def _timer_pop(self):
""" Handles the timer popping.
"""
ui = self.ui
control = ui.control
if control is None:
# Looks like someone forgot to tell us that the ui has been closed:
self.stop()
return
# Make sure that the initial distance of the mouse pointer to the
# control has been set:
mx, my = toolkit().mouse_position()
if self.mouse is None:
self.mouse = (mx, my)
self.distance = self._distance(mx, my)
if self.is_activated:
# Don't close the popup if any mouse buttons are currently pressed:
if len(toolkit().mouse_buttons()) > 0:
return
# Check for the special case of the mouse pointer having to be
# within the original bounds of the object the popup was created
# for:
if self.is_info:
parent = control._parent
if isinstance(parent, tuple):
px, py, pdx, pdy = parent
else:
px, py = parent.screen_position
pdx, pdy = parent.size
if (mx < px) or (mx >= (px + pdx)) or (my < py) or (my >= (py + pdy)):
do_later(ui.owner.close_popup)
self.is_activated = False
else:
# Allow for a 'dead zone' border around the window to allow for
# small motor control problems:
if self._distance(mx, my) > self.border:
control_at = toolkit().control_at(mx, my)
while control_at is not None:
if control_at is control:
return
control_at = control_at.parent
do_later(ui.owner.close_popup)
self.is_activated = False
else:
distance = self._distance(mx, my)
if distance == 0:
# If the pointer is now in the popup view, activate it:
self.is_activated = True
elif distance > (self.distance + 25):
# If the mouse has moved too far away from the popup view, then
# close it:
do_later(ui.owner.close_popup)
示例2: dispose
def dispose ( self ):
""" Disposes of the contents of a user interface.
"""
# Save the user preference information for the user interface:
toolkit().save_window( self )
# Finish disposing of the user interface:
self.finish()
示例3: prepare_ui
def prepare_ui ( self ):
""" Performs all processing that occurs after the user interface is
created.
"""
# Invoke all of the editor 'name_defined' methods we've accumulated:
info = self.info
for method in self._defined:
method( info )
# Then reset the list, since we don't need it anymore:
del self._defined[:]
# Hook all events if the handler is an extended 'ViewHandler':
handler = self.handler
if isinstance( handler, ViewHandler ):
toolkit().hook_events( self, self.control )
# Invoke the handler's 'init' method, and abort if it indicates failure:
if handler.init( info ) == False:
raise TraitError, 'User interface creation aborted'
# For each Handler method whose name is of the form
# 'object_name_changed', where 'object' is the name of an object in the
# UI's 'context', create a trait notification handler that will call
# the method whenever 'object's 'name' trait changes. Also invoke the
# method immediately so initial user interface state can be correctly
# set:
context = self.context
for name in self._each_trait_method( handler ):
if name[-8:] == '_changed':
prefix = name[:-8]
col = prefix.find( '_', 1 )
if col >= 0:
object = context.get( prefix[ : col ] )
if object is not None:
method = getattr( handler, name )
trait_name = prefix[ col + 1: ]
self._dispatchers.append( Dispatcher(
method, info, object, trait_name ) )
if object.base_trait( trait_name ).type != 'event':
method( info )
# If there are any Editor object's whose 'visible', 'enabled' or
# 'checked' state is controlled by a 'visible_when', 'enabled_when' or
# 'checked_when' expression, set up an 'anytrait' changed notification
# handler on each object in the 'context' that will cause the 'visible',
# 'enabled' or 'checked' state of each affected Editor to be set. Also
# trigger the evaluation immediately, so the visible, enabled or checked
# state of each Editor can be correctly initialized:
if (len( self._visible ) +
len( self._enabled ) +
len( self._checked )) > 0:
for object in context.values():
object.on_trait_change( self._evaluate_when, dispatch = 'ui' )
self._evaluate_when()
# Indicate that the user interface has been initialized:
info.initialized = True
示例4: dispose
def dispose ( self, result = None, abort = False ):
""" Disposes of the contents of a user interface.
"""
# Save the user preference information for the user interface:
if not abort:
toolkit().save_window( self )
# Finish disposing of the user interface:
self.finish( result )
示例5: set_error_state
def set_error_state ( self, state = None, control = None ):
""" Sets the editor's current error state.
"""
from facets.ui.colors import OKColor, ErrorColor
state = self.get_error_state( state )
if control is None:
control = self.get_error_control()
controls = control
if not isinstance( control, list ):
controls = [ control ]
for control in controls:
# fixme: Eventually this code should not be necessary...
control = toolkit().as_toolkit_adapter( control )
ui_control = control()
if state:
color = ErrorColor
if getattr( ui_control, '_ok_color', None ) is None:
ui_control._ok_color = control.background_color
else:
color = getattr( ui_control, '_ok_color', None )
if color is None:
color = OKColor
if control.is_panel:
color = WindowColor
control.background_color = color
control.refresh()
示例6: CodeEditor
def CodeEditor(*args, **facets):
""" Allows the user to edit a multi-line string.
The "simple" and "custom" styles of this editor display multiple lines
of the string, with line numbers.
"""
return toolkit().code_editor(*args, **facets)
示例7: init
def init(self, parent):
""" Finishes initializing the editor by creating the underlying toolkit
widget.
"""
if (self.item.resizable is True) or (self.item.height != -1.0):
self.adapter = (
toolkit()
.create_text_input(parent, read_only=True, multi_line=True)
.set(value=self.str_value, background_color=WindowColor)
)
else:
self.adapter = toolkit().create_label(parent).set(value=self.str_value)
# fixme: How to do this in GUI toolkit neutral manner?...
###self.layout_style = 0
self.set_tooltip()
示例8: CheckListEditor
def CheckListEditor ( *args, **traits ):
""" Allows the user to select zero, one, or more values from a finite set of
possibilities.
Note that the "simple" style is limited to selecting a single value.
"""
return toolkit().check_list_editor( *args, **traits )
示例9: TextEditor
def TextEditor ( *args, **traits ):
""" Allows the user to modify a text string.
The string value entered by the user is coerced to the appropriate type
for the trait attribute being modified.
"""
return toolkit().text_editor( *args, **traits )
示例10: ListEditor
def ListEditor(*args, **facets):
""" Allows the user to modify a list of values.
The user can add, delete, or reorder items, or change the content of
items.
"""
return toolkit().list_editor(*args, **facets)
示例11: _label_control_set
def _label_control_set ( self, control ):
""" Handles the 'label_control' facet being changed.
"""
if control is None:
self.label_adapter = None
elif ((self.label_adapter is None) or
(self.label_adapter() is not control)):
self.label_adapter = toolkit().control_adapter_for( control )
示例12: _control_set
def _control_set ( self, control ):
""" Handles the 'control' facet being changed.
"""
if control is None:
self.adapter = None
elif (self.adapter is None) or (self.adapter() is not control):
self.adapter = toolkit().adapter_for( control )
control._editor = self
示例13: ui
def ui ( self, parent, kind ):
""" Creates a user interface from the associated View template object.
"""
if (parent is None) and (kind in kind_must_have_parent):
kind = 'live'
self.rebuild = getattr( toolkit(), 'ui_' + kind )
self.rebuild( self, parent )
self.view.on_trait_change( self._updated_changed, 'updated',
dispatch = 'ui' )
示例14: EnumEditor
def EnumEditor(*args, **facets):
""" Allows the user to select a single value from an enumerated list of
values.
"""
# from facets.ui.editors.enum_editor import EnumEditor
#
# return EnumEditor( *args, **facets )
return toolkit().enum_editor(*args, **facets)
示例15: facets_init
def facets_init(self):
""" Completes the initialization of the object.
"""
kind = self.ui.view.kind
self.is_activated = self.is_info = kind == "info"
if kind == "popup":
self.border = 10
self.timer = toolkit().create_timer(100, self._timer_pop)