|
1 | 1 | import threading |
2 | 2 | import time |
3 | 3 | from PySide6.QtCore import Qt, QRect, QSize, QMetaObject, QCoreApplication, Signal |
4 | | -from PySide6.QtWidgets import QWidget, QTextEdit, QPlainTextEdit, QTextEdit, QDialog, QGridLayout |
5 | | -from PySide6.QtGui import QColor, QPainter, QTextFormat, QShortcut, QIcon |
| 4 | +from PySide6.QtWidgets import QWidget, QTextEdit, QPlainTextEdit, QTextEdit, QDialog, QGridLayout, QLineEdit |
| 5 | +from PySide6.QtGui import QColor, QPainter, QTextFormat, QShortcut, QIcon, QCursor |
| 6 | + |
6 | 7 | from pygments import highlight |
7 | 8 | from pygments.lexers import Python3Lexer |
8 | 9 | from pygments.formatters import HtmlFormatter |
@@ -126,7 +127,7 @@ def codeHighlight(self): |
126 | 127 | curs.select(curs.LineUnderCursor) |
127 | 128 | curs.deleteChar() |
128 | 129 | curs.insertHtml(f'<style type="text/css">{self.css}</style>{out}'[:-2]) |
129 | | - print(f'<style type="text/css">{self.css}</style>{out}'[:-1]) |
| 130 | + # print(f'<style type="text/css">{self.css}</style>{out}'[:-1]) |
130 | 131 | curs.setPosition(oldPos) |
131 | 132 | self.setTextCursor(curs) |
132 | 133 | self.textChanged.connect(self.codeHighlight) |
@@ -229,6 +230,29 @@ def open_file(fName:str): |
229 | 230 | codeEditor.QCodeEditor.saveFile() |
230 | 231 | return f"File \"{fName}\" saved" |
231 | 232 |
|
| 233 | + |
| 234 | +def get_user_rename(default_text:str="")->str: |
| 235 | + """弹出一个小窗口, 让用户输入字符, 并返回这个字符""" |
| 236 | + redialog = QDialog() |
| 237 | + shortcut = QShortcut(redialog) |
| 238 | + shortcut.setKey(u'Return') |
| 239 | + shortcut.activated.connect(lambda: redialog.close()) |
| 240 | + shortcut2 = QShortcut(redialog) |
| 241 | + shortcut2.setKey(u'Enter') |
| 242 | + shortcut2.activated.connect(lambda: redialog.close()) |
| 243 | + gridLayout = QGridLayout(redialog) |
| 244 | + gridLayout.setSpacing(0) |
| 245 | + gridLayout.setObjectName(u"gridLayout") |
| 246 | + gridLayout.setContentsMargins(0, 0, 0, 0) |
| 247 | + redialog.setWindowFlag(Qt.FramelessWindowHint) |
| 248 | + redialog.move(QCursor.pos()) |
| 249 | + Lin = QLineEdit(redialog) |
| 250 | + Lin.setText(default_text) |
| 251 | + gridLayout.addWidget(Lin, 0, 0, 1, 1) |
| 252 | + Lin.selectAll() |
| 253 | + redialog.exec() |
| 254 | + return Lin.text() |
| 255 | + |
232 | 256 | if __name__ == '__main__': |
233 | 257 | import sys |
234 | 258 | from PySide6.QtWidgets import QApplication |
|
0 commit comments