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)
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()
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) self.config = config # components self.translation_text = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER) cancel = wx.Button(self, id=wx.ID_CANCEL) self.listbox = wx.ListBox(self, size=wx.Size(210, 200)) # layout global_sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, label=self.TRANSLATION_TEXT) sizer.Add(label, flag=wx.TOP | wx.LEFT | 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(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.listbox, flag=wx.ALL | wx.FIXED_MINSIZE, 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 # 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.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.translation_text.Bind(wx.EVT_TEXT_ENTER, self.on_close) 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)
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)
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