Exemple #1
0
    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)

        instructions = wx.StaticText(self, label=ARPEGGIATE_INSTRUCTIONS)
        sizer.Add(instructions, border=UI_BORDER, flag=wx.ALL)
        self.arpeggiate_option = wx.CheckBox(self, label=ARPEGGIATE_LABEL)
        self.arpeggiate_option.SetValue(options.arpeggiate)
        sizer.Add(self.arpeggiate_option,
                  border=UI_BORDER,
                  flag=wx.LEFT | wx.RIGHT | wx.BOTTOM)

        ok_button = wx.Button(self, id=wx.ID_OK)
        ok_button.SetDefault()
        cancel_button = wx.Button(self, id=wx.ID_CANCEL)

        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
        button_sizer.Add(ok_button, border=UI_BORDER, flag=wx.ALL)
        button_sizer.Add(cancel_button, border=UI_BORDER, flag=wx.ALL)
        sizer.Add(button_sizer, flag=wx.ALL | wx.ALIGN_RIGHT, border=UI_BORDER)

        self.SetSizer(sizer)
        sizer.Fit(self)
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.Bind(wx.EVT_MOVE, self.on_move)
        ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
        cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
Exemple #2
0
    def __init__(self, parent, config):
        self.config = config
        on_top = config.get_stroke_display_on_top()
        style = wx.DEFAULT_DIALOG_STYLE
        if on_top:
            style |= wx.STAY_ON_TOP
        pos = (config.get_stroke_display_x(), config.get_stroke_display_y())
        wx.Dialog.__init__(self, parent, title=TITLE, style=style, pos=pos)

        self.SetBackgroundColour(wx.WHITE)

        sizer = wx.BoxSizer(wx.VERTICAL)

        self.on_top = wx.CheckBox(self, label=ON_TOP_TEXT)
        self.on_top.SetValue(config.get_stroke_display_on_top())
        self.on_top.Bind(wx.EVT_CHECKBOX, self.handle_on_top)
        sizer.Add(self.on_top, flag=wx.ALL, border=UI_BORDER)

        box = wx.BoxSizer(wx.HORIZONTAL)
        box.Add(wx.StaticText(self, label=STYLE_TEXT),
                border=UI_BORDER,
                flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT)
        self.choice = wx.Choice(self, choices=STYLES)
        self.choice.SetStringSelection(self.config.get_stroke_display_style())
        self.choice.Bind(wx.EVT_CHOICE, self.on_style)
        box.Add(self.choice, proportion=1)
        sizer.Add(box,
                  flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
                  border=UI_BORDER)

        self.header = MyStaticText(self, label=ALL_KEYS)
        font = self.header.GetFont()
        font.SetFaceName("Courier")
        self.header.SetFont(font)
        sizer.Add(self.header,
                  flag=wx.LEFT | wx.RIGHT | wx.BOTTOM,
                  border=UI_BORDER)
        sizer.Add(wx.StaticLine(self), flag=wx.EXPAND)

        self.listbox = wx.ListBox(self, size=wx.Size(210, 500))
        font = self.listbox.GetFont()
        font.SetFaceName("Courier")
        self.listbox.SetFont(font)

        sizer.Add(self.listbox, flag=wx.ALL | wx.FIXED_MINSIZE, border=3)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        sizer.Layout()
        sizer.Fit(self)

        self.on_style()

        self.Show()
        self.close_all()
        self.other_instances.append(self)

        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.Bind(wx.EVT_MOVE, self.on_move)
Exemple #3
0
    def __init__(self, parent, engine, config):
        pos = (config.get_lookup_frame_x(),
               config.get_lookup_frame_y())
        wx.Dialog.__init__(self, parent, title=TITLE, pos=pos,
                           style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)

        self.config = config

        # components
        self.translation_text = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
        self.listbox = wx.ListBox(self, size=wx.Size(210, 200),
                                  style=wx.LB_HSCROLL)
        cancel = wx.Button(self, wx.ID_CANCEL, CANCEL_BUTTON)
        cancel.Bind(wx.EVT_BUTTON, self.on_close)
        # layout
        global_sizer = wx.BoxSizer(wx.VERTICAL)

        global_sizer.Add(self.translation_text, 0, wx.ALL | wx.EXPAND,
                         self.BORDER)
        global_sizer.Add(self.listbox, 1, wx.ALL & ~wx.TOP | wx.EXPAND,
                         self.BORDER)
        global_sizer.Add(cancel, 0, wx.ALL & ~wx.TOP | wx.EXPAND, self.BORDER)

        self.SetAutoLayout(True)
        self.SetSizer(global_sizer)
        global_sizer.Fit(self)
        global_sizer.SetSizeHints(self)
        self.Layout()
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        # events
        self.translation_text.Bind(wx.EVT_TEXT, self.on_translation_change)
        self.translation_text.Bind(wx.EVT_SET_FOCUS, self.on_translation_gained_focus)
        self.translation_text.Bind(wx.EVT_KILL_FOCUS, self.on_translation_lost_focus)
        self.Bind(wx.EVT_CLOSE, self.on_close)

        self.Bind(wx.EVT_MOVE, self.on_move)

        self.engine = engine
        
        # TODO: add functions on engine for state
        self.previous_state = self.engine.translator.get_state()
        # TODO: use state constructor?
        self.engine.translator.clear_state()
        self.translation_state = self.engine.translator.get_state()
        self.engine.translator.set_state(self.previous_state)
        
        self.last_window = util.GetForegroundWindow()
        
        # Now that we saved the last window we'll close other instances. This 
        # may restore their original window but we've already saved ours so it's 
        # fine.
        for instance in self.other_instances:
            instance.Close()
        del self.other_instances[:]
        self.other_instances.append(self)
Exemple #4
0
    def __init__(self, parent, config, engine):
        self.config = config
        self.engine = engine
        self.words = ''
        on_top = config.get_suggestions_display_on_top()
        style = wx.DEFAULT_DIALOG_STYLE
        style |= wx.RESIZE_BORDER
        if on_top:
            style |= wx.STAY_ON_TOP
        pos = (config.get_suggestions_display_x(), config.get_suggestions_display_y())
        wx.Dialog.__init__(self, parent, title=TITLE, style=style, pos=pos)

        self.SetBackgroundColour(wx.WHITE)

        sizer = wx.BoxSizer(wx.VERTICAL)

        self.on_top = wx.CheckBox(self, label=ON_TOP_TEXT)
        self.on_top.SetValue(config.get_suggestions_display_on_top())
        self.on_top.Bind(wx.EVT_CHECKBOX, self.handle_on_top)
        sizer.Add(self.on_top, flag=wx.ALL, border=UI_BORDER)

        box = wx.BoxSizer(wx.HORIZONTAL)

        self.header = MyStaticText(self, label=LAST_WORD_TEXT % DEFAULT_LAST_WORD)
        font = self.header.GetFont()
        font.SetFaceName("Courier")
        self.header.SetFont(font)
        sizer.Add(self.header, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM,
                  border=UI_BORDER)
        sizer.Add(wx.StaticLine(self), flag=wx.EXPAND)

        self.listbox = wx.ListBox(self, size=wx.Size(210, 500))
        font = self.listbox.GetFont()
        font.SetFaceName("Courier")
        self.listbox.SetFont(font)

        sizer.Add(self.listbox,
                  proportion=1,
                  flag=wx.ALL | wx.FIXED_MINSIZE | wx.EXPAND,
                  border=3)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        sizer.Layout()
        sizer.Fit(self)

        self.Show()
        self.close_all()
        self.other_instances.append(self)

        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.Bind(wx.EVT_MOVE, self.on_move)
