示例#1
0
    def __init__(self, parent, title, size=(450, 450), style=wx.DEFAULT_DIALOG_STYLE):
        super().__init__(parent, title=title, style=style)
        bg_color = (215, 215, 215) if not IS_HIGH_CONTRAST_ACTIVE else (30, 30, 30)
        self.SetBackgroundColour(wx.Colour(bg_color))
        self.parent = parent
        self.reader = self.parent.reader
        # Zoom support
        self.scaling_factor = 0.2
        self._zoom_factor = 1.5
        # Translators: the label of the image of a page in a dialog to render the current page
        panel = self.scroll = scrolled.ScrolledPanel(self, -1, name=_("Page"), style=0)
        panel.SetTransparent(0)
        sizer = wx.BoxSizer(wx.VERTICAL)

        self.imageCtrl = ImageViewControl(panel, -1)
        sizer.Add(self.imageCtrl, 1, wx.CENTER | wx.BOTH)
        panel.SetSizer(sizer)
        sizer.Fit(panel)
        panel.Layout()
        self.setDialogImage()
        NavigationProvider(
            ctrl=panel,
            reader=self.reader,
            callback_func=self.setDialogImage,
            zoom_callback=self.set_zoom,
        )
        panel.Bind(wx.EVT_KEY_UP, self.onKeyUp, panel)
        panel.Bind(wx.EVT_CHAR_HOOK, self.onScrollChar, panel)
        panel.SetupScrolling(rate_x=self.scroll_rate_x, rate_y=self.scroll_rate_y)
        self._currently_rendered_page = self.reader.current_page
        reader_page_changed.connect(self.onPageChange, sender=self.reader)
示例#2
0
 def __init__(self):
     self.tts = SpeechProvider(self)
     self._current_textinfo = None
     reader_book_unloaded.connect(self._tts_on_unload, sender=self)
     reader_page_changed.connect(self._change_page_for_tts, sender=self)
     speech_engine_state_changed.connect(self._on_tts_state_changed,
                                         sender=self.tts)
示例#3
0
    def __init__(self, parent, title, size=(450, 450), style=wx.DEFAULT_DIALOG_STYLE):
        super().__init__(parent, title=title, style=style)
        self.parent = parent
        self.reader = self.parent.reader
        # Zoom support
        self.scaling_factor = 0.2
        self._zoom_factor = 1
        self.scroll_rate = 30
        # Translators: the label of the image of a page in a dialog to render the current page
        panel = self.scroll = scrolled.ScrolledPanel(self, -1, name=_("Page"))
        sizer = wx.BoxSizer(wx.VERTICAL)

        self.imageCtrl = wx.StaticBitmap(panel)
        sizer.Add(self.imageCtrl, 1, wx.CENTER | wx.BOTH)
        panel.SetSizer(sizer)
        sizer.Fit(panel)
        panel.Layout()
        self.setDialogImage()
        NavigationProvider(
            ctrl=panel,
            reader=self.reader,
            callback_func=self.setDialogImage,
            zoom_callback=self.set_zoom,
        )
        panel.Bind(wx.EVT_KEY_UP, self.onKeyUp, panel)
        panel.SetupScrolling(rate_x=self.scroll_rate, rate_y=self.scroll_rate)
        self._currently_rendered_page = self.reader.current_page
        reader_page_changed.connect(self.onPageChange, sender=self.reader)
示例#4
0
 def __post_init__(self):
     self.config_manager = TTSConfigManager()
     self.textCtrl = self.view.contentTextCtrl
     self.engine = None
     self._whole_page_text_info = None
     self._highlighted_ranges = set()
     restart_speech.connect(self.on_restart_speech, sender=self.view)
     reader_book_unloaded.connect(self.on_reader_unload, sender=self.reader)
     reader_page_changed.connect(self._change_page_for_tts,
                                 sender=self.reader)
     # maintain state upon book load
     self.view.add_load_handler(
         lambda s: self.on_engine_state_changed(state=SynthState.ready))
     reading_position_change.connect(self.on_reading_position_change,
                                     sender=self.view)
     self.initialize_state()
