예제 #1
0
    def show_suggestions(self, suggestion_list):

        # Limit history.
        undo_levels = self.config.get_undo_levels()
        while len(self.history) >= undo_levels:
            _, text_length = self.history.pop(0)
            last_position = self.listbox.GetLastPosition()
            self.listbox.Remove(last_position - text_length, last_position)
        # Insert last entry on top.
        self.listbox.SetInsertionPoint(0)

        # Find available text width.
        max_width = self.listbox.Size[0]
        # Yes, 2 times the scrollbar width, because...
        max_width -= 2 * wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
        dc = wx.ScreenDC()
        dc.SetFont(self.stroke_style.GetFont())

        for suggestion in suggestion_list:
            self.listbox.SetDefaultStyle(self.word_style)
            self.listbox.WriteText(
                shorten_unicode(escape_translation(suggestion.text)) + u'\n'
            )
            if not suggestion.steno_list:
                self.listbox.SetDefaultStyle(self.no_suggestion_style)
                self.listbox.WriteText(self.no_suggestion_indent)
                self.listbox.WriteText(u'No suggestions\n')
                continue
            self.listbox.SetDefaultStyle(self.stroke_style)
            # Limit arbitrarily to 10 suggestions per word.
            for stroke_list in suggestion.steno_list[:10]:
                line_text = None
                for n, stroke in enumerate(stroke_list):
                    if 0 == n:
                        line_text = text = self.strokes_indent + stroke
                    else:
                        text = u'/' + stroke
                        line_text += text
                        if dc.GetTextExtent(line_text)[0] >= max_width:
                            line_text = 2 * self.strokes_indent + text
                            text = u'\n' + line_text
                    self.listbox.WriteText(shorten_unicode(text))
                self.listbox.WriteText(u'\n')

        length = self.listbox.GetInsertionPoint()
        assert length
        self.history.append((suggestion_list, length))
        # Reset style after final \n, so following
        # word is correctly displayed.
        self.listbox.SetDefaultStyle(self.word_style)
        self.listbox.WriteText('')
        # Make sure first line is shown.
        self.listbox.ShowPosition(0)
예제 #2
0
    def show_suggestions(self, suggestion_list):

        # Limit history.
        undo_levels = self.config.get_undo_levels()
        while len(self.history) >= undo_levels:
            _, text_length = self.history.pop(0)
            last_position = self.listbox.GetLastPosition()
            self.listbox.Remove(last_position - text_length, last_position)
        # Insert last entry on top.
        self.listbox.SetInsertionPoint(0)

        # Find available text width.
        max_width = self.listbox.Size[0]
        # Yes, 2 times the scrollbar width, because...
        max_width -= 2 * wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
        dc = wx.ScreenDC()
        dc.SetFont(self.stroke_style.GetFont())

        for suggestion in suggestion_list:
            self.listbox.SetDefaultStyle(self.word_style)
            self.listbox.WriteText(
                shorten_unicode(escape_translation(suggestion.text)) + u'\n')
            if not suggestion.steno_list:
                self.listbox.SetDefaultStyle(self.no_suggestion_style)
                self.listbox.WriteText(self.no_suggestion_indent)
                self.listbox.WriteText(u'No suggestions\n')
                continue
            self.listbox.SetDefaultStyle(self.stroke_style)
            # Limit arbitrarily to 10 suggestions per word.
            for stroke_list in suggestion.steno_list[:10]:
                line_text = None
                for n, stroke in enumerate(stroke_list):
                    if 0 == n:
                        line_text = text = self.strokes_indent + stroke
                    else:
                        text = u'/' + stroke
                        line_text += text
                        if dc.GetTextExtent(line_text)[0] >= max_width:
                            line_text = 2 * self.strokes_indent + text
                            text = u'\n' + line_text
                    self.listbox.WriteText(shorten_unicode(text))
                self.listbox.WriteText(u'\n')

        length = self.listbox.GetInsertionPoint()
        assert length
        self.history.append((suggestion_list, length))
        # Reset style after final \n, so following
        # word is correctly displayed.
        self.listbox.SetDefaultStyle(self.word_style)
        self.listbox.WriteText('')
        # Make sure first line is shown.
        self.listbox.ShowPosition(0)
    def GetValue(self, row, col):
        item = self.sorted_keys[row]
        result = ""

        if col is COL_STROKE:
            result = item.stroke
        elif col is COL_TRANSLATION:
            result = shorten_unicode(item.translation)
        elif col is COL_DICTIONARY:
            result = item.dictionary
        return result
예제 #4
0
    def GetValue(self, row, col):
        item = self.sorted_keys[row]
        result = ""

        if col is COL_STROKE:
            result = item.stroke
        elif col is COL_TRANSLATION:
            result = shorten_unicode(item.translation)
        elif col is COL_DICTIONARY:
            result = item.dictionary.get_path()
        return result
예제 #5
0
 def on_strokes_change(self, event):
     key = self._normalized_strokes()
     if key:
         d = self.engine.get_dictionary()
         translation = d.raw_lookup(key)
         strokes = '/'.join(key)
         if translation:
             label = '%s maps to %s' % (strokes, escape_translation(translation))
         else:
             label = '%s is not in the dictionary' % strokes
         label = util.shorten_unicode(label)
     else:
         label = ''
     self.stroke_mapping_text.SetLabel(label)
     self.GetSizer().Layout()
예제 #6
0
 def on_strokes_change(self, event):
     key = self._normalized_strokes()
     if key:
         d = self.engine.get_dictionary()
         translation = d.raw_lookup(key)
         strokes = '/'.join(key)
         if translation:
             label = '%s maps to %s' % (strokes, translation)
         else:
             label = '%s is not in the dictionary' % strokes
         label = util.shorten_unicode(label)
     else:
         label = ''
     self.stroke_mapping_text.SetLabel(label)
     self.GetSizer().Layout()
예제 #7
0
 def on_translation_change(self, event):
     # TODO: normalize dict entries to make reverse lookup more reliable
     # with whitespace.
     translation = event.GetString().strip()
     if translation:
         d = self.engine.get_dictionary()
         strokes_list = d.reverse_lookup(unescape_translation(translation))
         if strokes_list:
             strokes = ', '.join('/'.join(x) for x in strokes_list)
             label = '%s is mapped from %s' % (translation, strokes)
         else:
             label = '%s is not in the dictionary' % translation
         label = util.shorten_unicode(label)
     else:
         label = ''
     self.translation_mapping_text.SetLabel(label)
     self.GetSizer().Layout()
예제 #8
0
 def on_translation_change(self, event):
     # TODO: normalize dict entries to make reverse lookup more reliable
     # with whitespace.
     translation = event.GetString().strip()
     if translation:
         d = self.engine.get_dictionary()
         strokes_list = d.reverse_lookup(unescape_translation(translation))
         if strokes_list:
             strokes = ', '.join('/'.join(x) for x in strokes_list)
             label = '%s is mapped from %s' % (translation, strokes)
         else:
             label = '%s is not in the dictionary' % translation
         label = util.shorten_unicode(label)
     else:
         label = ''
     self.translation_mapping_text.SetLabel(label)
     self.GetSizer().Layout()