Exemple #5
0
    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)

        instructions = wx.StaticText(self, label=ARPEGGIATE_INSTRUCTIONS)
        sizer.Add(instructions, border=UI_BORDER, flag=wx.ALL)
        self.arpeggiate_option = wx.CheckBox(self, label=ARPEGGIATE_LABEL)
        self.arpeggiate_option.SetValue(options.arpeggiate)
        sizer.Add(self.arpeggiate_option,
                  border=UI_BORDER,
                  flag=wx.LEFT | wx.RIGHT | wx.BOTTOM)

        # editable list for keymap bindings
        self.keymap_list_ctrl = EditableListCtrl(self,
                                                 style=wx.LC_REPORT,
                                                 size=(300, 200))
        self.keymap_list_ctrl.InsertColumn(0, 'Steno Key')
        self.keymap_list_ctrl.InsertColumn(1, 'Keys')

        keymap = options.keymap.get()
        stenoKeys = keymap.keys()
        rows = map(lambda x: (x, ' '.join(keymap[x])), stenoKeys)
        for index, row in enumerate(rows):
            self.keymap_list_ctrl.InsertStringItem(index, row[0])
            self.keymap_list_ctrl.SetStringItem(index, 1, row[1])
        sizer.Add(self.keymap_list_ctrl, flag=wx.EXPAND)

        ok_button = wx.Button(self, id=wx.ID_OK)
        ok_button.SetDefault()
        cancel_button = wx.Button(self, id=wx.ID_CANCEL)

        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
        button_sizer.Add(ok_button, border=UI_BORDER, flag=wx.ALL)
        button_sizer.Add(cancel_button, border=UI_BORDER, flag=wx.ALL)
        sizer.Add(button_sizer, flag=wx.ALL | wx.ALIGN_RIGHT, border=UI_BORDER)

        self.SetSizer(sizer)
        sizer.Fit(self)
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.Bind(wx.EVT_MOVE, self.on_move)
        ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
        cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
Exemple #6
0
    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(KeyboardMachine.KEYS_LAYOUT.split(),
                             KeyboardMachine.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)
Exemple #7
0
    def __init__(self, config):
        self.config = config

        # Note: don't set position from config, since it's not yet loaded.
        wx.Frame.__init__(
            self,
            None,
            title=self.TITLE,
            style=wx.DEFAULT_FRAME_STYLE
            & ~(wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX))
        root = wx.Panel(self, style=wx.DEFAULT_FRAME_STYLE)

        # Menu Bar
        MenuBar = wx.MenuBar()
        self.SetMenuBar(MenuBar)

        # Application icon
        icon = wx.Icon(self.PLOVER_ICON_FILE, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

        # Configure button.
        self.configure_button = wx.Button(root,
                                          label=self.CONFIGURE_BUTTON_LABEL)
        self.configure_button.Bind(wx.EVT_BUTTON, self._show_config_dialog)

        # About button.
        self.about_button = wx.Button(root, label=self.ABOUT_BUTTON_LABEL)
        self.about_button.Bind(wx.EVT_BUTTON, self._show_about_dialog)

        # Status radio buttons.
        self.radio_output_enable = wx.RadioButton(
            root, label=self.ENABLE_OUTPUT_LABEL)
        self.radio_output_enable.Bind(
            wx.EVT_RADIOBUTTON,
            lambda e: self.steno_engine.set_is_running(True))
        self.radio_output_disable = wx.RadioButton(
            root, label=self.DISABLE_OUTPUT_LABEL)
        self.radio_output_disable.Bind(
            wx.EVT_RADIOBUTTON,
            lambda e: self.steno_engine.set_is_running(False))

        # Machine status.
        # TODO: Figure out why spinner has darker gray background.
        self.spinner = wx.animate.GIFAnimationCtrl(root, -1, SPINNER_FILE)
        self.spinner.GetPlayer().UseBackgroundColour(True)
        # Need to call this so the size of the control is not
        # messed up (100x100 instead of 16x16) on Linux...
        self.spinner.InvalidateBestSize()
        self.spinner.Hide()

        self.connected_bitmap = wx.Bitmap(self.CONNECTED_IMAGE_FILE,
                                          wx.BITMAP_TYPE_PNG)
        self.disconnected_bitmap = wx.Bitmap(self.DISCONNECTED_IMAGE_FILE,
                                             wx.BITMAP_TYPE_PNG)
        self.connection_ctrl = wx.StaticBitmap(root,
                                               bitmap=self.disconnected_bitmap)

        border_flag = wx.SizerFlags(1).Border(wx.ALL, self.BORDER)

        # Create Settings Box
        settings_sizer = wx.BoxSizer(wx.HORIZONTAL)

        settings_sizer.AddF(self.configure_button, border_flag.Expand())
        settings_sizer.AddF(self.about_button, border_flag.Expand())

        # Create Output Status Box
        box = wx.StaticBox(root, label=self.HEADER_OUTPUT)
        status_sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)

        status_sizer.AddF(self.radio_output_enable, border_flag)
        status_sizer.AddF(self.radio_output_disable, border_flag)

        # Create Machine Status Box
        machine_sizer = wx.BoxSizer(wx.HORIZONTAL)
        center_flag =\
            wx.SizerFlags()\
              .Align(wx.ALIGN_CENTER_VERTICAL)\
              .Border(wx.LEFT | wx.RIGHT, self.BORDER)

        machine_sizer.AddF(self.spinner, center_flag)
        machine_sizer.AddF(self.connection_ctrl, center_flag)
        longest_machine = max(machine_registry.get_all_names(), key=len)
        longest_state = max((STATE_ERROR, STATE_INITIALIZING, STATE_RUNNING),
                            key=len)
        longest_machine_status = '%s: %s' % (longest_machine, longest_state)
        self.machine_status_text = wx.StaticText(root,
                                                 label=longest_machine_status)
        machine_sizer.AddF(self.machine_status_text, center_flag)
        refresh_bitmap = wx.Bitmap(self.REFRESH_IMAGE_FILE, wx.BITMAP_TYPE_PNG)
        self.reconnect_button = wx.BitmapButton(root, bitmap=refresh_bitmap)
        machine_sizer.AddF(self.reconnect_button, center_flag)

        # Assemble main UI
        global_sizer = wx.GridBagSizer(vgap=self.BORDER, hgap=self.BORDER)
        global_sizer.Add(settings_sizer,
                         flag=wx.EXPAND,
                         pos=(0, 0),
                         span=(1, 2))
        global_sizer.Add(status_sizer,
                         flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
                         border=self.BORDER,
                         pos=(1, 0),
                         span=(1, 2))
        global_sizer.Add(machine_sizer,
                         flag=wx.CENTER | wx.ALIGN_CENTER | wx.EXPAND
                         | wx.LEFT,
                         pos=(2, 0),
                         border=self.BORDER,
                         span=(1, 2))
        self.machine_sizer = machine_sizer
        # Add a border around the entire sizer.
        border = wx.BoxSizer()
        border.AddF(global_sizer,
                    wx.SizerFlags(1).Border(wx.ALL, self.BORDER).Expand())
        root.SetSizerAndFit(border)
        border.SetSizeHints(self)

        self.Bind(wx.EVT_CLOSE, self._quit)
        self.Bind(wx.EVT_MOVE, self.on_move)
        self.reconnect_button.Bind(wx.EVT_BUTTON, lambda e: self._reconnect())

        try:
            with open(config.target_file, 'rb') as f:
                self.config.load(f)
        except Exception:
            log.error('loading configuration failed, reseting to default',
                      exc_info=True)
            self.config.clear()

        rect = wx.Rect(config.get_main_frame_x(), config.get_main_frame_y(),
                       *self.GetSize())
        self.SetRect(AdjustRectToScreen(rect))

        self.steno_engine = app.StenoEngine()
        self.steno_engine.add_callback(
            lambda s: wx.CallAfter(self._update_status, s))
        self.steno_engine.set_output(
            Output(self.consume_command, self.steno_engine))

        self.steno_engine.add_stroke_listener(
            StrokeDisplayDialog.stroke_handler)
        if self.config.get_show_stroke_display():
            StrokeDisplayDialog.display(self, self.config)

        self.steno_engine.formatter.add_listener(
            SuggestionsDisplayDialog.stroke_handler)
        if self.config.get_show_suggestions_display():
            SuggestionsDisplayDialog.display(self, self.config,
                                             self.steno_engine)

        try:
            app.init_engine(self.steno_engine, self.config)
        except Exception:
            log.error('engine initialization failed', exc_info=True)
            self._show_config_dialog()
