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)
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)
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() # Calculate required width and height. dc = wx.ScreenDC() dc.SetFont(fixed_font) # Extra spaces for Max OS X... text_width, text_height = dc.GetTextExtent(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, # 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) 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)
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)
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(x[0].strip('-') for x in sorted(system.KEY_ORDER.items(), key=lambda x: x[1])) 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)