示例#5
0
 def __init__(self,
              ctrl,
              reader,
              callback_func=None,
              zoom_callback=None,
              view=None):
     self._nav_ctrl = ctrl
     self.reader = reader
     self.callback_func = callback_func
     self.zoom_callback = zoom_callback
     self.view = view
     self._key_press_record = {}
     if self.zoom_callback:
         self.zoom_keymap = {ord("0"): 0, ord("="): 1, ord("-"): -1}
     ctrl.Bind(wx.EVT_KEY_UP, self.onKeyUp, ctrl)
     if isinstance(ctrl, wx.TextCtrl):
         ctrl.Bind(EVT_CONTENT_NAVIGATION, self.onTextCtrlNavigate)
         ctrl.Bind(EVT_STRUCTURED_NAVIGATION, self.onStructuredNavigation)
     reader_page_changed.connect(self._reset_up_arrow_pressed_time,
                                 weak=False)
示例#6
0
 def __post_init__(self):
     self.view.contentTextCtrl.Bind(wx.EVT_KEY_UP, self.onKeyUp,
                                    self.view.contentTextCtrl)
     reader_book_loaded.connect(self.on_book_load, sender=self.reader)
     reader_book_unloaded.connect(self.on_book_unload, sender=self.reader)
     reader_page_changed.connect(self.comments_page_handler,
                                 sender=self.reader)
     reader_page_changed.connect(self.highlight_bookmarked_positions,
                                 sender=self.reader)
     reader_page_changed.connect(self.highlight_highlighted_text,
                                 sender=self.reader)
示例#7
0
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, name="main_window")
        self.setFrameIcon()

        self.reader = EBookReader(self)
        MenubarProvider.__init__(self)
        ToolbarProvider.__init__(self)
        StateProvider.__init__(self)
        self.CreateStatusBar()

        # Now create the Panel to put the other controls on.
        rect = wx.GetClientDisplayRect()
        panel = wx.Panel(self, size=(rect.width * 0.8, rect.height * 0.75))

        # Create the book reader controls
        # Translators: the label of the table-of-contents tree
        tocTreeLabel = wx.StaticText(panel, -1, _("Table of Contents"))
        self.tocTreeCtrl = wx.TreeCtrl(
            panel,
            size=(280, 160),
            style=wx.TR_TWIST_BUTTONS
            | wx.TR_NO_LINES
            | wx.TR_FULL_ROW_HIGHLIGHT
            | wx.TR_ROW_LINES,
            name="toc_tree",
        )
        # Translators: the label of the text area which shows the
        # content of the current page
        self.contentTextCtrlLabel = wx.StaticText(panel, -1, _("Content"))
        self.contentTextCtrl = wx.TextCtrl(
            panel,
            size=(200, 160),
            style=wx.TE_READONLY
            | wx.TE_MULTILINE
            | wx.TE_RICH2
            | wx.TE_AUTO_URL
            | wx.TE_PROCESS_ENTER
            | wx.TE_NOHIDESEL,
            name="content_view",
        )
        self.contentTextCtrl.Bind(wx.EVT_CONTEXT_MENU, lambda e: e.Skip(False),
                                  self.contentTextCtrl)
        self.contentTextCtrl.Bind(wx.EVT_RIGHT_UP,
                                  self.onContentTextCtrlContextMenu,
                                  self.contentTextCtrl)
        self.contentTextCtrl.SetMargins(self._get_text_view_margins())

        # Use a sizer to layout the controls, stacked horizontally and with
        # a 10 pixel border around each
        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        lftSizer = wx.BoxSizer(wx.VERTICAL)
        rgtSizer = wx.BoxSizer(wx.VERTICAL)
        lftSizer.Add(tocTreeLabel, 0, wx.ALL, 5)
        lftSizer.Add(self.tocTreeCtrl, 1, wx.ALL, 5)
        rgtSizer.Add(self.contentTextCtrlLabel, 0, wx.EXPAND | wx.ALL, 5)
        rgtSizer.Add(self.contentTextCtrl, 1, wx.EXPAND | wx.ALL, 5)
        mainSizer.Add(lftSizer, 0, wx.ALL | wx.EXPAND, 10)
        mainSizer.Add(rgtSizer, 1, wx.ALL | wx.EXPAND, 10)
        panel.SetSizer(mainSizer)
        panel.Layout()

        # And also use a sizer to manage the size of the panel such
        # that it fills the frame
        sizer = wx.BoxSizer()
        sizer.Add(panel, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.Fit()
        self.SetMinSize(self.GetSize())
        self.CenterOnScreen(wx.BOTH)

        # Bind Events
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onTOCItemClick,
                  self.tocTreeCtrl)

        # Set statusbar text
        # Translators: the text of the status bar when no book is currently open.
        # It is being used also as a label for the page content text area when no book is opened.
        self._no_open_book_status = _("Press (Ctrl + O) to open an ebook")
        self.SetStatusText(self._no_open_book_status)
        NavigationProvider(
            ctrl=self.contentTextCtrl,
            reader=self.reader,
            zoom_callback=self.onTextCtrlZoom,
        )
        if config.conf["general"]["play_page_note_sound"]:
            reader_page_changed.connect(play_sound_if_note, sender=self.reader)
        if config.conf["general"]["highlight_bookmarked_positions"]:
            reader_page_changed.connect(highlight_bookmarked_positions,
                                        sender=self.reader)