Exemple #8
0
    def __init__(self, parent, engine, config):
        pos = (config.get_translation_frame_x(), 
               config.get_translation_frame_y())
        wx.Dialog.__init__(self, parent, wx.ID_ANY, TITLE, 
                           pos, wx.DefaultSize, 
                           wx.DEFAULT_DIALOG_STYLE, wx.DialogNameStr)

        self.config = config

        # components
        self.strokes_text = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
        self.translation_text = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
        button = wx.Button(self, id=wx.ID_OK, label='Add to dictionary')
        cancel = wx.Button(self, id=wx.ID_CANCEL)
        self.stroke_mapping_text = wx.StaticText(self)
        self.translation_mapping_text = wx.StaticText(self)
        
        # layout
        global_sizer = wx.BoxSizer(wx.VERTICAL)
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        label = wx.StaticText(self, label=self.STROKES_TEXT)
        sizer.Add(label, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL, 
                  border=self.BORDER)
        sizer.Add(self.strokes_text, 
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 
                  border=self.BORDER)
        label = wx.StaticText(self, label=self.TRANSLATION_TEXT)
        sizer.Add(label, 
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 
                  border=self.BORDER)
        sizer.Add(self.translation_text          , 
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 
                  border=self.BORDER)
        sizer.Add(button, 
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 
                  border=self.BORDER)
        sizer.Add(cancel, 
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, 
                  border=self.BORDER)
        global_sizer.Add(sizer)
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.stroke_mapping_text, 
                  flag= wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        global_sizer.Add(sizer)
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.translation_mapping_text, 
                  flag= wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        global_sizer.Add(sizer)
        
        self.SetAutoLayout(True)
        self.SetSizer(global_sizer)
        global_sizer.Fit(self)
        global_sizer.SetSizeHints(self)
        self.Layout()
        self.SetRect(AdjustRectToScreen(self.GetRect()))
        
        # events
        button.Bind(wx.EVT_BUTTON, self.on_add_translation)
        # The reason for the focus event here is to skip focus on tab traversal
        # of the buttons. But it seems that on windows this prevents the button
        # from being pressed. Leave this commented out until that problem is
        # resolved.
        #button.Bind(wx.EVT_SET_FOCUS, self.on_button_gained_focus)
        cancel.Bind(wx.EVT_BUTTON, self.on_close)
        #cancel.Bind(wx.EVT_SET_FOCUS, self.on_button_gained_focus)
        self.strokes_text.Bind(wx.EVT_TEXT, self.on_strokes_change)
        self.translation_text.Bind(wx.EVT_TEXT, self.on_translation_change)
        self.strokes_text.Bind(wx.EVT_SET_FOCUS, self.on_strokes_gained_focus)
        self.strokes_text.Bind(wx.EVT_KILL_FOCUS, self.on_strokes_lost_focus)
        self.strokes_text.Bind(wx.EVT_TEXT_ENTER, self.on_add_translation)
        self.translation_text.Bind(wx.EVT_SET_FOCUS, self.on_translation_gained_focus)
        self.translation_text.Bind(wx.EVT_KILL_FOCUS, self.on_translation_lost_focus)
        self.translation_text.Bind(wx.EVT_TEXT_ENTER, self.on_add_translation)
        self.Bind(wx.EVT_CLOSE, self.on_close)
        self.Bind(wx.EVT_MOVE, self.on_move)
        
        self.engine = engine
        
        # TODO: add functions on engine for state
        self.previous_state = self.engine.translator.get_state()
        # TODO: use state constructor?
        self.engine.translator.clear_state()
        self.strokes_state = self.engine.translator.get_state()
        self.engine.translator.clear_state()
        self.translation_state = self.engine.translator.get_state()
        self.engine.translator.set_state(self.previous_state)
        
        self.last_window = GetForegroundWindow()
        
        # Now that we saved the last window we'll close other instances. This 
        # may restore their original window but we've already saved ours so it's 
        # fine.
        for instance in self.other_instances:
            instance.Close()
        del self.other_instances[:]
        self.other_instances.append(self)
