class LabelItalicFontCommand(AbstractCommand): """ The LabelNormalFontCommand class is a command that sets an italic font for a label's text. """ #### 'ICommand' interface ################################################# # The data being operated on. data = Instance(Label) # The name of the command. name = Unicode("&Italic font") ########################################################################### # 'ICommand' interface. ########################################################################### def do(self): # Save the old value. self._saved = self.data.style # Calling redo() is a convenient way to update the model now that the # old value is saved. self.redo() def redo(self): self.data.style = 'italic' def undo(self): self.data.style = self._saved
class IWizard(IDialog): """ The interface for all pyface wizards. """ #### 'IWizard' interface ################################################## # The pages in the wizard. pages = List(IWizardPage) # The wizard controller provides the pages displayed in the wizard, and # determines when the wizard is complete etc. controller = Instance(IWizardController) # Should the 'Cancel' button be displayed? show_cancel = Bool(True) #### 'IWindow' interface ################################################## # The dialog title. title = Unicode('Wizard') ########################################################################### # 'IWizard' interface. ########################################################################### def next(self): """ Advance to the next page in the wizard. """ def previous(self): """ Return to the previous page in the wizard. """
class ManagePolicyPermission(Permission): """The standard permission for managing permissions policies.""" #### 'Permission' interface ############################################### id = Str('ets.permissions.manage_policy') description = Unicode(u"Manage permissions policy") bootstrap = Bool(True)
class ManageUsersPermission(Permission): """The standard permission for managing permissions users.""" #### 'Permission' interface ############################################### id = Str('ets.permissions.manage_users') description = Unicode(u"Manage users") bootstrap = Bool(True)
class AcmeUIPreferencesHelper(PreferencesHelper): """ A helper! """ # The path to the preferences node that contains our preferences. preferences_path = 'acme.ui' # The traits that we want to initialize from preferences. bgcolor = Str('blue') width = Int(50) ratio = Float(1.0) visible = Bool(True) description = Unicode(u'description') offsets = List(Int, [1, 2, 3, 4]) names = List(Str, ['joe', 'fred', 'jane'])
class LoginAction(Action): """An action that authenticates the current user.""" #### 'Action' interface ################################################### name = Unicode("Log&in...") ########################################################################### # 'Action' interface. ########################################################################### def perform(self, event): """Perform the action.""" get_permissions_manager().user_manager.authenticate_user()
class LabelDecrementSizeAction(LabelAction): """ The LabelDecrementSizeAction class is a action that decreases the size of a label's text. """ #### 'Action' interface ################################################### # The name of the action. name = Unicode("&Decrement size") ########################################################################### # 'Action' interface. ########################################################################### def perform(self, event): self.obj.decrement_size(1)
class StartRecordingAction(Action): """An action that starts the recording of changes to scriptable objects to a script.""" #### 'Action' interface ################################################### name = Unicode("Start recording") ########################################################################### # 'Action' interface. ########################################################################### def perform(self, event): """ Perform the action. """ get_script_manager().start_recording()
class IHeadingText(Interface): """ Heading text. """ #### 'IHeadingText' interface ############################################# # Heading level. # # fixme: Currently we ignore anything but one, but in future we could # have different visualizations based on the level. level = Int(1) # The heading text. text = Unicode('Default') # The background image. image = Instance(ImageResource)
class LabelItalicFontAction(LabelAction): """ The LabelNormalFontAction class is a action that sets an italic font for a label's text. """ #### 'Action' interface ################################################### # The name of the action. name = Unicode("&Italic font") ########################################################################### # 'Action' interface. ########################################################################### def perform(self, event): self.obj.style = 'italic'
class _ChangePasswordAction(Action): """An action that allows the current user to change their password. It isn't exported through actions/api.py because it is specific to this user manager implementation.""" #### 'Action' interface ################################################### enabled = Bool(False) name = Unicode("&Change Password...") ########################################################################### # 'object' interface. ########################################################################### def __init__(self, **traits): """Initialise the object.""" super(_ChangePasswordAction, self).__init__(**traits) get_permissions_manager().user_manager.on_trait_event( self._refresh_enabled, 'user_authenticated') ########################################################################### # 'Action' interface. ########################################################################### def perform(self, event): """Perform the action.""" um = get_permissions_manager().user_manager um.user_db.change_password(um.user) ########################################################################### # Private interface. ########################################################################### def _refresh_enabled(self, user): """Invoked whenever the current user's authorisation state changes.""" self.enabled = user is not None
class LabelDecrementSizeCommand(AbstractCommand): """ The LabelDecrementSizeCommand class is a command that decreases the size of a label's text. This command will merge multiple decrements togther. """ #### 'ICommand' interface ################################################# # The data being operated on. data = Instance(Label) # The name of the command. name = Unicode("&Decrement size") #### Private interface #################################################### _decremented_by = Int ########################################################################### # 'ICommand' interface. ########################################################################### def do(self): self.data.decrement_size(1) self._decremented_by = 1 def merge(self, other): # We can merge if the other command is the same type (or a sub-type). if isinstance(other, type(self)): self._decremented_by += 1 merged = True else: merged = False return merged def redo(self): self.data.decrement_size(self._decremented_by) def undo(self): self.data.increment_size(self._decremented_by)
class LogoutAction(Action): """An action that unauthenticates the current user.""" #### 'Action' interface ################################################### enabled = Bool(False) name = Unicode("Log&out") ########################################################################### # 'object' interface. ########################################################################### def __init__(self, **traits): """Initialise the object.""" super(LogoutAction, self).__init__(**traits) get_permissions_manager().user_manager.on_trait_event( self._refresh_enabled, 'user_authenticated') ########################################################################### # 'Action' interface. ########################################################################### def perform(self, event): """Perform the action.""" get_permissions_manager().user_manager.unauthenticate_user() ########################################################################### # Private interface. ########################################################################### def _refresh_enabled(self, user): """Invoked whenever the current user's authorisation state changes.""" self.enabled = user is not None
class UserMenuManager(MenuManager): """A menu that contains all the actions related to users and permissions. """ #### 'MenuManager' interface ############################################## id = 'User' name = Unicode("&User") ########################################################################### # 'object' interface. ########################################################################### def __init__(self, **traits): """Initialise the object.""" pm = get_permissions_manager() # Put them in a group so we can optionally append (because the PyFace # API doesn't do what you expect with append()). group = Group() group.append(LoginAction()) for act in pm.user_manager.user_actions: group.append(act) group.append(LogoutAction()) for act in pm.user_manager.management_actions: group.append(act) for act in pm.policy_manager.management_actions: group.append(act) super(UserMenuManager, self).__init__(group, **traits)
class TestTraits(HasTraits): b = Bool(False) i = Int(7) l = Long(1234567890123456789L) f = Float(math.pi) c = Complex(complex(1.01234, 2.3)) n = Any s = Str('String') u = Unicode(u'Unicode') inst = Instance(A) tuple = Tuple list = List pure_list = List(range(5)) dict = Dict numeric = Array(value=numpy.ones((2, 2, 2), 'f')) ref = Array _tvtk = Instance(tvtk.Property, ()) def __init__(self): self.inst = A() self.tuple = (1, 2, 'a', A()) self.list = [1, 1.1, 'a', 1j, self.inst] self.dict = {'a': 1, 'b': 2, 'ref': self.inst} self.ref = self.numeric
class ViewMenuManager(MenuManager): """ The 'View' menu. By default, this menu is displayed on the main menu bar. """ #### 'ActionManager' interface ############################################ # All of the groups in the manager. groups = List(Group) # The manager's unique identifier (if it has one). id = Str('View') #### 'MenuManager' interface ############################################## # The menu manager's name (if the manager is a sub-menu, this is what its # label will be). name = Unicode('&View') #### 'ViewMenuManager' interface ########################################## # Should the perspective menu be shown? show_perspective_menu = Bool(True) # The workbench window that the menu is part of. window = Instance('enthought.pyface.workbench.api.WorkbenchWindow') #### 'Private' interface ################################################## # The group containing the view hide/show actions. _view_group = Any ########################################################################### # 'ActionManager' interface. ########################################################################### def _groups_default(self): """ Trait initializer. """ groups = [] # Add a group containing the perspective menu (if requested). if self.show_perspective_menu and len(self.window.perspectives) > 0: groups.append(Group(PerspectiveMenuManager(window=self.window))) # Add a group containing a 'toggler' for all visible views. self._view_group = self._create_view_group(self.window) groups.append(self._view_group) # Add a group containing an 'Other...' item that will launch a dialog # to allow the user to choose a view to show. groups.append(self._create_other_group(self.window)) return groups ########################################################################### # 'ViewMenuManager' interface. ########################################################################### @on_trait_change('window.active_perspective,window.active_part,' 'window.views,window.views_items') def refresh(self): """ Refreshes the checked state of the actions in the menu. """ logger.debug('refreshing view menu') if self._view_group is not None: self._clear_group(self._view_group) self._initialize_view_group(self.window, self._view_group) self.changed = True return ########################################################################### # Private interface. ########################################################################### def _clear_group(self, group): """ Remove all items in a group. """ # fixme: Fix this API in PyFace so there is only one call! group.destroy() group.clear() return def _create_other_group(self, window): """ Creates a group containing the 'Other...' action. """ group = Group() group.append(ShowViewAction(name='Other...', window=window)) return group def _create_view_group(self, window): """ Creates a group containing the view 'togglers'. """ group = Group() self._initialize_view_group(window, group) return group def _initialize_view_group(self, window, group): """ Initializes a group containing the view 'togglers'. """ views = window.views[:] views.sort(None, lambda view: view.name) for view in views: # fixme: It seems a little smelly to be reaching in to the window # layout here. Should the 'contains_view' method be part of the # window interface? if window.layout.contains_view(view): group.append( ToggleViewVisibilityAction(view=view, window=window)) return
class Employee(HasTraits): name = Unicode(label=u"姓名") department = Unicode(label=u"部门") salary = Int(label=u"薪水") bonus = Int(label=u"奖金") view = View("name", "department", "salary", "bonus")