示例#8
0
    def __init__(self, service):
        super().__init__()
        self.service = service
        self.view = service.view
        self._ocr_cancelled = threading.Event()
        image2textId = wx.NewIdRef()

        # Add menu items
        self.Append(
            OCRMenuIds.scanCurrentPage,
            # Translators: the label of an item in the application menubar
            _("&Scan Current Page...\tF4"),
            # Translators: the help text of an item in the application menubar
            _("Run OCR on the current page"),
        )
        self.auto_scan_item = self.Append(
            OCRMenuIds.autoScanPages,
            # Translators: the label of an item in the application menubar
            _("&Automatic OCR\tCtrl-F4"),
            # Translators: the help text of an item in the application menubar
            _("Auto run  OCR when turning pages."),
            kind=wx.ITEM_CHECK,
        )
        self.Append(
            OCRMenuIds.changeOCROptions,
            # Translators: the label of an item in the application menubar
            _("&Change OCR Options..."),
            # Translators: the help text of an item in the application menubar
            _("Change OCR options"),
        )
        self.Append(
            OCRMenuIds.scanToTextFile,
            # Translators: the label of an item in the application menubar
            _("Scan To &Text File..."),
            # Translators: the help text of an item in the application menubar
            _("Scan pages and save the text to a .txt file."),
        )
        self.Append(
            image2textId,
            # Translators: the label of an item in the application menubar
            _("Image To Text..."),
            # Translators: the help text of an item in the application menubar
            _("Run OCR on an image."),
        )
        # Add the menu to the menubar
        # Translators: the label of the OCR menu in the application menubar
        # Event handlers
        self.view.Bind(wx.EVT_MENU,
                       self.onScanCurrentPage,
                       id=OCRMenuIds.scanCurrentPage)
        self.view.Bind(wx.EVT_MENU,
                       self.onAutoScanPages,
                       id=OCRMenuIds.autoScanPages)
        self.view.Bind(wx.EVT_MENU,
                       self.onScanToTextFile,
                       id=OCRMenuIds.scanToTextFile)
        self.view.Bind(wx.EVT_MENU,
                       self.onChangeOCROptions,
                       id=OCRMenuIds.changeOCROptions)
        self.view.Bind(wx.EVT_MENU, self.onScanImageFile, id=image2textId)
        self.view.add_load_handler(self._on_reader_loaded)
        reader_book_unloaded.connect(self._on_reader_unloaded,
                                     sender=self.view.reader)
        reader_page_changed.connect(self._on_reader_page_changed,
                                    sender=self.service.reader)
        if should_auto_navigate_to_next_page:
            should_auto_navigate_to_next_page.connect(
                self.on_should_auto_navigate_to_next_page, sender=self.view)