Exemple #9
0
    def __init__(self, engine, config, parent):
        """Create a configuration GUI based on the given config file.

        Arguments:

        configuration file to view and edit.
        during_plover_init -- If this is set to True, the configuration dialog
        won't tell the user that Plover needs to be restarted.
        """
        pos = (config.get_config_frame_x(), config.get_config_frame_y())
        size = wx.Size(config.get_config_frame_width(),
                       config.get_config_frame_height())
        wx.Dialog.__init__(self,
                           parent,
                           title=TITLE,
                           pos=pos,
                           size=size,
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
        self.engine = engine
        self.config = config

        # Close all other instances.
        if self.other_instances:
            for instance in self.other_instances:
                instance.Close()
        del self.other_instances[:]
        self.other_instances.append(self)

        sizer = wx.BoxSizer(wx.VERTICAL)

        # The tab container
        notebook = wx.Notebook(self)

        # Configuring each tab
        self.machine_config = MachineConfig(self.config, notebook)
        self.dictionary_config = DictionaryConfig(self.engine, self.config,
                                                  notebook)
        self.logging_config = LoggingConfig(self.config, notebook)
        self.display_config = DisplayConfig(self.config, notebook, self.engine)
        self.output_config = OutputConfig(self.config, notebook)

        # Adding each tab
        notebook.AddPage(self.machine_config, MACHINE_CONFIG_TAB_NAME)
        notebook.AddPage(self.dictionary_config, DICTIONARY_CONFIG_TAB_NAME)
        notebook.AddPage(self.logging_config, LOGGING_CONFIG_TAB_NAME)
        notebook.AddPage(self.display_config, DISPLAY_CONFIG_TAB_NAME)
        notebook.AddPage(self.output_config, OUTPUT_CONFIG_TAB_NAME)

        sizer.Add(notebook, proportion=1, flag=wx.EXPAND)

        # The bottom button container
        button_sizer = wx.StdDialogButtonSizer()

        # Configuring and adding the save button
        save_button = wx.Button(self, wx.ID_SAVE, SAVE_CONFIG_BUTTON_NAME)
        save_button.SetDefault()
        button_sizer.AddButton(save_button)

        # Configuring and adding the cancel button
        cancel_button = wx.Button(self, wx.ID_CANCEL, label='Cancel')
        button_sizer.AddButton(cancel_button)
        button_sizer.Realize()

        sizer.Add(button_sizer, flag=wx.ALL | wx.ALIGN_RIGHT, border=UI_BORDER)

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

        # Binding the save button to the self._save callback
        self.Bind(wx.EVT_BUTTON, self._save, save_button)

        self.Bind(wx.EVT_MOVE, self.on_move)
        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_CLOSE, self.on_close)
