Esempio n. 1
0
class KeyboardConfigDialog(wx.Dialog):
    """Keyboard configuration dialog."""

    def __init__(self, options, parent, config):
        self.config = config
        self.options = options
        
        pos = (config.get_keyboard_config_frame_x(), 
               config.get_keyboard_config_frame_y())
        wx.Dialog.__init__(self, parent, title=DIALOG_TITLE, pos=pos)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_flags = wx.SizerFlags().Border(wx.ALL, UI_BORDER).Align(wx.ALIGN_CENTER_HORIZONTAL)

        instructions = wx.StaticText(self, label=ARPEGGIATE_INSTRUCTIONS)
        sizer.AddF(instructions, sizer_flags.Align(wx.LEFT))
        self.arpeggiate_option = wx.CheckBox(self, label=ARPEGGIATE_LABEL)
        self.arpeggiate_option.SetValue(options.arpeggiate)
        sizer.AddF(self.arpeggiate_option, sizer_flags)

        # editable list for keymap bindings
        self.keymap = Keymap(Keyboard.KEYS_LAYOUT.split(), Keyboard.ACTIONS)
        mappings = config.get_system_keymap('Keyboard')
        if mappings is not None:
            self.keymap.set_mappings(mappings)
        self.keymap_widget = EditKeymapWidget(self)
        self.keymap_widget.set_mappings(self.keymap.get_mappings())
        sizer.AddF(self.keymap_widget, sizer_flags.Expand())

        ok_button = wx.Button(self, id=wx.ID_OK)
        ok_button.SetDefault()
        cancel_button = wx.Button(self, id=wx.ID_CANCEL, label='Cancel')
        reset_button = wx.Button(self, id=wx.ID_RESET, label='Reset to default')

        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
        button_sizer.AddF(ok_button, sizer_flags)
        button_sizer.AddF(cancel_button, sizer_flags)
        button_sizer.AddF(reset_button, sizer_flags)
        sizer.AddF(button_sizer, sizer_flags)

        self.SetSizerAndFit(sizer)
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.Bind(wx.EVT_MOVE, self.on_move)
        ok_button.Bind(wx.EVT_BUTTON, lambda e: self.EndModal(wx.ID_OK))
        cancel_button.Bind(wx.EVT_BUTTON, lambda e: self.EndModal(wx.ID_CANCEL))
        reset_button.Bind(wx.EVT_BUTTON, self.on_reset)

    def ShowModal(self):
        code = super(KeyboardConfigDialog, self).ShowModal()
        if wx.ID_OK == code:
            self.options.arpeggiate = self.arpeggiate_option.GetValue()
            # Validate mappings by updating the keymap object.
            self.keymap.set_mappings(self.keymap_widget.get_mappings())
            self.config.set_system_keymap('Keyboard', self.keymap.get_mappings())
        return code

    def on_reset(self, event):
        mappings = self.keymap_widget.get_mappings()
        mappings.update(system.KEYMAPS['Keyboard'])
        self.keymap_widget.set_mappings(mappings)

    def on_move(self, event):
        pos = self.GetScreenPositionTuple()
        self.config.set_keyboard_config_frame_x(pos[0]) 
        self.config.set_keyboard_config_frame_y(pos[1])
        event.Skip()
Esempio n. 2
0
class KeyboardConfigDialog(wx.Dialog):
    """Keyboard configuration dialog."""
    def __init__(self, options, parent, config):
        self.config = config
        self.options = options

        pos = (config.get_keyboard_config_frame_x(),
               config.get_keyboard_config_frame_y())
        wx.Dialog.__init__(self, parent, title=DIALOG_TITLE, pos=pos)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_flags = wx.SizerFlags().Border(wx.ALL, UI_BORDER).Align(
            wx.ALIGN_CENTER_HORIZONTAL)

        instructions = wx.StaticText(self, label=ARPEGGIATE_INSTRUCTIONS)
        sizer.AddF(instructions, sizer_flags.Align(wx.LEFT))
        self.arpeggiate_option = wx.CheckBox(self, label=ARPEGGIATE_LABEL)
        self.arpeggiate_option.SetValue(options.arpeggiate)
        sizer.AddF(self.arpeggiate_option, sizer_flags)

        # editable list for keymap bindings
        self.keymap = Keymap(Keyboard.KEYS_LAYOUT.split(), Keyboard.ACTIONS)
        mappings = config.get_system_keymap('Keyboard')
        if mappings is not None:
            self.keymap.set_mappings(mappings)
        self.keymap_widget = EditKeymapWidget(self)
        self.keymap_widget.set_mappings(self.keymap.get_mappings())
        sizer.AddF(self.keymap_widget, sizer_flags.Expand())

        ok_button = wx.Button(self, id=wx.ID_OK)
        ok_button.SetDefault()
        cancel_button = wx.Button(self, id=wx.ID_CANCEL, label='Cancel')
        reset_button = wx.Button(self,
                                 id=wx.ID_RESET,
                                 label='Reset to default')

        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
        button_sizer.AddF(ok_button, sizer_flags)
        button_sizer.AddF(cancel_button, sizer_flags)
        button_sizer.AddF(reset_button, sizer_flags)
        sizer.AddF(button_sizer, sizer_flags)

        self.SetSizerAndFit(sizer)
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.Bind(wx.EVT_MOVE, self.on_move)
        ok_button.Bind(wx.EVT_BUTTON, lambda e: self.EndModal(wx.ID_OK))
        cancel_button.Bind(wx.EVT_BUTTON,
                           lambda e: self.EndModal(wx.ID_CANCEL))
        reset_button.Bind(wx.EVT_BUTTON, self.on_reset)

    def ShowModal(self):
        code = super(KeyboardConfigDialog, self).ShowModal()
        if wx.ID_OK == code:
            self.options.arpeggiate = self.arpeggiate_option.GetValue()
            # Validate mappings by updating the keymap object.
            self.keymap.set_mappings(self.keymap_widget.get_mappings())
            self.config.set_system_keymap('Keyboard',
                                          self.keymap.get_mappings())
        return code

    def on_reset(self, event):
        mappings = self.keymap_widget.get_mappings()
        mappings.update(system.KEYMAPS['Keyboard'])
        self.keymap_widget.set_mappings(mappings)

    def on_move(self, event):
        pos = self.GetScreenPositionTuple()
        self.config.set_keyboard_config_frame_x(pos[0])
        self.config.set_keyboard_config_frame_y(pos[1])
        event.Skip()