Web search for selection
Bugfixes
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
import os
|
||||
import zipfile
|
||||
import webbrowser
|
||||
|
||||
try:
|
||||
import popplerqt5
|
||||
@@ -252,7 +253,8 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
|
||||
self.main_window.QImageFactory.get_image('visibility'),
|
||||
distraction_free_prompt)
|
||||
|
||||
viewSubMenu = contextMenu.addMenu('View')
|
||||
view_submenu_string = self._translate('PliantQGraphicsView', 'View')
|
||||
viewSubMenu = contextMenu.addMenu(view_submenu_string)
|
||||
viewSubMenu.setIcon(
|
||||
self.main_window.QImageFactory.get_image('mail-thread-watch'))
|
||||
|
||||
@@ -392,25 +394,41 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
||||
self.parent.metadata['position']['cursor_position'] = cursor_position
|
||||
|
||||
def generate_textbrowser_context_menu(self, position):
|
||||
selected_word = self.textCursor().selection()
|
||||
selected_word = selected_word.toPlainText()
|
||||
selection = self.textCursor().selection()
|
||||
selection = selection.toPlainText()
|
||||
|
||||
contextMenu = QtWidgets.QMenu()
|
||||
|
||||
# The following cannot be None because a click
|
||||
# outside the menu means that the action variable is None.
|
||||
defineAction = fsToggleAction = dfToggleAction = 'Caesar si viveret, ad remum dareris'
|
||||
searchAction = searchGoogleAction = 'TODO Insert Latin Joke'
|
||||
searchWikipediaAction = searchYoutubeAction = 'Does anyone know something funny in Latin?'
|
||||
|
||||
if selected_word and selected_word != '':
|
||||
selected_word = selected_word.split()[0]
|
||||
if selection and selection != '':
|
||||
first_selected_word = selection.split()[0]
|
||||
define_string = self._translate('PliantQTextBrowser', 'Define')
|
||||
defineAction = contextMenu.addAction(
|
||||
self.main_window.QImageFactory.get_image('view-readermode'),
|
||||
f'{define_string} "{selected_word}"')
|
||||
f'{define_string} "{first_selected_word}"')
|
||||
|
||||
searchAction = contextMenu.addAction(
|
||||
search_submenu_string = self._translate('PliantQTextBrowser', 'Search for')
|
||||
searchSubMenu = contextMenu.addMenu(search_submenu_string + f' "{selection}"')
|
||||
searchSubMenu.setIcon(self.main_window.QImageFactory.get_image('search'))
|
||||
|
||||
searchAction = searchSubMenu.addAction(
|
||||
self.main_window.QImageFactory.get_image('search'),
|
||||
self._translate('PliantQTextBrowser', 'Search'))
|
||||
self._translate('PliantQTextBrowser', 'In this book'))
|
||||
searchSubMenu.addSeparator()
|
||||
searchGoogleAction = searchSubMenu.addAction(
|
||||
QtGui.QIcon(':/images/Google.png'),
|
||||
'Google')
|
||||
searchWikipediaAction = searchSubMenu.addAction(
|
||||
QtGui.QIcon(':/images/Wikipedia.png'),
|
||||
'Wikipedia')
|
||||
searchYoutubeAction = searchSubMenu.addAction(
|
||||
QtGui.QIcon(':/images/Youtube.png'),
|
||||
'Youtube')
|
||||
|
||||
if self.parent.is_fullscreen:
|
||||
fsToggleAction = contextMenu.addAction(
|
||||
@@ -439,9 +457,19 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
|
||||
action = contextMenu.exec_(self.sender().mapToGlobal(position))
|
||||
|
||||
if action == defineAction:
|
||||
self.main_window.definitionDialog.find_definition(selected_word)
|
||||
self.main_window.definitionDialog.find_definition(selection)
|
||||
if action == searchAction:
|
||||
self.main_window.bookToolBar.searchBar.setText(selection)
|
||||
self.main_window.bookToolBar.searchBar.setFocus()
|
||||
if action == searchGoogleAction:
|
||||
webbrowser.open_new_tab(
|
||||
f'https://www.google.com/search?q={selection}')
|
||||
if action == searchWikipediaAction:
|
||||
webbrowser.open_new_tab(
|
||||
f'https://en.wikipedia.org/wiki/Special:Search?search={selection}')
|
||||
if action == searchYoutubeAction:
|
||||
webbrowser.open_new_tab(
|
||||
f'https://www.youtube.com/results?search_query={selection}')
|
||||
if action == bookmarksToggleAction:
|
||||
self.parent.toggle_bookmarks()
|
||||
if action == fsToggleAction:
|
||||
|
@@ -234,7 +234,8 @@ class Library:
|
||||
|
||||
# Sorting according to roles and the drop down in the library toolbar
|
||||
self.itemProxyModel.setSortRole(
|
||||
QtCore.Qt.UserRole + sort_roles[self.main_window.libraryToolBar.sortingBox.currentIndex()])
|
||||
QtCore.Qt.UserRole +
|
||||
sort_roles[self.main_window.libraryToolBar.sortingBox.currentIndex()])
|
||||
|
||||
# This can be expanded to other fields by appending to the list
|
||||
sort_order = QtCore.Qt.AscendingOrder
|
||||
|
8
lector/resources/raw/DarkIcons/web-browser.svg
Normal file
8
lector/resources/raw/DarkIcons/web-browser.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#5c616c; } .ColorScheme-Highlight { color:#5294e2; }
|
||||
</style>
|
||||
</defs>
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="M 8 0.99609375 C 4.134 0.99609375 1 4.1300937 1 7.9960938 C 1 11.862094 4.134 14.996094 8 14.996094 C 11.866 14.996094 15 11.862094 15 7.9960938 C 15 4.1300937 11.866 0.99609375 8 0.99609375 z M 7.5 2.9335938 C 7.5669 2.9265937 7.65125 2.9375937 7.71875 2.9335938 C 7.72675 2.9655938 7.67005 3.0794638 7.59375 3.2460938 C 7.10789 4.3074937 7.08033 5.5504437 7.53125 6.2148438 C 7.61285 6.3353038 7.6875 6.4499437 7.6875 6.4648438 C 7.6875 6.4797438 7.5995 6.4960938 7.5 6.4960938 C 7.26642 6.4960938 7.04538 6.3537238 6.59375 5.9960938 C 6.39312 5.8372237 6.1323 5.7037938 6.03125 5.6835938 C 5.87257 5.6518937 5.83028 5.6657938 5.625 5.8710938 C 5.43401 6.0620537 5.375 6.1650237 5.375 6.3398438 C 5.375 7.0027837 6.16208 7.5297437 7.625 7.8398438 C 9.6117 8.2609137 10.10145 8.6389138 10.15625 9.6835938 C 10.22505 10.993594 9.5276 11.981394 8 12.746094 C 7.81767 12.837394 7.7015 12.872844 7.625 12.902344 C 7.5911 12.899344 7.56505 12.905344 7.53125 12.902344 C 7.51825 12.861844 7.5 12.767884 7.5 12.589844 C 7.5 11.894064 7.22575 11.177844 6.8125 10.777344 C 6.70157 10.669824 6.39098 10.441994 6.125 10.277344 C 5.85903 10.112704 5.59105 9.9214438 5.53125 9.8398438 C 5.43215 9.7044337 5.42386 9.6212437 5.5 9.3710938 C 5.63876 8.9142237 5.80392 8.6597637 6.125 8.3710938 C 6.29333 8.2197537 6.46271 8.0928437 6.5 8.0898438 C 6.5373 8.0868438 6.28485 8.0110437 5.90625 7.9335938 C 5.52767 7.8559938 4.97383 7.6934738 4.6875 7.5898438 C 4.16392 7.4003938 3.457 7.0026837 3.1875 6.7148438 C 3.1761 6.7026437 3.16615 6.6943938 3.15625 6.6835938 C 3.54238 5.1454938 4.626 3.8848438 6.0625 3.2773438 C 6.36307 3.1502138 6.67292 3.0629938 7 2.9960938 C 7.16292 2.9627938 7.33178 2.9506937 7.5 2.9335938 z M 12.1875 5.2773438 C 12.30495 5.3499437 12.74841 6.3093438 12.875 6.7773438 C 13.03844 7.3815337 13.02661 8.4271437 12.875 9.0273438 C 12.8173 9.2557838 12.74335 9.4694937 12.71875 9.4960938 C 12.69415 9.5226938 12.60494 9.3695637 12.5 9.1835938 C 12.39505 8.9976538 12.05984 8.6025437 11.78125 8.3085938 C 10.97711 7.4600637 10.85066 7.0170437 11.1875 6.3398438 C 11.35737 5.9983538 12.0966 5.2212438 12.1875 5.2773438 z" transform="translate(4 4)"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.4 KiB |
BIN
lector/resources/raw/Google.png
Normal file
BIN
lector/resources/raw/Google.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
8
lector/resources/raw/LightIcons/web-browser.svg
Normal file
8
lector/resources/raw/LightIcons/web-browser.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<defs>
|
||||
<style id="current-color-scheme" type="text/css">
|
||||
.ColorScheme-Text { color:#d3dae3; } .ColorScheme-Highlight { color:#5294e2; }
|
||||
</style>
|
||||
</defs>
|
||||
<path style="fill:currentColor" class="ColorScheme-Text" d="M 8 0.99609375 C 4.134 0.99609375 1 4.1300937 1 7.9960938 C 1 11.862094 4.134 14.996094 8 14.996094 C 11.866 14.996094 15 11.862094 15 7.9960938 C 15 4.1300937 11.866 0.99609375 8 0.99609375 z M 7.5 2.9335938 C 7.5669 2.9265937 7.65125 2.9375937 7.71875 2.9335938 C 7.72675 2.9655938 7.67005 3.0794638 7.59375 3.2460938 C 7.10789 4.3074937 7.08033 5.5504437 7.53125 6.2148438 C 7.61285 6.3353038 7.6875 6.4499437 7.6875 6.4648438 C 7.6875 6.4797438 7.5995 6.4960938 7.5 6.4960938 C 7.26642 6.4960938 7.04538 6.3537238 6.59375 5.9960938 C 6.39312 5.8372237 6.1323 5.7037938 6.03125 5.6835938 C 5.87257 5.6518937 5.83028 5.6657938 5.625 5.8710938 C 5.43401 6.0620537 5.375 6.1650237 5.375 6.3398438 C 5.375 7.0027837 6.16208 7.5297437 7.625 7.8398438 C 9.6117 8.2609137 10.10145 8.6389138 10.15625 9.6835938 C 10.22505 10.993594 9.5276 11.981394 8 12.746094 C 7.81767 12.837394 7.7015 12.872844 7.625 12.902344 C 7.5911 12.899344 7.56505 12.905344 7.53125 12.902344 C 7.51825 12.861844 7.5 12.767884 7.5 12.589844 C 7.5 11.894064 7.22575 11.177844 6.8125 10.777344 C 6.70157 10.669824 6.39098 10.441994 6.125 10.277344 C 5.85903 10.112704 5.59105 9.9214438 5.53125 9.8398438 C 5.43215 9.7044337 5.42386 9.6212437 5.5 9.3710938 C 5.63876 8.9142237 5.80392 8.6597637 6.125 8.3710938 C 6.29333 8.2197537 6.46271 8.0928437 6.5 8.0898438 C 6.5373 8.0868438 6.28485 8.0110437 5.90625 7.9335938 C 5.52767 7.8559938 4.97383 7.6934738 4.6875 7.5898438 C 4.16392 7.4003938 3.457 7.0026837 3.1875 6.7148438 C 3.1761 6.7026437 3.16615 6.6943938 3.15625 6.6835938 C 3.54238 5.1454938 4.626 3.8848438 6.0625 3.2773438 C 6.36307 3.1502138 6.67292 3.0629938 7 2.9960938 C 7.16292 2.9627938 7.33178 2.9506937 7.5 2.9335938 z M 12.1875 5.2773438 C 12.30495 5.3499437 12.74841 6.3093438 12.875 6.7773438 C 13.03844 7.3815337 13.02661 8.4271437 12.875 9.0273438 C 12.8173 9.2557838 12.74335 9.4694937 12.71875 9.4960938 C 12.69415 9.5226938 12.60494 9.3695637 12.5 9.1835938 C 12.39505 8.9976538 12.05984 8.6025437 11.78125 8.3085938 C 10.97711 7.4600637 10.85066 7.0170437 11.1875 6.3398438 C 11.35737 5.9983538 12.0966 5.2212438 12.1875 5.2773438 z" transform="translate(4 4)"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.4 KiB |
BIN
lector/resources/raw/Wikipedia.png
Normal file
BIN
lector/resources/raw/Wikipedia.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
lector/resources/raw/Youtube.png
Normal file
BIN
lector/resources/raw/Youtube.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
@@ -1,5 +1,10 @@
|
||||
<RCC>
|
||||
<qresource prefix="images">
|
||||
<file>Google.png</file>
|
||||
<file>Wikipedia.png</file>
|
||||
<file>Youtube.png</file>
|
||||
<file>DarkIcons/web-browser.svg</file>
|
||||
<file>LightIcons/web-browser.svg</file>
|
||||
<file>DarkIcons/arrow-down.svg</file>
|
||||
<file>DarkIcons/arrow-up.svg</file>
|
||||
<file>LightIcons/arrow-down.svg</file>
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -520,9 +520,16 @@ class PliantDockWidget(QtWidgets.QDockWidget):
|
||||
self.main_window.bookToolBar.bookmarkButton.setChecked(True)
|
||||
self.main_window.active_bookmark_docks.append(self)
|
||||
|
||||
def hideEvent(self, event):
|
||||
def hideEvent(self, event=None):
|
||||
self.main_window.bookToolBar.bookmarkButton.setChecked(False)
|
||||
try:
|
||||
self.main_window.active_bookmark_docks.remove(self)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def closeEvent(self, event):
|
||||
self.hide()
|
||||
event.ignore()
|
||||
|
||||
|
||||
class PliantQGraphicsScene(QtWidgets.QGraphicsScene):
|
||||
|
Reference in New Issue
Block a user