Exemple #10
0
    def __init__(self, config):
        self.config = config
        
        pos = wx.DefaultPosition
        size = wx.DefaultSize
        wx.Frame.__init__(self, None, title=self.TITLE, pos=pos, size=size,
                          style=wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER |
                                                           wx.RESIZE_BOX |
                                                           wx.MAXIMIZE_BOX))

        # Status button.
        self.on_bitmap = wx.Bitmap(self.ON_IMAGE_FILE, wx.BITMAP_TYPE_PNG)
        self.off_bitmap = wx.Bitmap(self.OFF_IMAGE_FILE, wx.BITMAP_TYPE_PNG)
        self.status_button = wx.BitmapButton(self, bitmap=self.on_bitmap)
        self.status_button.Bind(wx.EVT_BUTTON, self._toggle_steno_engine)

        # Configure button.
        self.configure_button = wx.Button(self,
                                          label=self.CONFIGURE_BUTTON_LABEL)
        self.configure_button.Bind(wx.EVT_BUTTON, self._show_config_dialog)

        # About button.
        self.about_button = wx.Button(self, label=self.ABOUT_BUTTON_LABEL)
        self.about_button.Bind(wx.EVT_BUTTON, self._show_about_dialog)

        # Machine status.
        # TODO: Figure out why spinner has darker gray background.
        self.spinner = wx.animate.GIFAnimationCtrl(self, -1, SPINNER_FILE)
        self.spinner.GetPlayer().UseBackgroundColour(True)
        self.spinner.Hide()

        self.connected_bitmap = wx.Bitmap(self.CONNECTED_IMAGE_FILE, 
                                          wx.BITMAP_TYPE_PNG)
        self.disconnected_bitmap = wx.Bitmap(self.DISCONNECTED_IMAGE_FILE, 
                                             wx.BITMAP_TYPE_PNG)
        self.connection_ctrl = wx.StaticBitmap(self, 
                                               bitmap=self.disconnected_bitmap)

        # Layout.
        global_sizer = wx.BoxSizer(wx.VERTICAL)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.status_button,
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        sizer.Add(self.configure_button,
                  flag=wx.TOP | wx.BOTTOM | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        sizer.Add(self.about_button,
                  flag=wx.TOP | wx.BOTTOM | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        global_sizer.Add(sizer)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.spinner,
                  flag=(wx.LEFT | wx.BOTTOM | wx.RIGHT | 
                        wx.ALIGN_CENTER_VERTICAL), 
                  border=self.BORDER)
        sizer.Add(self.connection_ctrl, 
                  flag=(wx.LEFT | wx.BOTTOM | wx.RIGHT | 
                        wx.ALIGN_CENTER_VERTICAL), 
                  border=self.BORDER)
        longest_machine = max(machine_registry.get_all_names(), key=len)
        longest_state = max((STATE_ERROR, STATE_INITIALIZING, STATE_RUNNING), 
                            key=len)
        longest_status = '%s: %s' % (longest_machine, longest_state)
        self.machine_status_text = wx.StaticText(self, label=longest_status)
        sizer.Add(self.machine_status_text, 
                  flag=wx.BOTTOM | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        refresh_bitmap = wx.Bitmap(self.REFRESH_IMAGE_FILE, wx.BITMAP_TYPE_PNG)          
        self.reconnect_button = wx.BitmapButton(self, bitmap=refresh_bitmap)
        sizer.Add(self.reconnect_button, 
                  flag=wx.BOTTOM | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 
                  border=self.BORDER)
        self.machine_status_sizer = sizer
        global_sizer.Add(sizer)
        self.SetSizer(global_sizer)
        global_sizer.Fit(self)
        
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.Bind(wx.EVT_CLOSE, self._quit)
        self.Bind(wx.EVT_MOVE, self.on_move)
        self.reconnect_button.Bind(wx.EVT_BUTTON, 
            lambda e: app.reset_machine(self.steno_engine, self.config))

        try:
            with open(config.target_file, 'rb') as f:
                self.config.load(f)
        except InvalidConfigurationError as e:
            self._show_alert(unicode(e))
            self.config.clear()

        self.steno_engine = app.StenoEngine()
        self.steno_engine.add_callback(
            lambda s: wx.CallAfter(self._update_status, s))
        self.steno_engine.set_output(
            Output(self.consume_command, self.steno_engine))

        while True:
            try:
                app.init_engine(self.steno_engine, self.config)
                break
            except InvalidConfigurationError as e:
                self._show_alert(unicode(e))
                dlg = ConfigurationDialog(self.steno_engine,
                                          self.config,
                                          parent=self)
                ret = dlg.ShowModal()
                if ret == wx.ID_CANCEL:
                    self._quit()
                    return
                    
        self.steno_engine.add_stroke_listener(
            StrokeDisplayDialog.stroke_handler)
        if self.config.get_show_stroke_display():
            StrokeDisplayDialog.display(self, self.config)
            
        pos = (config.get_main_frame_x(), config.get_main_frame_y())
        self.SetPosition(pos)
Exemple #11
0
    def __init__(self, parent, engine, config, on_exit):
        pos = (config.get_dictionary_editor_frame_x(),
               config.get_dictionary_editor_frame_y())
        wx.Dialog.__init__(self, parent, wx.ID_ANY, TITLE, pos, wx.DefaultSize,
                           wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                           wx.DialogNameStr)

        self.config = config
        self.on_exit = on_exit

        # layout
        global_sizer = wx.BoxSizer(wx.VERTICAL)

        filter_sizer = wx.BoxSizer(wx.HORIZONTAL)

        filter_left_sizer = wx.FlexGridSizer(2, 2, 4, 10)

        label = wx.StaticText(self, label=FILTER_BY_STROKE_TEXT)
        filter_left_sizer.Add(label,
                              flag=wx.ALIGN_CENTER_VERTICAL,
                              border=self.BORDER)

        self.filter_by_stroke = wx.TextCtrl(self,
                                            style=wx.TE_PROCESS_ENTER,
                                            size=wx.Size(200, 20))
        self.Bind(wx.EVT_TEXT_ENTER, self._do_filter, self.filter_by_stroke)
        filter_left_sizer.Add(self.filter_by_stroke)

        label = wx.StaticText(self, label=FILTER_BY_TRANSLATION_TEXT)
        filter_left_sizer.Add(label,
                              flag=wx.ALIGN_CENTER_VERTICAL,
                              border=self.BORDER)

        self.filter_by_translation = wx.TextCtrl(self,
                                                 style=wx.TE_PROCESS_ENTER,
                                                 size=wx.Size(200, 20))
        self.Bind(wx.EVT_TEXT_ENTER, self._do_filter,
                  self.filter_by_translation)
        filter_left_sizer.Add(self.filter_by_translation)

        filter_sizer.Add(filter_left_sizer, flag=wx.ALL, border=self.BORDER)

        do_filter_button = wx.Button(self, label=DO_FILTER_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._do_filter, do_filter_button)

        filter_sizer.Add(do_filter_button,
                         flag=wx.EXPAND | wx.ALL,
                         border=self.BORDER)

        global_sizer.Add(filter_sizer, flag=wx.ALL, border=self.BORDER)

        self.store = DictionaryEditorStore(engine, config)

        # Grid
        self.grid = DictionaryEditorGrid(self, size=wx.Size(800, 600))
        self.grid.CreateGrid(self.store, 0, NUM_COLS)

        self.grid.SetRowLabelSize(wx.grid.GRID_AUTOSIZE)

        self.grid.SetColSize(COL_STROKE, 250)
        self.grid.SetColSize(COL_TRANSLATION, 250)
        self.grid.SetColSize(COL_DICTIONARY, 150)

        read_only_right_aligned = wx.grid.GridCellAttr()
        read_only_right_aligned.SetReadOnly(True)
        read_only_right_aligned.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTRE)
        self.grid.SetColAttr(COL_DICTIONARY, read_only_right_aligned)
        self.grid.SetColAttr(COL_SPACER, read_only_right_aligned)

        global_sizer.Add(self.grid, 1, wx.EXPAND)

        buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)

        insert_button = wx.Button(self, label=INSERT_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._insert_new, insert_button)

        buttons_sizer.Add(insert_button, flag=wx.ALL, border=self.BORDER)

        delete_button = wx.Button(self, label=DELETE_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._delete, delete_button)

        buttons_sizer.Add(delete_button, flag=wx.ALL, border=self.BORDER)

        buttons_sizer.Add((0, 0), 1, wx.EXPAND)

        save_button = wx.Button(self, label=SAVE_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._save_close, save_button)

        buttons_sizer.Add(save_button, flag=wx.ALL, border=self.BORDER)

        cancel_button = wx.Button(self, label=CANCEL_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._cancel_close, cancel_button)

        buttons_sizer.Add(cancel_button, flag=wx.ALL, border=self.BORDER)

        global_sizer.Add(buttons_sizer,
                         0,
                         flag=wx.EXPAND | wx.ALL,
                         border=self.BORDER)

        self.Bind(wx.EVT_MOVE, self._on_move)
        self.Bind(wx.EVT_CLOSE, self._on_close)

        self.SetAutoLayout(True)
        self.SetSizer(global_sizer)
        global_sizer.Fit(self)
        global_sizer.SetSizeHints(self)
        self.Layout()
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.last_window = util.GetForegroundWindow()
Exemple #12
0
    def __init__(self, parent, config, engine):
        self.config = config
        self.engine = engine
        self.words = u''
        on_top = config.get_suggestions_display_on_top()
        style = wx.DEFAULT_DIALOG_STYLE
        style |= wx.RESIZE_BORDER
        if on_top:
            style |= wx.STAY_ON_TOP
        pos = (config.get_suggestions_display_x(),
               config.get_suggestions_display_y())
        wx.Dialog.__init__(self, parent, title=TITLE, style=style, pos=pos)

        sizer = wx.BoxSizer(wx.VERTICAL)

        self.on_top = wx.CheckBox(self, label=ON_TOP_TEXT)
        self.on_top.SetValue(config.get_suggestions_display_on_top())
        self.on_top.Bind(wx.EVT_CHECKBOX, self.handle_on_top)
        sizer.Add(self.on_top, flag=wx.ALL, border=UI_BORDER)

        sizer.Add(wx.StaticLine(self), flag=wx.EXPAND)

        self.listbox = wx.TextCtrl(self,
                                   style=wx.TE_MULTILINE | wx.TE_READONLY
                                   | wx.TE_DONTWRAP | wx.BORDER_NONE)

        standard_font = self.listbox.GetFont()
        fixed_font = find_fixed_width_font()

        # Calculate required width and height.
        display_width = len(
            system.KEY_ORDER) + 2 * STROKE_INDENT + 1  # extra +1 for /
        dc = wx.ScreenDC()
        dc.SetFont(fixed_font)
        fixed_text_size = dc.GetTextExtent(' ' * display_width)
        dc.SetFont(standard_font)
        standard_text_size = dc.GetTextExtent(' ' * display_width)

        text_width, text_height = [
            max(d1, d2) for d1, d2 in zip(fixed_text_size, standard_text_size)
        ]

        # Will show MAX_DISPLAY_LINES lines (+1 for inter-line spacings...).
        self.listbox.SetSize(
            wx.Size(text_width, text_height * (MAX_DISPLAY_LINES + 1)))

        self.history = []

        sizer.Add(self.listbox,
                  proportion=1,
                  flag=wx.ALL | wx.FIXED_MINSIZE | wx.EXPAND,
                  border=UI_BORDER)

        self.word_style = wx.TextAttr()
        self.word_style.SetFont(standard_font)
        self.word_style.SetFontStyle(wx.FONTSTYLE_NORMAL)
        self.word_style.SetFontWeight(wx.FONTWEIGHT_BOLD)
        self.word_style.SetAlignment(wx.TEXT_ALIGNMENT_LEFT)
        self.stroke_style = wx.TextAttr()
        self.stroke_style.SetFont(fixed_font)
        self.stroke_style.SetFontStyle(wx.FONTSTYLE_NORMAL)
        self.stroke_style.SetFontWeight(wx.FONTWEIGHT_NORMAL)
        self.stroke_style.SetAlignment(wx.TEXT_ALIGNMENT_LEFT)
        self.no_suggestion_style = wx.TextAttr()
        self.no_suggestion_style.SetFont(standard_font)
        self.no_suggestion_style.SetFontStyle(wx.FONTSTYLE_ITALIC)
        self.no_suggestion_style.SetFontWeight(wx.FONTWEIGHT_NORMAL)
        self.no_suggestion_style.SetAlignment(wx.TEXT_ALIGNMENT_LEFT)
        self.strokes_indent = u' ' * STROKE_INDENT
        self.no_suggestion_indent = self.strokes_indent
        self.no_suggestion_indent *= (fixed_text_size[0] /
                                      standard_text_size[0])

        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        sizer.Layout()
        sizer.Fit(self)

        self.Show()
        self.close_all()
        self.other_instances.append(self)

        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.Bind(wx.EVT_MOVE, self.on_move)
        self.Bind(wx.EVT_SIZE, self.on_resize)
