mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-01-05 03:30:20 -05:00
Add a send button
This commit is contained in:
parent
444a3069a8
commit
9e0a99440f
43
imgsrc/send.svg
Normal file
43
imgsrc/send.svg
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
id="Layer_1"
|
||||
data-name="Layer 1"
|
||||
viewBox="0 0 122.56 122.88"
|
||||
version="1.1"
|
||||
sodipodi:docname="send.svg"
|
||||
inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#eeeeee"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="0.17089844"
|
||||
inkscape:cx="58.514284"
|
||||
inkscape:cy="61.439999"
|
||||
inkscape:window-width="976"
|
||||
inkscape:window-height="581"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Layer_1" />
|
||||
<defs
|
||||
id="defs1">
|
||||
<style
|
||||
id="style1">.cls-1{fill-rule:evenodd;}</style>
|
||||
</defs>
|
||||
<title
|
||||
id="title1">send</title>
|
||||
<path
|
||||
class="cls-1"
|
||||
d="M2.33,44.58,117.33.37a3.63,3.63,0,0,1,5,4.56l-44,115.61h0a3.63,3.63,0,0,1-6.67.28L53.93,84.14,89.12,33.77,38.85,68.86,2.06,51.24a3.63,3.63,0,0,1,.27-6.66Z"
|
||||
id="path1"
|
||||
style="fill:#2271d5;fill-opacity:1" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
1
imgsrc/srv/send.svg
Normal file
1
imgsrc/srv/send.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.56 122.88"><defs><style>.cls-1{fill-rule:evenodd;}</style></defs><title>send</title><path class="cls-1" d="M2.33,44.58,117.33.37a3.63,3.63,0,0,1,5,4.56l-44,115.61h0a3.63,3.63,0,0,1-6.67.28L53.93,84.14,89.12,33.77,38.85,68.86,2.06,51.24a3.63,3.63,0,0,1,.27-6.66Z"/></svg>
|
||||
|
After Width: | Height: | Size: 361 B |
BIN
resources/images/send.png
Normal file
BIN
resources/images/send.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@ -5,7 +5,7 @@ from html import escape
|
||||
from math import ceil
|
||||
from typing import NamedTuple
|
||||
|
||||
from qt.core import QFrame, QPalette, Qt, QTextBrowser, QTextEdit, QUrl, QVBoxLayout, QWidget, pyqtSignal
|
||||
from qt.core import QFrame, QHBoxLayout, QIcon, QPalette, Qt, QTextBrowser, QTextEdit, QToolButton, QUrl, QVBoxLayout, QWidget, pyqtSignal
|
||||
|
||||
from calibre.utils.logging import INFO, WARN
|
||||
|
||||
@ -52,7 +52,7 @@ class Header(NamedTuple):
|
||||
return f'<div>{title}</div>'
|
||||
|
||||
|
||||
class Input(QTextEdit):
|
||||
class InputEdit(QTextEdit):
|
||||
|
||||
returnPressed = pyqtSignal()
|
||||
|
||||
@ -89,6 +89,40 @@ class Input(QTextEdit):
|
||||
return
|
||||
super().keyPressEvent(event)
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self.toPlainText()
|
||||
|
||||
@value.setter
|
||||
def value(self, val: str) -> None:
|
||||
self.setPlainText(val)
|
||||
|
||||
|
||||
class Input(QWidget):
|
||||
|
||||
send_requested = pyqtSignal()
|
||||
|
||||
def __init__(self, parent: QWidget = None, placeholder_text: str = ''):
|
||||
super().__init__(parent)
|
||||
l = QHBoxLayout(self)
|
||||
l.setContentsMargins(0, 0, 0, 0)
|
||||
self.text_input = ti = InputEdit(self, placeholder_text)
|
||||
ti.returnPressed.connect(self.send_requested)
|
||||
l.addWidget(ti)
|
||||
self.send_button = b = QToolButton(self)
|
||||
b.setIcon(QIcon.ic('send.png'))
|
||||
b.setToolTip(_('Send query to AI'))
|
||||
b.clicked.connect(self.send_requested)
|
||||
l.addWidget(b, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self.text_input.value
|
||||
|
||||
@value.setter
|
||||
def value(self, val: str) -> None:
|
||||
self.text_input.value = val
|
||||
|
||||
|
||||
class ChatWidget(QWidget):
|
||||
|
||||
@ -103,7 +137,7 @@ class ChatWidget(QWidget):
|
||||
b.anchorClicked.connect(self.link_clicked)
|
||||
l.addWidget(b)
|
||||
self.input = iw = Input(parent=self, placeholder_text=placeholder_text)
|
||||
iw.returnPressed.connect(self.on_input)
|
||||
iw.send_requested.connect(self.on_input)
|
||||
l.addWidget(iw)
|
||||
self.blocks: list[str] = []
|
||||
self.current_message = ''
|
||||
@ -166,6 +200,6 @@ class ChatWidget(QWidget):
|
||||
self.browser.setHtml('\n\n'.join(self.blocks))
|
||||
|
||||
def on_input(self) -> None:
|
||||
text = self.input.toPlainText()
|
||||
self.input.setPlainText('')
|
||||
text = self.input.value
|
||||
self.input.value = ''
|
||||
self.input_from_user.emit(text)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user