mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Merge pull request #914 from hgiesel/previewineditor
Preview Button in Editor instead of Browser
This commit is contained in:
commit
5f02be4943
5 changed files with 79 additions and 40 deletions
|
@ -624,12 +624,6 @@ class Browser(QMainWindow):
|
||||||
# pylint: disable=unnecessary-lambda
|
# pylint: disable=unnecessary-lambda
|
||||||
# actions
|
# actions
|
||||||
f = self.form
|
f = self.form
|
||||||
qconnect(f.previewButton.clicked, self.onTogglePreview)
|
|
||||||
f.previewButton.setToolTip(
|
|
||||||
tr(TR.BROWSING_PREVIEW_SELECTED_CARD, val=shortcut("Ctrl+Shift+P"))
|
|
||||||
)
|
|
||||||
f.previewButton.setShortcut("Ctrl+Shift+P")
|
|
||||||
|
|
||||||
qconnect(f.filter.clicked, self.onFilterButton)
|
qconnect(f.filter.clicked, self.onFilterButton)
|
||||||
# edit
|
# edit
|
||||||
qconnect(f.actionUndo.triggered, self.mw.onUndo)
|
qconnect(f.actionUndo.triggered, self.mw.onUndo)
|
||||||
|
@ -874,7 +868,30 @@ QTableView {{ gridline-color: {grid} }}
|
||||||
self.singleCard = False
|
self.singleCard = False
|
||||||
|
|
||||||
def setupEditor(self):
|
def setupEditor(self):
|
||||||
|
def add_preview_button(leftbuttons, editor):
|
||||||
|
preview_shortcut = "Ctrl+Shift+P"
|
||||||
|
leftbuttons.insert(
|
||||||
|
0,
|
||||||
|
editor.addButton(
|
||||||
|
None,
|
||||||
|
"preview",
|
||||||
|
lambda _editor: self.onTogglePreview(),
|
||||||
|
tr(
|
||||||
|
TR.BROWSING_PREVIEW_SELECTED_CARD,
|
||||||
|
val=shortcut(preview_shortcut),
|
||||||
|
),
|
||||||
|
tr(TR.ACTIONS_PREVIEW),
|
||||||
|
id="previewButton",
|
||||||
|
keys=preview_shortcut,
|
||||||
|
disables=False,
|
||||||
|
rightside=False,
|
||||||
|
toggleable=True,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
gui_hooks.editor_did_init_left_buttons.append(add_preview_button)
|
||||||
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self)
|
self.editor = aqt.editor.Editor(self.mw, self.form.fieldsArea, self)
|
||||||
|
gui_hooks.editor_did_init_left_buttons.remove(add_preview_button)
|
||||||
|
|
||||||
def onRowChanged(self, current, previous):
|
def onRowChanged(self, current, previous):
|
||||||
"Update current note and hide/show editor."
|
"Update current note and hide/show editor."
|
||||||
|
@ -1567,7 +1584,10 @@ where id in %s"""
|
||||||
|
|
||||||
def _renderPreview(self):
|
def _renderPreview(self):
|
||||||
if self._previewer:
|
if self._previewer:
|
||||||
self._previewer.render_card()
|
if self.singleCard:
|
||||||
|
self._previewer.render_card()
|
||||||
|
else:
|
||||||
|
self.onTogglePreview()
|
||||||
|
|
||||||
def _cleanup_preview(self):
|
def _cleanup_preview(self):
|
||||||
if self._previewer:
|
if self._previewer:
|
||||||
|
@ -1575,6 +1595,8 @@ where id in %s"""
|
||||||
self._previewer.close()
|
self._previewer.close()
|
||||||
|
|
||||||
def _on_preview_closed(self):
|
def _on_preview_closed(self):
|
||||||
|
if self.editor.web:
|
||||||
|
self.editor.web.eval("$('#previewButton').removeClass('highlighted')")
|
||||||
self._previewer = None
|
self._previewer = None
|
||||||
|
|
||||||
# Card deletion
|
# Card deletion
|
||||||
|
|
|
@ -65,15 +65,33 @@ button.linkb {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
padding: 0px 2px;
|
padding: 0px 2px;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.3;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nightMode & > img {
|
||||||
|
filter: invert(180);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button.linkb:disabled {
|
button:focus {
|
||||||
opacity: 0.3;
|
outline: none;
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button.highlighted {
|
button.highlighted {
|
||||||
border-bottom: 3px solid #000;
|
.nightMode #topbutsleft & {
|
||||||
|
background: linear-gradient(0deg, #333333 0%, #434343 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
#topbutsleft & {
|
||||||
|
background-color: lightgrey;
|
||||||
|
}
|
||||||
|
|
||||||
|
#topbutsright & {
|
||||||
|
border-bottom: 3px solid #000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#fields {
|
#fields {
|
||||||
|
@ -88,12 +106,6 @@ button.highlighted {
|
||||||
color: var(--link);
|
color: var(--link);
|
||||||
}
|
}
|
||||||
|
|
||||||
.nightMode {
|
|
||||||
button.linkb > img {
|
|
||||||
filter: invert(180);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.drawing {
|
.drawing {
|
||||||
zoom: 50%;
|
zoom: 50%;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import urllib.error
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import warnings
|
import warnings
|
||||||
|
from random import randrange
|
||||||
from typing import Callable, List, Optional, Tuple
|
from typing import Callable, List, Optional, Tuple
|
||||||
|
|
||||||
import bs4
|
import bs4
|
||||||
|
@ -251,12 +252,29 @@ class Editor:
|
||||||
"""Assign func to bridge cmd, register shortcut, return button"""
|
"""Assign func to bridge cmd, register shortcut, return button"""
|
||||||
if func:
|
if func:
|
||||||
self._links[cmd] = func
|
self._links[cmd] = func
|
||||||
if keys:
|
|
||||||
QShortcut( # type: ignore
|
if keys:
|
||||||
QKeySequence(keys),
|
|
||||||
self.widget,
|
def on_activated():
|
||||||
activated=lambda s=self: func(s),
|
func(self)
|
||||||
)
|
|
||||||
|
if toggleable:
|
||||||
|
# generate a random id for triggering toggle
|
||||||
|
id = id or str(randrange(1_000_000))
|
||||||
|
|
||||||
|
def on_hotkey():
|
||||||
|
on_activated()
|
||||||
|
self.web.eval(f'toggleEditorButton("#{id}");')
|
||||||
|
|
||||||
|
else:
|
||||||
|
on_hotkey = on_activated
|
||||||
|
|
||||||
|
QShortcut( # type: ignore
|
||||||
|
QKeySequence(keys),
|
||||||
|
self.widget,
|
||||||
|
activated=on_hotkey,
|
||||||
|
)
|
||||||
|
|
||||||
btn = self._addButton(
|
btn = self._addButton(
|
||||||
icon,
|
icon,
|
||||||
cmd,
|
cmd,
|
||||||
|
|
|
@ -114,19 +114,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="3">
|
|
||||||
<widget class="QPushButton" name="previewButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>ACTIONS_PREVIEW</string>
|
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string notr="true">Ctrl+Shift+P</string>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QPushButton" name="filter">
|
<widget class="QPushButton" name="filter">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
@ -16,6 +16,7 @@ from aqt.qt import (
|
||||||
QIcon,
|
QIcon,
|
||||||
QKeySequence,
|
QKeySequence,
|
||||||
QPixmap,
|
QPixmap,
|
||||||
|
QShortcut,
|
||||||
Qt,
|
Qt,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QWidget,
|
QWidget,
|
||||||
|
@ -63,6 +64,9 @@ class Previewer(QDialog):
|
||||||
def _create_gui(self):
|
def _create_gui(self):
|
||||||
self.setWindowTitle(tr(TR.ACTIONS_PREVIEW))
|
self.setWindowTitle(tr(TR.ACTIONS_PREVIEW))
|
||||||
|
|
||||||
|
self.close_shortcut = QShortcut(QKeySequence("Ctrl+Shift+P"), self)
|
||||||
|
qconnect(self.close_shortcut.activated, self.close)
|
||||||
|
|
||||||
qconnect(self.finished, self._on_finished)
|
qconnect(self.finished, self._on_finished)
|
||||||
self.silentlyClose = True
|
self.silentlyClose = True
|
||||||
self.vbox = QVBoxLayout()
|
self.vbox = QVBoxLayout()
|
||||||
|
@ -305,10 +309,6 @@ class BrowserPreviewer(MultiCardPreviewer):
|
||||||
self._last_card_id = c.id
|
self._last_card_id = c.id
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
def _on_finished(self, ok):
|
|
||||||
super()._on_finished(ok)
|
|
||||||
self._parent.form.previewButton.setChecked(False)
|
|
||||||
|
|
||||||
def _on_prev_card(self):
|
def _on_prev_card(self):
|
||||||
self._parent.editor.saveNow(
|
self._parent.editor.saveNow(
|
||||||
lambda: self._parent._moveCur(QAbstractItemView.MoveUp)
|
lambda: self._parent._moveCur(QAbstractItemView.MoveUp)
|
||||||
|
|
Loading…
Reference in a new issue