Exemple #13
0
    def __init__(self, parent, config):
        self.config = config        
        on_top = config.get_stroke_display_on_top()
        style = wx.DEFAULT_DIALOG_STYLE
        if on_top:
            style |= wx.STAY_ON_TOP
        pos = (config.get_stroke_display_x(), config.get_stroke_display_y())
        wx.Dialog.__init__(self, parent, title=TITLE, style=style, pos=pos)

        sizer = wx.BoxSizer(wx.VERTICAL)

        self.on_top = wx.CheckBox(self, label=ON_TOP_TEXT)
        self.on_top.SetValue(config.get_stroke_display_on_top())
        self.on_top.Bind(wx.EVT_CHECKBOX, self.handle_on_top)
        sizer.Add(self.on_top, flag=wx.ALL, border=UI_BORDER)
        
        box = wx.BoxSizer(wx.HORIZONTAL)
        box.Add(wx.StaticText(self, label=STYLE_TEXT),
                border=UI_BORDER,
                flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT)
        self.choice = wx.Choice(self, choices=STYLES)
        self.choice.SetStringSelection(self.config.get_stroke_display_style())
        self.choice.Bind(wx.EVT_CHOICE, self.on_style)
        box.Add(self.choice, proportion=1)
        sizer.Add(box, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 
                  border=UI_BORDER)

        fixed_font = find_fixed_width_font()

        self.all_keys = ''.join(k.strip('-') for k in system.KEYS)
        self.reverse_numbers = {v: k for k, v in system.NUMBERS.items()}

        # Calculate required width and height.
        dc = wx.ScreenDC()
        dc.SetFont(fixed_font)
        # Extra spaces for Max OS X...
        text_width, text_height = dc.GetTextExtent(self.all_keys + 2 * ' ')
        scroll_width = wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
        scroll_height = wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)

        self.header = wx.StaticText(self)
        self.header.SetFont(fixed_font)
        sizer.Add(self.header, flag=wx.ALL|wx.EXPAND|wx.ALIGN_LEFT, border=UI_BORDER)

        sizer.Add(wx.StaticLine(self), flag=wx.EXPAND)

        self.listbox = wx.TextCtrl(self,
                                   style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP|wx.BORDER_NONE|wx.HSCROLL|wx.VSCROLL,
                                   # Will show MAX_STROKE_LINES lines.
                                   size=wx.Size(scroll_width + text_width,
                                                scroll_height + text_height * MAX_STROKE_LINES))
        self.listbox.SetFont(fixed_font)

        sizer.Add(self.listbox,
                  flag=wx.ALL|wx.EXPAND|wx.ALIGN_LEFT,
                  border=UI_BORDER)

        buttons = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(buttons, flag=wx.EXPAND|wx.ALL)

        clear_button = wx.Button(self, id=wx.ID_CLEAR, label=CLEAR_BUTTON_NAME)
        buttons.AddSpacer(5)
        buttons.Add(clear_button, flag=wx.EXPAND|wx.ALIGN_LEFT)
        self.Bind(wx.EVT_BUTTON, self._clear, clear_button)
        buttons.AddStretchSpacer()
        save_button = wx.Button(self, id=wx.ID_SAVE, label=SAVE_BUTTON_NAME)
        buttons.Add(save_button, flag=wx.EXPAND|wx.ALIGN_RIGHT)
        buttons.AddSpacer(5)
        self.Bind(wx.EVT_BUTTON, self._save, save_button)

        sizer.AddSpacer(5)

        self.on_style()

        self.SetSizerAndFit(sizer)

        self.Show()
        self.close_all()
        self.other_instances.append(self)
        
        self.SetRect(AdjustRectToScreen(self.GetRect()))
        
        self.Bind(wx.EVT_MOVE, self.on_move)
