def __init__(self): super(ShortcutBasicsExample, self).__init__() self.setSpacing(True) # Firstname input with an input prompt for demo clarity firstname = TextField('Firstname') firstname.setInputPrompt('ALT-SHIFT-F to focus') self.addComponent(firstname) # Add global shortcut that focuses the field firstname.addShortcutListener(FocusShortcut(firstname, KeyCode.F, ModifierKey.ALT, ModifierKey.SHIFT)) # Lastname input with an input prompt for demo clarity lastname = TextField('Lastname') lastname.setInputPrompt('ALT-SHIFT-L to focus') self.addComponent(lastname) # Add global shortcut that focuses the field lastname.addShortcutListener(FocusShortcut(lastname, KeyCode.L, ModifierKey.ALT, ModifierKey.SHIFT)) # Button with a simple click-listener enter = Button('Enter', EnterListener(self)) self.addComponent(enter) enter.setStyleName('primary') # make it look like it's default # Add global shortcut using the built-in helper enter.setClickShortcut(KeyCode.ENTER)
def __init__(self): super(ShortcutBasicsExample, self).__init__() self.setSpacing(True) # Firstname input with an input prompt for demo clarity firstname = TextField('Firstname') firstname.setInputPrompt('ALT-SHIFT-F to focus') self.addComponent(firstname) # Add global shortcut that focuses the field firstname.addShortcutListener( FocusShortcut(firstname, KeyCode.F, ModifierKey.ALT, ModifierKey.SHIFT)) # Lastname input with an input prompt for demo clarity lastname = TextField('Lastname') lastname.setInputPrompt('ALT-SHIFT-L to focus') self.addComponent(lastname) # Add global shortcut that focuses the field lastname.addShortcutListener( FocusShortcut(lastname, KeyCode.L, ModifierKey.ALT, ModifierKey.SHIFT)) # Button with a simple click-listener enter = Button('Enter', EnterListener(self)) self.addComponent(enter) enter.setStyleName('primary') # make it look like it's default # Add global shortcut using the built-in helper enter.setClickShortcut(KeyCode.ENTER)
def createPanel(self, number): p = Panel('Panel %d' % number) p.getContent().setSpacing(True) # Let's create a customized shortcut that jumps to the next field p.addAction(NextFieldListener("Next field", KeyCode.ARROW_DOWN, None)) # Firstname input with an input prompt for demo clarity firstname = TextField('Firstname') firstname.setInputPrompt('ALT-SHIFT-F to focus') p.addComponent(firstname) # Using firstname.addShortcutListener() would add globally, # but we want the shortcut only in this panel: p.addAction( FocusShortcut(firstname, KeyCode.F, ModifierKey.ALT, ModifierKey.SHIFT)) # additinally we'll add a global shortcut for this field using the # shorthand notation (^1 == CTRL-1,NextFieldListener etc) firstname.addShortcutListener( FocusShortcut(firstname, 'Focus panel &_' + str(number))) p.setDescription('CTRL-' + str(number) + ' to focus') # Lastname input with an input prompt for demo clarity lastname = TextField('Lastname') lastname.setInputPrompt('ALT-SHIFT-L to focus') p.addComponent(lastname) # Using firstname.addShortcutListener() would add globally, # but we want the shortcut only in this panel: p.addAction( FocusShortcut(lastname, KeyCode.L, ModifierKey.ALT, ModifierKey.SHIFT)) # Button with a simple click-listener save = Button('Save', SaveListener(self, p)) p.addComponent(save) # setClickShortcut() would add global shortcut, instead we # 'scope' the shortcut to the panel: p.addAction( ClickShortcut(save, KeyCode.S, ModifierKey.ALT, ModifierKey.SHIFT)) return p
def createPanel(self, number): p = Panel('Panel %d' % number) p.getContent().setSpacing(True) # Let's create a customized shortcut that jumps to the next field p.addAction(NextFieldListener("Next field", KeyCode.ARROW_DOWN, None)) # Firstname input with an input prompt for demo clarity firstname = TextField('Firstname') firstname.setInputPrompt('ALT-SHIFT-F to focus') p.addComponent(firstname) # Using firstname.addShortcutListener() would add globally, # but we want the shortcut only in this panel: p.addAction(FocusShortcut(firstname, KeyCode.F, ModifierKey.ALT, ModifierKey.SHIFT)) # additinally we'll add a global shortcut for this field using the # shorthand notation (^1 == CTRL-1,NextFieldListener etc) firstname.addShortcutListener(FocusShortcut(firstname, 'Focus panel &_' + str(number))) p.setDescription('CTRL-' + str(number) + ' to focus') # Lastname input with an input prompt for demo clarity lastname = TextField('Lastname') lastname.setInputPrompt('ALT-SHIFT-L to focus') p.addComponent(lastname) # Using firstname.addShortcutListener() would add globally, # but we want the shortcut only in this panel: p.addAction(FocusShortcut(lastname, KeyCode.L, ModifierKey.ALT, ModifierKey.SHIFT)) # Button with a simple click-listener save = Button('Save', SaveListener(self, p)) p.addComponent(save) # setClickShortcut() would add global shortcut, instead we # 'scope' the shortcut to the panel: p.addAction(ClickShortcut(save, KeyCode.S, ModifierKey.ALT, ModifierKey.SHIFT)) return p