def __init__(self, parent): wx.Dialog.__init__(self, parent, title=_('Flatten text')) sizer = wx.BoxSizer(wx.VERTICAL) self._scope_box = wx.RadioBox(self, label=_('Scope') + ':', choices=(_('current page'), _('all pages')), style=wx.RA_HORIZONTAL) self._zone_box = wx.RadioBox( self, label=_('Remove details') + ':', choices=[label for label, type in ZONES_MAP], style=wx.RA_SPECIFY_COLS, majorDimension=2) self._zone_box.SetSelection(len(ZONES_MAP) - 1) for box in self._scope_box, self._zone_box: sizer.Add(box, 0, wx.EXPAND | wx.ALL, 5) line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 5) button_sizer = wx.StdDialogButtonSizer() button = wx.Button(self, wx.ID_OK) button.SetDefault() button_sizer.AddButton(button) button = wx.Button(self, wx.ID_CANCEL) button_sizer.AddButton(button) button_sizer.Realize() sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, 5) self.SetSizerAndFit(sizer)
def __init__(self, parent): wx.Dialog.__init__(self, parent, title=_('Flatten text')) sizer = wx.BoxSizer(wx.VERTICAL) self._scope_box = wx.RadioBox(self, label=(_('Scope') + ':'), choices=(_('current page'), _('all pages')), style=wx.RA_HORIZONTAL ) self._zone_box = wx.RadioBox(self, label=(_('Remove details') + ':'), choices=[label for label, type in ZONES_MAP], style=wx.RA_SPECIFY_COLS, majorDimension=2 ) self._zone_box.SetSelection(len(ZONES_MAP) - 1) for box in self._scope_box, self._zone_box: sizer.Add(box, 0, wx.EXPAND | wx.ALL, 5) line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 5) button_sizer = wx.StdDialogButtonSizer() button = wx.Button(self, wx.ID_OK) button.SetDefault() button_sizer.AddButton(button) button = wx.Button(self, wx.ID_CANCEL) button_sizer.AddButton(button) button_sizer.Realize() sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, 5) self.SetSizerAndFit(sizer)
def _setup_main_properties_box(self): node = self._node box = wx.StaticBox(self, label=_('Main properties')) box_sizer = wx.StaticBoxSizer(box) grid_sizer = wx.FlexGridSizer(0, 2, 5, 5) uri_label = wx.StaticText(self, label='URI: ') uri_edit = wx.TextCtrl(self, size=(self.DEFAULT_TEXT_WIDTH, -1)) if node is not None: uri_edit.SetValue(self._node.uri) target_label = wx.StaticText(self, label=(_('Target frame') + ': ')) target_edit = wx.ComboBox(self, size=(self.DEFAULT_TEXT_WIDTH, -1), style=wx.CB_DROPDOWN, choices=HTML_TARGETS ) if node is not None: target_edit.SetValue(self._node.target or '') comment_label = wx.StaticText(self, label=(_('Comment') + ': ')) comment_edit = wx.TextCtrl(self, size=(self.DEFAULT_TEXT_WIDTH, -1)) if node is not None: comment_edit.SetValue(self._node.comment) for widget in uri_label, uri_edit, target_label, target_edit, comment_label, comment_edit: grid_sizer.Add(widget) box_sizer.Add(grid_sizer, 0, wx.EXPAND | wx.ALL, 5) self._edit_uri = uri_edit self._edit_target = target_edit self._edit_comment = comment_edit return box_sizer
def _create_settings_menu(self): menu = wx.Menu() menu_item = functools.partial(self._create_menu_item, menu) sidebar_menu_item = menu_item(_('Show &sidebar') + '\tF9', _('Show/hide the sidebar'), self.on_show_sidebar, style=wx.ITEM_CHECK) if self.default_sidebar_shown: sidebar_menu_item.Check() menu_item(_(u'External editor…'), _('Setup an external editor'), self.on_setup_external_editor) return menu
def _create_go_menu(self): menu = wx.Menu() menu_item = functools.partial(self._create_menu_item, menu) for caption, help, method, icon in [ (_('&First page') + '\tCtrl-Home', _('Jump to first document page'), self.on_first_page, None), (_('&Previous page') + '\tPgUp', _('Jump to previous document page'), self.on_previous_page, wx.ART_GO_UP), (_('&Next page') + '\tPgDn', _('Jump to next document page'), self.on_next_page, wx.ART_GO_DOWN), (_('&Last page') + '\tCtrl-End', _('Jump to last document page'), self.on_last_page, None), (_(u'&Go to page…') + '\tCtrl-G', _(u'Jump to page…'), self.on_goto_page, None) ]: menu_item(caption, help, method, icon=icon) return menu
def on_setup_external_editor(self, event): dialog = wx.TextEntryDialog(self, caption=_('Setup an external editor'), message=_('Enter path to your favourite text editor.') ) try: dialog.SetValue(self.default_editor_path or '') if dialog.ShowModal() == wx.ID_OK: self.default_editor_path = dialog.GetValue() self.setup_external_editor() finally: dialog.Destroy()
def on_edit_metadata(self, event): document_metadata_model = self.metadata_model[models.SHARED_ANNOTATIONS_PAGENO].clone() document_metadata_model.title = _('Document metadata') page_metadata_model = self.metadata_model[self.page_no].clone() page_metadata_model.title = _('Page %d metadata') % (self.page_no + 1) dialog = MetadataDialog(self, models=(document_metadata_model, page_metadata_model), known_keys=djvu.const.METADATA_KEYS) try: if dialog.ShowModal() == wx.ID_OK: self.metadata_model[models.SHARED_ANNOTATIONS_PAGENO] = document_metadata_model self.metadata_model[self.page_no] = page_metadata_model self.dirty = True finally: dialog.Destroy()
def on_about(self, event): message = ( '%(app)s %(version)s\n' + _('Author') + ': %(author)s\n' + _('License') + ': %(license)s' ) message = message % dict( app=APPLICATION_NAME, version=__version__, author=__author__, license=LICENSE ) wx.MessageBox(message=message, caption=_(u'About…'))
def show_menu(parent, annotations, node, point, origin=None): menu = wx.Menu() try: menu_item = menu.Append(wx.ID_ANY, _(u'&New hyperlink…')) parent.Bind(wx.EVT_MENU, lambda event: on_new_annotation(event, parent, annotations, origin), menu_item) if node is not None: menu_item = menu.Append(wx.ID_ANY, _(u'&Properties…')) parent.Bind(wx.EVT_MENU, lambda event: on_properties(event, parent, node), menu_item) menu_item = menu.Append(wx.ID_ANY, _('&Remove') + '\tDel') parent.Bind(wx.EVT_MENU, lambda event: on_delete(event, parent, node), menu_item) del menu_item parent.PopupMenu(menu, point) finally: menu.Destroy()
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.LC_REPORT): wx.ListCtrl.__init__(self, parent, id, pos, size, style) self.InsertColumn(0, _('URI')) self.InsertColumn(1, _('Comment')) self._have_items = False self._data = {} self._data_map = {} self.page = None wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin.__init__(self) wx.lib.mixins.listctrl.TextEditMixin.__init__(self) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_selection_changed, self) self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.on_item_right_click, self) self.Bind(wx.EVT_CHAR, self.on_char, self) self.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
def do_save(self): if not self.dirty: return True queue = Queue() sed = StreamEditor(self.path, autosave=True) for model in self.models: model.export(sed) def job(): try: sed.commit() self.document = self.context.new_document(djvu.decode.FileURI(self.path)) for model in self.models: model.reset_document(self.document) except Exception as exception: pass else: exception = None queue.put(exception) thread = threading.Thread(target=job) thread.start() dialog = None try: try: exception = queue.get(block=True, timeout=0.1) if exception is not None: self.on_save_failed(exception) return False except QueueEmpty: dialog = dialogs.ProgressDialog( title=_('Saving document'), message=_(u'Saving the document, please wait…'), parent=self, style=(wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME), ) while dialog is not None: try: exception = queue.get(block=True, timeout=0.1) if exception is not None: self.on_save_failed(exception) return False break except QueueEmpty: dialog.Pulse() finally: thread.join() if dialog is not None: dialog.Destroy() self.dirty = False return True
def __init__(self): self._config = wx.GetApp().config # The ._config attribute should not be accessed directly, but only # via .default_* properties. # Use .save_defaults() to save the config file. x, y, w, h = self.default_xywh wx.Frame.__init__(self, None, pos=(x, y), size=(w, h)) self.setup_external_editor() self.Bind(wx.EVT_DJVU_MESSAGE, self.handle_message) self.context = Context(self) self._page_text_callback = PageTextCallback(self) self._page_annotations_callback = PageAnnotationsCallback(self) self._outline_callback = OutlineCallback(self) self.status_bar = self.CreateStatusBar(2, style=wx.ST_SIZEGRIP) self.splitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE) self.splitter.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.on_splitter_sash_changed) self.sidebar = wx.Notebook(self.splitter, wx.ID_ANY) self.text_browser = TextBrowser(self.sidebar) self.outline_browser = OutlineBrowser(self.sidebar) self.maparea_browser = MapAreaBrowser(self.sidebar) self.sidebar.AddPage(self.outline_browser, _('Outline')) self.sidebar.AddPage(self.maparea_browser, _('Hyperlinks')) self.sidebar.AddPage(self.text_browser, _('Text')) self.sidebar.Bind( wx.EVT_NOTEBOOK_PAGE_CHANGED, self._on_sidebar_page_changed( self.on_display_no_nonraster, self.on_display_maparea, self.on_display_text) ) self.scrolled_panel = ScrolledPanel(self.splitter) self.splitter.SetSashGravity(0.1) self.do_show_sidebar() if not self.default_sidebar_shown: self.do_hide_sidebar() sizer = wx.BoxSizer(wx.VERTICAL) self.scrolled_panel.SetSizer(sizer) self.scrolled_panel.SetupScrolling() self.page_widget = PageWidget(self.scrolled_panel) self.page_widget.Bind(wx.EVT_CHAR, self.on_char) self.scrolled_panel.Bind(wx.EVT_SIZE, self.page_widget.on_parent_resize) sizer.Add(self.page_widget, 0, wx.ALL, 0) self.editable_menu_items = [] self.saveable_menu_items = [] self.file_history = FileHistory(self._config) self.create_menus() self.dirty = False self.do_open(None) self.Bind(wx.EVT_CLOSE, self.on_exit)
def on_external_edit_text(self, event): sexpr = self.text_model[self.page_no].raw_value if not sexpr: self.error_box(_('No text layer to edit.')) return def job(disabler): new_sexpr = None try: with external_editor.temporary_file('text.txt') as tmp_file: text_mangle.export(sexpr, tmp_file) tmp_file.flush() self.external_editor(tmp_file.name) tmp_file.seek(0) try: new_sexpr = text_mangle.import_(sexpr, tmp_file) except text_mangle.NothingChanged: pass except Exception as exception: pass else: exception = None wx.CallAfter(self.after_external_edit_text, new_sexpr, disabler, exception) disabler = exception = None disabler = wx.WindowDisabler() thread = threading.Thread(target=job, args=(disabler,)) thread.start()
def on_goto_page(self, event): dialog = dialogs.NumberEntryDialog( parent=self, message=(_('Go to page') + ':'), prompt='', caption=_('Go to page'), value=self.page_no + 1, min=1, max=len(self.document.pages) ) try: rc = dialog.ShowModal() if rc == wx.ID_OK: self.page_no = dialog.GetValue() - 1 finally: dialog.Destroy()
def after_external_edit_text(self, sexpr, disabler, exception): if exception is not None: try: raise exception except text_mangle.CharacterZoneFound: self.error_box(_('Cannot edit text with character zones.')) return except text_mangle.LengthChanged: self.error_box(_('Number of lines changed.')) return except Exception: self.on_external_edit_failed(exception) return if sexpr is None: # nothing changed return self.text_model[self.page_no].raw_value = sexpr
def _create_file_menu(self): menu = wx.Menu() menu_item = functools.partial(self._create_menu_item, menu) menu_item(_('&Open') + '\tCtrl+O', _('Open a DjVu document'), self.on_open, icon=wx.ART_FILE_OPEN) recent_menu = wx.Menu() recent_menu_item = menu.AppendMenu(wx.ID_ANY, _('Open &recent'), recent_menu) self.file_history.set_menu(self, recent_menu_item, self.do_open) save_menu_item = menu_item(_('&Save') + '\tCtrl+S', _('Save the document'), self.on_save, icon=wx.ART_FILE_SAVE) close_menu_item = menu_item(_('&Close') + '\tCtrl+W', _('Close the document'), self.on_close, id=wx.ID_CLOSE) self.editable_menu_items += close_menu_item, self.saveable_menu_items += save_menu_item, menu.AppendSeparator() menu_item(_('&Quit') + '\tCtrl+Q', _('Quit the application'), self.on_exit, icon=wx.ART_QUIT) return menu
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.LC_REPORT): wx.ListCtrl.__init__(self, parent, id, pos, size, style) self.InsertColumn(0, _('URI')) self.InsertColumn(1, _('Comment')) self._have_items = False self._data = {} self._data_map = {} self.page = None wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin.__init__(self) wx.lib.mixins.listctrl.TextEditMixin.__init__(self) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_selection_changed, self) self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.on_item_right_click, self) self.Bind(wx.EVT_CHAR, self.on_char, self)
def set(self, n): if self.document is None: self._page_no = 0 self.status_bar.SetStatusText('', 1) return if n < 0 or n >= len(self.document.pages): return self._page_no = n self.status_bar.SetStatusText(_('Page %(pageno)d of %(npages)d') % {'pageno': (n + 1), 'npages': len(self.document.pages)}, 1) self.update_page_widget(new_page=True)
def _create_root_item(self): node = self.document.outline.root if node: type = str(node.type) self._root_item = self.AddRoot(_(type)) self.SetPyData(self._root_item, node) return True else: self._root_item = None return False
def _setup_shape_box(self): box = wx.RadioBox(self, label=_('Shape'), choices=[shape.label for shape in SHAPES] ) for i, shape in enumerate(SHAPES): box.EnableItem(i, shape.enabled) self.Bind(wx.EVT_RADIOBOX, self.on_select_shape, box) self._edit_shape = box # It's too early to select proper shape. We'll do it later. return box
def create_menus(self): menu_bar = wx.MenuBar() menu_bar.Append(self._create_file_menu(), _('&File')) menu_bar.Append(self._create_edit_menu(), _('&Edit')) menu_bar.Append(self._create_view_menu(), _('&View')) menu_bar.Append(self._create_go_menu(), _('&Go')) menu_bar.Append(self._create_settings_menu(), _('&Settings')) menu_bar.Append(self._create_help_menu(), _('&Help')) self.SetMenuBar(menu_bar)
def do_open(self, path): if isinstance(path, unicode): path = path.encode(system_encoding) if self.dirty: dialog = wx.MessageDialog(self, _('Do you want to save your changes?'), '', wx.YES_NO | wx.YES_DEFAULT | wx.CANCEL | wx.ICON_QUESTION) try: rc = dialog.ShowModal() if rc == wx.ID_YES: if not self.do_save(): return False assert not self.dirty elif rc == wx.ID_NO: pass elif rc == wx.ID_CANCEL: return False finally: dialog.Destroy() self.path = path self.document = None self.page_no = 0 def clear_models(): self.metadata_model = self.text_model = self.outline_model = self.annotations_model = None self.models = () self.enable_edit(False) if path is None: clear_models() else: self.file_history.add(path) self.default_open_dir = os.path.dirname(path) try: self.document = self.context.new_document(djvu.decode.FileURI(path)) self.metadata_model = MetadataModel(self.document) self.text_model = TextModel(self.document) self.outline_model = OutlineModel(self.document) self.annotations_model = AnnotationsModel(path) self.models = self.metadata_model, self.text_model, self.outline_model, self.annotations_model self.enable_edit(True) except djvu.decode.JobFailed: clear_models() self.document = None # Do *not* display error message here. It will be displayed by `handle_message()`. self.page_no = 0 # again, to set status bar text self.update_title() self.update_page_widget(new_document=True, new_page=True) self.dirty = False return True
def __init__(self, parent, models, known_keys): wx.Dialog.__init__(self, parent, title=_('Edit metadata'), style=(wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)) sizer = wx.BoxSizer(wx.VERTICAL) tabs = wx.Notebook(self, -1) for model in models: grid = MetadataGrid(tabs, model, known_keys) tabs.AddPage(grid, model.title) sizer.Add(tabs, 1, wx.EXPAND | wx.ALL, 5) line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 5) button_sizer = wx.StdDialogButtonSizer() button = wx.Button(self, wx.ID_OK) button.SetDefault() button_sizer.AddButton(button) button = wx.Button(self, wx.ID_CANCEL) button_sizer.AddButton(button) button_sizer.Realize() sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, 5) self.SetSizerAndFit(sizer)
def __init__(self, parent, models, known_keys): wx.Dialog.__init__(self, parent, title=_('Edit metadata'), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) sizer = wx.BoxSizer(wx.VERTICAL) tabs = wx.Notebook(self, -1) for model in models: grid = MetadataGrid(tabs, model, known_keys) tabs.AddPage(grid, model.title) sizer.Add(tabs, 1, wx.EXPAND | wx.ALL, 5) line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 5) button_sizer = wx.StdDialogButtonSizer() button = wx.Button(self, wx.ID_OK) button.SetDefault() button_sizer.AddButton(button) button = wx.Button(self, wx.ID_CANCEL) button_sizer.AddButton(button) button_sizer.Realize() sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, 5) self.SetSizerAndFit(sizer)
def __init__(self, parent, node=None, origin=None): wx.Dialog.__init__(self, parent, title=_('Overprinted annotation (hyperlink) properties')) self._node = node if origin is None: self._origin = None else: self._origin = tuple(origin) if len(self._origin) != 2: raise ValueError sizer = wx.BoxSizer(wx.VERTICAL) main_properties_box_sizer = self._setup_main_properties_box() shape_box_sizer = self._setup_shape_box() border_box_sizer = self._setup_border_box() extra_sizers = self._setup_extra_boxes() for box_sizer in [main_properties_box_sizer, shape_box_sizer, border_box_sizer] + extra_sizers: sizer.Add(box_sizer, 0, wx.EXPAND | wx.ALL, 5) line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 5) button_sizer = wx.StdDialogButtonSizer() button = wx.Button(self, wx.ID_OK) button.SetDefault() button_sizer.AddButton(button) button = wx.Button(self, wx.ID_CANCEL) button_sizer.AddButton(button) button_sizer.Realize() sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Fit() self._sizer = sizer if self._node is None: i, shape = 0, SHAPE_RECTANGLE else: for i, shape in enumerate(SHAPES): if isinstance(node, shape.model_class): break else: raise TypeError self._edit_shape.SetSelection(i) self.do_select_shape(shape)
def error_box(self, message, caption=_('Error')): wx.MessageBox(message=message, caption=caption, style=(wx.OK | wx.ICON_ERROR), parent=self)
# the Free Software Foundation; version 2 dated June, 1991. # # This package is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. import wx import wx.grid import wx.lib.mixins.grid import djvu.sexpr from djvusmooth.i18n import _ LABELS = [_('key'), _('value')] class MetadataTable(wx.grid.PyGridTableBase): def __init__(self, model, known_keys): wx.grid.PyGridTableBase.__init__(self) self._model = model self._keys = sorted(model) self._keys.append(None) attr_normal = wx.grid.GridCellAttr() attr_known = wx.grid.GridCellAttr() font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) font.SetWeight(wx.FONTWEIGHT_BOLD) attr_known.SetFont(font) self._attrs = attr_normal, attr_known self._known_keys = known_keys
def on_external_edit_failed(self, exception): self.error_box( _('External edit failed:\n%s') % str(exception).decode(system_encoding, 'replace') )
def on_bookmark_current_page(self, event): uri = self.get_page_uri() node = models.outline.InnerNode(djvu.sexpr.Expression((_('(no title)'), uri)), self.outline_model) self.outline_model.root.add_child(node) node.notify_select()
# # This package is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. import wx import djvu.sexpr import djvu.const from djvusmooth.i18n import _ ZONES_MAP = \ ( (_('all'), djvu.const.TEXT_ZONE_PAGE), (_('columns'), djvu.const.TEXT_ZONE_COLUMN), (_('regions'), djvu.const.TEXT_ZONE_REGION), (_('paragraphs'), djvu.const.TEXT_ZONE_PARAGRAPH), (_('lines'), djvu.const.TEXT_ZONE_LINE), (_('words'), djvu.const.TEXT_ZONE_WORD), (_('characters'), djvu.const.TEXT_ZONE_CHARACTER) ) class FlattenTextDialog(wx.Dialog): def __init__(self, parent): wx.Dialog.__init__(self, parent, title=_('Flatten text')) sizer = wx.BoxSizer(wx.VERTICAL) self._scope_box = wx.RadioBox(self, label=_('Scope') + ':',
def __init__(self, parent): wx.FileDialog.__init__(self, parent, style=wx.FD_OPEN, wildcard=self.__wildcard, message=_('Open a DjVu document') )
def _create_view_menu(self): menu = wx.Menu() menu_item = functools.partial(self._create_menu_item, menu) submenu = wx.Menu() submenu_item = functools.partial(self._create_menu_item, submenu) for caption, help, method, id in [ (_('Zoom &in') + '\tCtrl++', _('Increase the magnification'), self.on_zoom_in, wx.ID_ZOOM_IN), (_('Zoom &out') + '\tCtrl+-', _('Decrease the magnification'), self.on_zoom_out, wx.ID_ZOOM_OUT), ]: submenu_item(caption, help, method, id=id) submenu.AppendSeparator() for caption, help, zoom, id in [ (_('Fit &width'), _('Set magnification to fit page width'), FitWidthZoom(), None), (_('Fit &page'), _('Set magnification to fit page'), FitPageZoom(), wx.ID_ZOOM_FIT), (_('&Stretch'), _('Stretch the image to the window size'), StretchZoom(), None), (_('One &to one'), _('Set full resolution magnification.'), OneToOneZoom(), wx.ID_ZOOM_100), ]: id = id or wx.ID_ANY submenu_item(caption, help, self.on_zoom(zoom), style=wx.ITEM_RADIO, id=id) submenu.AppendSeparator() self.zoom_menu_items = {} for percent in 300, 200, 150, 100, 75, 50, 25: item = submenu_item( '%d%%' % percent, _('Magnify %d%%') % percent, self.on_zoom(PercentZoom(percent)), style=wx.ITEM_RADIO ) if percent == 100: item.Check() self.zoom_menu_items[percent] = item menu.AppendMenu(wx.ID_ANY, _('&Zoom'), submenu) submenu = wx.Menu() submenu_item = functools.partial(self._create_menu_item, submenu) for caption, help, method in [ (_('&Color') + '\tAlt+C', _('Display everything'), self.on_display_everything), (_('&Stencil'), _('Display only the document bitonal stencil'), self.on_display_stencil), (_('&Foreground'), _('Display only the foreground layer'), self.on_display_foreground), (_('&Background'), _('Display only the background layer'), self.on_display_background), (_('&None') + '\tAlt+N', _('Neither display the foreground layer nor the background layer'), self.on_display_none) ]: submenu_item(caption, help, method, style=wx.ITEM_RADIO) menu.AppendMenu(wx.ID_ANY, _('&Image'), submenu) submenu = wx.Menu() submenu_item = functools.partial(self._create_menu_item, submenu) _tmp_items = [] for caption, help, method in [ (_('&None'), _('Don\'t display non-raster data'), self.on_display_no_nonraster), (_('&Hyperlinks') + '\tAlt+H', _('Display overprinted annotations'), self.on_display_maparea), (_('&Text') + '\tAlt+T', _('Display the text layer'), self.on_display_text), ]: _tmp_items += [submenu_item(caption, help, method, style=wx.ITEM_RADIO)] self.menu_item_display_no_nonraster, self.menu_item_display_maparea, self.menu_item_display_text = _tmp_items del _tmp_items self.menu_item_display_no_nonraster.Check() menu.AppendMenu(wx.ID_ANY, _('&Non-raster data'), submenu) menu_item(_('&Refresh') + '\tCtrl+L', _('Refresh the window'), self.on_refresh) return menu
def _create_edit_menu(self): menu = wx.Menu() menu_item = functools.partial(self._create_menu_item, menu) menu_item(_('&Metadata') + '\tCtrl+M', _('Edit the document or page metadata'), self.on_edit_metadata) submenu = wx.Menu() submenu_item = functools.partial(self._create_menu_item, submenu) submenu_item(_('&External editor') + '\tCtrl+T', _('Edit page text in an external editor'), self.on_external_edit_text) submenu_item(_('&Flatten'), _('Remove details from page text'), self.on_flatten_text) menu.AppendMenu(wx.ID_ANY, _('&Text'), submenu) submenu = wx.Menu() submenu_item = functools.partial(self._create_menu_item, submenu) submenu_item(_('&Bookmark this page') + '\tCtrl+B', _('Add the current to document outline'), self.on_bookmark_current_page) submenu_item(_('&External editor'), _('Edit document outline in an external editor'), self.on_external_edit_outline) submenu_item(_('&Remove all'), _('Remove whole document outline'), self.on_remove_outline) menu.AppendMenu(wx.ID_ANY, _('&Outline'), submenu) return menu
def get_label_for_node(node): zone_type = str(node.type) if node.is_inner(): return _(zone_type) else: return _(zone_type) + ': ' + replace_control_characters(' ', node.text)
def i18n(string): return _(string)
def _create_view_menu(self): menu = wx.Menu() submenu = wx.Menu() for caption, help, method, id in \ [ (_('Zoom &in'), _('Increase the magnification'), self.on_zoom_in, wx.ID_ZOOM_IN), (_('Zoom &out'), _('Decrease the magnification'), self.on_zoom_out, wx.ID_ZOOM_OUT), ]: self._add_menu_item(submenu, caption, help, method, id=id or wx.ID_ANY) submenu.AppendSeparator() for caption, help, zoom, id in \ [ (_('Fit &width'), _('Set magnification to fit page width'), FitWidthZoom(), None), (_('Fit &page'), _('Set magnification to fit page'), FitPageZoom(), wx.ID_ZOOM_FIT), (_('&Stretch'), _('Stretch the image to the window size'), StretchZoom(), None), (_('One &to one'), _('Set full resolution magnification.'), OneToOneZoom(), wx.ID_ZOOM_100), ]: item = self._add_menu_item(submenu, caption, help, self.on_zoom(zoom), kind=wx.ITEM_RADIO, id=id or wx.ID_ANY) if item.GetId() == wx.ID_ZOOM_FIT: item.Check() submenu.AppendSeparator() self.zoom_menu_items = {} for percent in 300, 200, 150, 100, 75, 50, 25: item = self._add_menu_item(submenu, '%d%%' % percent, _('Magnify %d%%') % percent, self.on_zoom(PercentZoom(percent)), kind=wx.ITEM_RADIO) self.zoom_menu_items[percent] = item menu.AppendMenu(wx.ID_ANY, _('&Zoom'), submenu) submenu = wx.Menu() for caption, help, method in \ [ (_('&Color') + '\tAlt+C', _('Display everything'), self.on_display_everything), (_('&Stencil'), _('Display only the document bitonal stencil'), self.on_display_stencil), (_('&Foreground'), _('Display only the foreground layer'), self.on_display_foreground), (_('&Background'), _('Display only the background layer'), self.on_display_background), (_('&None') + '\tAlt+N', _('Neither display the foreground layer nor the background layer'), self.on_display_none) ]: item = self._add_menu_item(submenu, caption, help, method, kind=wx.ITEM_RADIO) if caption == _('&Foreground'): item.Check() menu.AppendMenu(wx.ID_ANY, _('&Image'), submenu) """ submenu = wx.Menu() _tmp_items = [] for caption, help, method in \ [ (_('&None'), _('Don\'t display non-raster data'), self.on_display_no_nonraster), (_('&Hyperlinks') + '\tAlt+H', _('Display overprinted annotations'), self.on_display_maparea), (_('&Text') + '\tAlt+T', _('Display the text layer'), self.on_display_text), ]: _tmp_items += self._add_menu_item(submenu, caption, help, method, kind=wx.ITEM_RADIO), self._menu_item_display_no_nonraster, self._menu_item_display_maparea, self._menu_item_display_text = _tmp_items del _tmp_items self._menu_item_display_no_nonraster.Check() menu.AppendMenu(wx.ID_ANY, _('&Non-raster data'), submenu) """ self._add_menu_item(menu, _('&Refresh') + '\tCtrl+L', _('Refresh the window'), self.on_refresh) return menu
def _create_help_menu(self): menu = wx.Menu() menu_item = functools.partial(self._create_menu_item, menu) menu_item(_('&About') + '\tF1', _('More information about this program'), self.on_about, id=wx.ID_ABOUT) return menu
], 'PrevCharToLabel': [ 'Poprzedni niezaetykietowany kształt \tCtrl+W', u'Przejdź do poprzedniego niezaetykietowanego kształtu bez zatwierdzenia etykiety' ], 'NextCharCommit': [ 'Zatwierdź etykietę \tCtrl+N', u'Przejdź do następnego kształtu, zatwierdzając etykietę dla obecnego' ], 'NextCharToLabel': [ 'Następny niezaetykietowany kształt \tCtrl+Shift+E', 'Przejdź do następnego niezaetykietowanego kształtu bez zatwierdzania etykiety' ], 'NextCharToLabelCommit': [ 'Zatwierdź etykietę 2 \tCtrl+E', 'Przejdź do następnego kształtu, zatwierdzając etykietę dla obecnego' ], 'EditHierarchy': [ 'Edytuj hierarchię kształtów\tCtrl+O', 'Wyświetl okno pozwalające wybrać i usunąć kształt z aktualnej hierarchii' ], 'KeyboardShortcuts': ['&Skróty klawiaturowe\tF1', 'Lista skrótów klawiaturowych'], 'About': [_('&About'), _('More information about this program')], 'ApproveLabel': [ 'Zatwierdź etykietę\tCtrl+E', 'Zatwierdź etykietę hierarchii kształtów, zapisując ją w bazie danych' ] }
def on_save_failed(self, exception): self.error_box(_('Saving document failed:\n%s') % exception)
def notify_node_select(self, node): try: self._owner.SetStatusText(_('Link: %s') % node.uri) except AttributeError: pass