Exemple #14
0
    def __init__(self, serial, parent, config):
        """Create a configuration GUI for the given serial port.

        Arguments:

        serial -- An object containing all the current serial options. This 
        object will be modified when pressing the OK button. The object will not 
        be changed if the cancel button is pressed.

        parent -- See wx.Dialog.
        
        config -- The config object that holds plover's settings.

        """
        self.config = config
        pos = (config.get_serial_config_frame_x(), 
               config.get_serial_config_frame_y())
        wx.Dialog.__init__(self, parent, title=DIALOG_TITLE, pos=pos)

        self.serial = serial

        # Create and layout components. Components must be created after the 
        # static box that contains them or they will be unresponsive on OSX.

        global_sizer = wx.BoxSizer(wx.VERTICAL)

        static_box = wx.StaticBox(self, label=CONNECTION_STR)
        outline_sizer = wx.StaticBoxSizer(static_box, wx.VERTICAL)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, label=PORT_STR),
                    proportion=1,
                    flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                    border=LABEL_BORDER)
        self.port_combo_box = wx.ComboBox(self,
                                          choices=[],
                                          style=wx.CB_DROPDOWN)
        sizer.Add(self.port_combo_box, flag=wx.ALIGN_CENTER_VERTICAL)
        self.scan_button = wx.Button(self, label=SCAN_STR)
        sizer.Add(self.scan_button, flag=wx.ALIGN_CENTER_VERTICAL)
        self.loading_text = wx.StaticText(self, label=LOADING_STR)
        sizer.Add(self.loading_text,
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=LABEL_BORDER)
        self.loading_text.Hide()
        self.gif = wx.animate.GIFAnimationCtrl(self, -1, SPINNER_FILE)
        self.gif.GetPlayer().UseBackgroundColour(True)
        # Need to call this so the size of the control is not
        # messed up (100x100 instead of 16x16) on Linux...
        self.gif.InvalidateBestSize()
        self.gif.Hide()
        sizer.Add(self.gif, flag=wx.ALIGN_CENTER_VERTICAL)
        outline_sizer.Add(sizer, flag=wx.EXPAND)
        self.port_sizer = sizer

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, label=BAUDRATE_STR),
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=LABEL_BORDER)
        self.baudrate_choice = wx.Choice(self,
                                         choices=map(str, Serial.BAUDRATES))
        sizer.Add(self.baudrate_choice, flag=wx.ALIGN_RIGHT)
        outline_sizer.Add(sizer, flag=wx.EXPAND)
        global_sizer.Add(outline_sizer,
                         flag=wx.EXPAND | wx.ALL, border=GLOBAL_BORDER)

        static_box = wx.StaticBox(self, label=DATA_FORMAT_STR)
        outline_sizer = wx.StaticBoxSizer(static_box, wx.VERTICAL)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, label=DATA_BITS_STR),
                  proportion=5,
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=LABEL_BORDER)
        self.databits_choice = wx.Choice(self,
                                         choices=map(str, Serial.BYTESIZES))
        sizer.Add(self.databits_choice, proportion=3, flag=wx.ALIGN_RIGHT)
        outline_sizer.Add(sizer, flag=wx.EXPAND)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, label=STOP_BITS_STR),
                  proportion=5,
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=LABEL_BORDER)
        self.stopbits_choice = wx.Choice(self,
                                         choices=map(str, Serial.STOPBITS))
        sizer.Add(self.stopbits_choice, proportion=3, flag=wx.ALIGN_RIGHT)
        outline_sizer.Add(sizer, flag=wx.EXPAND)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(wx.StaticText(self, label=PARITY_STR),
                  proportion=5,
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=LABEL_BORDER)
        self.parity_choice = wx.Choice(self,
                                       choices=map(str, Serial.PARITIES))
        sizer.Add(self.parity_choice, proportion=3, flag=wx.ALIGN_RIGHT)
        outline_sizer.Add(sizer, flag=wx.EXPAND)
        global_sizer.Add(outline_sizer,
                         flag=wx.EXPAND | wx.ALL, border=GLOBAL_BORDER)

        static_box = wx.StaticBox(self, label=TIMEOUT_STR)
        outline_sizer = wx.StaticBoxSizer(static_box, wx.HORIZONTAL)
        self.timeout_checkbox = wx.CheckBox(self, label=USE_TIMEOUT_STR)
        outline_sizer.Add(self.timeout_checkbox,
                          flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                          border=LABEL_BORDER)
        self.timeout_text_ctrl = wx.TextCtrl(self,
                                             value='',
                                             validator=FloatValidator())
        outline_sizer.Add(self.timeout_text_ctrl)
        outline_sizer.Add(wx.StaticText(self, label=SECONDS_STR),
                          flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                          border=LABEL_BORDER)
        global_sizer.Add(outline_sizer, flag=wx.ALL, border=GLOBAL_BORDER)

        static_box = wx.StaticBox(self, label=FLOW_CONTROL_STR)
        outline_sizer = wx.StaticBoxSizer(static_box, wx.HORIZONTAL)
        self.rtscts_checkbox = wx.CheckBox(self, label=RTS_CTS_STR)
        outline_sizer.Add(self.rtscts_checkbox,
                          flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                          border=LABEL_BORDER)
        self.xonxoff_checkbox = wx.CheckBox(self, label=XON_XOFF_STR)
        outline_sizer.Add(self.xonxoff_checkbox,
                          flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                          border=LABEL_BORDER)
        outline_sizer.Add((10, 10), proportion=1, flag=wx.EXPAND)
        global_sizer.Add(outline_sizer,
                         flag=wx.EXPAND | wx.ALL,
                         border=GLOBAL_BORDER)

        self.ok_button = wx.Button(self, label=OK_STR)
        cancel_button = wx.Button(self, label=CANCEL_STR)
        self.ok_button.SetDefault()
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.ok_button)
        sizer.Add(cancel_button)
        global_sizer.Add(sizer,
                         flag=wx.ALL | wx.ALIGN_RIGHT,
                         border=GLOBAL_BORDER)

        # Bind events.
        self.Bind(wx.EVT_BUTTON, self._on_ok, self.ok_button)
        self.Bind(wx.EVT_BUTTON, self._on_cancel, cancel_button)
        self.Bind(wx.EVT_CHECKBOX,
                  self._on_timeout_select,
                  self.timeout_checkbox)
        self.Bind(wx.EVT_BUTTON, self._on_scan, self.scan_button)

        self.SetAutoLayout(True)
        self.SetSizer(global_sizer)
        global_sizer.Fit(self)
        global_sizer.SetSizeHints(self)
        self.Layout()
        self.SetRect(AdjustRectToScreen(self.GetRect()))
        
        self.Bind(wx.EVT_MOVE, self.on_move)
        self.Bind(wx.EVT_CLOSE, self._on_cancel)
        
        self._update()
        self.scan_pending = False
        self.closed = False
        
        if serial.port and serial.port != 'None':
            self.port_combo_box.SetValue(serial.port)
        else:
            self._on_scan()
