Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two commits #2538

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/calibre/gui2/dialogs/template_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
QTableWidgetItem,
QTextCharFormat,
QTextOption,
QTimer,
QToolButton,
QVBoxLayout,
pyqtSignal,
Expand Down Expand Up @@ -100,32 +101,34 @@ def setup_ui(self):
b.setEnabled(False)

b = self.bb.addButton(_('Show &all functions'), QDialogButtonBox.ButtonRole.ActionRole)
b.clicked.connect(self.show_all_functions)
b.clicked.connect(self.show_all_functions_button_clicked)
b.setToolTip((_('Shows a list of all built-in functions in alphabetic order')))

def back(self):
if not self.back_stack:
info_dialog(self, _('Go back'), _('No function to go back to'), show=True)
else:
place = self.back_stack.pop()
if not self.back_stack:
self.back_button.setEnabled(False)
self.back_button.setEnabled(bool(self.back_stack))
if isinstance(place, int):
self.show_all_functions()
self.doc_viewer_widget.verticalScrollBar().setSliderPosition(place)
# For reasons known only to Qt, I can't set the scroll bar position
# until some time has passed.
QTimer.singleShot(10, lambda: self.doc_viewer_widget.verticalScrollBar().setValue(place))
else:
self.show_function(place)
self._show_function(place)

def add_to_back_stack(self):
if self.last_function is not None:
self.back_stack.append(self.last_function)
elif self.last_operation is not None:
self.back_stack.append(self.doc_viewer_widget.verticalScrollBar().value())
self.back_button.setEnabled(bool(self.back_stack))

def url_clicked(self, qurl):
if qurl.scheme().startswith('http'):
safe_open_url(qurl)
else:
if self.last_function is not None:
self.back_stack.append(self.last_function)
self.back_button.setEnabled(True)
else:
self.back_stack.append(self.doc_viewer_widget.verticalScrollBar().sliderPosition())
self.back_button.setEnabled(True)
self.show_function(qurl.path())

def english_cb_state_changed(self):
Expand All @@ -146,6 +149,11 @@ def no_doc_string(self):
return _('No documentation provided')

def show_function(self, fname):
if fname in self.builtins and fname != self.last_function:
self.add_to_back_stack()
self._show_function(fname)

def _show_function(self, fname):
self.last_operation = partial(self.show_function, fname)
bif = self.builtins[fname]
if fname not in self.builtins or not bif.doc:
Expand All @@ -155,9 +163,11 @@ def show_function(self, fname):
self.set_html(self.header_line(fname) +
self.ffml.document_to_html(self.get_doc(bif), fname))

def show_all_functions_button_clicked(self):
self.add_to_back_stack()
self.show_all_functions()

def show_all_functions(self):
self.back_button.setEnabled(False)
self.back_stack = []
self.last_function = None
self.last_operation = self.show_all_functions
result = []
Expand Down
4 changes: 2 additions & 2 deletions src/calibre/utils/formatter_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2982,8 +2982,8 @@ class BuiltinExtraFileSize(BuiltinFormatterFunction):
r'''
``extra_file_size(file_name)`` -- returns the size in bytes of the extra file
``file_name`` in the book's ``data/`` folder if it exists, otherwise ``-1``.[/] See
also the functions ``has_extra_files()``, ``extra_file_names()`` and
``extra_file_modtime()``. This function can be used only in the GUI.
also the functions :ref:`has_extra_files`, :ref:`extra_file_names` and
:ref:`extra_file_modtime`. This function can be used only in the GUI.
''')

def evaluate(self, formatter, kwargs, mi, locals, file_name):
Expand Down
Loading