Exemple #15
0
    def __init__(self, parent, engine, config):
        pos = (config.get_dictionary_editor_frame_x(),
               config.get_dictionary_editor_frame_y())
        wx.Dialog.__init__(self, parent, wx.ID_ANY, TITLE, pos, wx.DefaultSize,
                           wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                           wx.DialogNameStr)

        self.config = config

        self.show_closing_prompt = True

        # layout
        global_sizer = wx.BoxSizer(wx.VERTICAL)

        filter_sizer = wx.BoxSizer(wx.HORIZONTAL)

        filter_left_sizer = wx.FlexGridSizer(2, 2, 4, 10)

        label = wx.StaticText(self, label=FILTER_BY_STROKE_TEXT)
        filter_left_sizer.Add(label,
                              flag=wx.ALIGN_CENTER_VERTICAL,
                              border=self.BORDER)

        self.filter_by_stroke = wx.TextCtrl(self,
                                            style=wx.TE_PROCESS_ENTER,
                                            size=wx.Size(200, 20))
        self.Bind(wx.EVT_TEXT_ENTER, self._do_filter, self.filter_by_stroke)
        filter_left_sizer.Add(self.filter_by_stroke)

        label = wx.StaticText(self, label=FILTER_BY_TRANSLATION_TEXT)
        filter_left_sizer.Add(label,
                              flag=wx.ALIGN_CENTER_VERTICAL,
                              border=self.BORDER)

        self.filter_by_translation = wx.TextCtrl(self,
                                                 style=wx.TE_PROCESS_ENTER,
                                                 size=wx.Size(200, 20))
        self.Bind(wx.EVT_TEXT_ENTER, self._do_filter,
                  self.filter_by_translation)
        filter_left_sizer.Add(self.filter_by_translation)

        filter_sizer.Add(filter_left_sizer, flag=wx.ALL, border=self.BORDER)

        do_filter_button = wx.Button(self, label=DO_FILTER_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._do_filter, do_filter_button)

        filter_sizer.Add(do_filter_button,
                         flag=wx.EXPAND | wx.ALL,
                         border=self.BORDER)

        global_sizer.Add(filter_sizer, flag=wx.ALL, border=self.BORDER)

        self.store = DictionaryEditorStore(engine, config)

        # grid
        self.grid = DictionaryEditorGrid(self, size=wx.Size(800, 600))
        self.grid.CreateGrid(self.store, 0, 3)
        self.grid.SetColSize(0, 250)
        self.grid.SetColSize(1, 250)
        self.grid.SetColSize(2, 180)
        global_sizer.Add(self.grid, 1, wx.EXPAND)

        buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)

        insert_button = wx.Button(self, label=INSERT_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._insert_new, insert_button)

        buttons_sizer.Add(insert_button, flag=wx.ALL, border=self.BORDER)

        delete_button = wx.Button(self, label=DELETE_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._delete, delete_button)

        buttons_sizer.Add(delete_button, flag=wx.ALL, border=self.BORDER)

        buttons_sizer.Add((0, 0), 1, wx.EXPAND)

        save_button = wx.Button(self, label=SAVE_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._save_close, save_button)

        buttons_sizer.Add(save_button, flag=wx.ALL, border=self.BORDER)

        cancel_button = wx.Button(self, label=CANCEL_BUTTON_NAME)
        self.Bind(wx.EVT_BUTTON, self._cancel_close, cancel_button)

        buttons_sizer.Add(cancel_button, flag=wx.ALL, border=self.BORDER)

        global_sizer.Add(buttons_sizer,
                         0,
                         flag=wx.EXPAND | wx.ALL,
                         border=self.BORDER)

        self.Bind(wx.EVT_MOVE, self._on_move)
        self.Bind(wx.EVT_CLOSE, self._on_close)

        self.SetAutoLayout(True)
        self.SetSizer(global_sizer)
        global_sizer.Fit(self)
        global_sizer.SetSizeHints(self)
        self.Layout()
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        self.last_window = util.GetForegroundWindow()

        # Now that we saved the last window we'll close other instances. This
        # may restore their original window but we've already saved ours so it's
        # fine.
        for instance in self.other_instances:
            instance.Close()
        del self.other_instances[:]
        self.other_instances.append(self)
Exemple #16
0
    def __init__(self, parent, engine, config):
        pos = (config.get_translation_frame_x(),
               config.get_translation_frame_y())
        wx.Dialog.__init__(self, parent, title=TITLE, pos=pos)

        opacity = config.get_translation_frame_opacity()
        self._apply_opacity(opacity)

        self.config = config

        # components
        self.strokes_text = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
        self.translation_text = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
        button = wx.Button(self, id=wx.ID_OK, label='Add to dictionary')
        cancel = wx.Button(self, id=wx.ID_CANCEL, label='Cancel')
        self.stroke_mapping_text = wx.StaticText(self)
        self.translation_mapping_text = wx.StaticText(self)

        # layout
        global_sizer = wx.BoxSizer(wx.VERTICAL)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        label = wx.StaticText(self, label=self.STROKES_TEXT)
        sizer.Add(label,
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        sizer.Add(self.strokes_text,
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM
                  | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        label = wx.StaticText(self, label=self.TRANSLATION_TEXT)
        sizer.Add(label,
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM
                  | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        sizer.Add(self.translation_text,
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM
                  | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        sizer.Add(button,
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM
                  | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        sizer.Add(cancel,
                  flag=wx.TOP | wx.RIGHT | wx.BOTTOM
                  | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        global_sizer.Add(sizer)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.stroke_mapping_text,
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        global_sizer.Add(sizer)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.translation_mapping_text,
                  flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                  border=self.BORDER)
        global_sizer.Add(sizer)

        self.SetAutoLayout(True)
        self.SetSizer(global_sizer)
        global_sizer.Fit(self)
        global_sizer.SetSizeHints(self)
        self.Layout()
        self.SetRect(AdjustRectToScreen(self.GetRect()))

        # events
        button.Bind(wx.EVT_BUTTON, self.on_add_translation)
        cancel.Bind(wx.EVT_BUTTON, self.on_close)
        self.strokes_text.Bind(wx.EVT_TEXT, self.on_strokes_change)
        self.translation_text.Bind(wx.EVT_TEXT, self.on_translation_change)
        self.strokes_text.Bind(wx.EVT_SET_FOCUS, self.on_strokes_gained_focus)
        self.strokes_text.Bind(wx.EVT_TEXT_ENTER, self.on_add_translation)
        self.translation_text.Bind(wx.EVT_SET_FOCUS,
                                   self.on_translation_gained_focus)
        self.translation_text.Bind(wx.EVT_TEXT_ENTER, self.on_add_translation)
        self.Bind(wx.EVT_ACTIVATE, self.on_activate)
        self.Bind(wx.EVT_CLOSE, self.on_close)
        self.Bind(wx.EVT_MOVE, self.on_move)

        self.engine = engine

        # TODO: add functions on engine for state
        self.previous_state = self.engine.translator.get_state()
        self.previous_start_attached = self.engine.formatter.start_attached
        self.previous_start_capitalized = self.engine.formatter.start_capitalized
        # TODO: use state constructor?
        self.engine.translator.clear_state()
        self.strokes_state = self.engine.translator.get_state()
        self.engine.translator.clear_state()
        self.translation_state = self.engine.translator.get_state()

        self._restore_engine_state()

        self.last_window = util.GetForegroundWindow()

        # Now that we saved the last window we'll close other instances. This
        # may restore their original window but we've already saved ours so it's
        # fine.
        for instance in self.other_instances:
            instance.Close()
        del self.other_instances[:]
        self.other_instances.append(self)

        self._focus = None