-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from Hpero4/main
实现战绩搜索历史
- Loading branch information
Showing
9 changed files
with
288 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import requests | ||
|
||
from app.common.config import cfg, VERSION | ||
|
||
|
||
class Github: | ||
def __init__(self, user="Zzaphkiel", repositories="Seraphine"): | ||
self.API = "http://api.github.com" | ||
|
||
self.user = user | ||
self.repositories = repositories | ||
self.sess = requests.session() | ||
|
||
def getReleasesInfo(self): | ||
url = f"{self.API}/repos/{self.user}/{self.repositories}/releases/latest" | ||
return self.sess.get(url, verify=False).json() | ||
|
||
def checkUpdate(self): | ||
""" | ||
检查版本更新 | ||
@return: 有更新 -> info, 无更新 -> None | ||
""" | ||
info = self.getReleasesInfo() | ||
if info.get("tag_name")[1:] != VERSION: | ||
return info | ||
return None | ||
|
||
github = Github() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from PyQt5.QtCore import Qt, QEvent, QAbstractItemModel | ||
from PyQt5.QtWidgets import QCompleter, QAction | ||
from PyQt5.uic.properties import QtCore, QtGui | ||
from qfluentwidgets import SearchLineEdit as QSearchLineEdit | ||
from qfluentwidgets.components.widgets.line_edit import CompleterMenu | ||
|
||
from app.common.config import cfg | ||
|
||
|
||
class MyCompleterMenu(CompleterMenu): | ||
|
||
def eventFilter(self, obj, e): | ||
if e.type() != QEvent.KeyPress: | ||
return super().eventFilter(obj, e) | ||
|
||
# redirect input to line edit | ||
self.lineEdit.event(e) | ||
self.view.event(e) | ||
|
||
if e.key() == Qt.Key_Escape: | ||
self.close() | ||
if e.key() in [Qt.Key_Enter, Qt.Key_Return]: | ||
self.lineEdit.searchButton.click() | ||
self.close() | ||
|
||
return True | ||
|
||
def setCompletion(self, model: QAbstractItemModel): | ||
""" set the completion model """ | ||
items = [] | ||
for i in range(model.rowCount()): | ||
for j in range(model.columnCount()): | ||
items.append(model.data(model.index(i, j))) | ||
|
||
if self.items == items and self.isVisible(): | ||
return False | ||
|
||
self.clear() | ||
self.items = items | ||
|
||
# add items | ||
for i in items: | ||
self.addAction(QAction(i, triggered=lambda c, x=i: self.__onItemSelected(x))) | ||
|
||
return True | ||
|
||
def __onItemSelected(self, text): | ||
self.lineEdit.setText(text) | ||
self.activated.emit(text) | ||
self.lineEdit.searchButton.click() | ||
|
||
|
||
class SearchLineEdit(QSearchLineEdit): | ||
def __init__(self, parent=None): | ||
super().__init__(parent) | ||
|
||
completer = QCompleter([], self) | ||
completer.setCaseSensitivity(Qt.CaseInsensitive) | ||
completer.setMaxVisibleItems(10) | ||
completer.setFilterMode(Qt.MatchFlag.MatchFixedString) | ||
completer.setCompletionRole(Qt.DisplayRole) | ||
completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion) | ||
self.setCompleter(completer) | ||
|
||
def _showCompleterMenu(self): | ||
if not self.completer(): | ||
return | ||
|
||
model = cfg.get(cfg.searchHistory) | ||
if not model: | ||
return | ||
|
||
model = model.split(",") | ||
self.completer().model().setStringList(model) | ||
|
||
# create menu | ||
if not self._completerMenu: | ||
self._completerMenu = MyCompleterMenu(self) | ||
self._completerMenu.activated.connect(self._completer.activated) | ||
|
||
# add menu items | ||
changed = self._completerMenu.setCompletion(self.completer().completionModel()) | ||
self._completerMenu.setMaxVisibleItems(self.completer().maxVisibleItems()) | ||
|
||
# show menu | ||
if changed: | ||
self._completerMenu.popup() | ||
|
||
def focusInEvent(self, e): | ||
self._showCompleterMenu() | ||
super().focusInEvent(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from PyQt5.QtWidgets import QLabel | ||
from qfluentwidgets import MessageBox, MessageBoxBase, SmoothScrollArea, SubtitleLabel, BodyLabel, TextEdit, TitleLabel, \ | ||
CheckBox | ||
|
||
from app.common.config import VERSION, cfg | ||
|
||
|
||
class UpdateMessageBox(MessageBoxBase): | ||
def __init__(self, info, parent=None): | ||
super().__init__(parent=parent) | ||
self.titleLabel = TitleLabel(self.tr('Update detected'), self) | ||
self.titleLabel.setContentsMargins(5, 0, 5, 0) | ||
self.content = BodyLabel(self.tr(f'{VERSION} -> {info.get("tag_name")[1:]}'), self) | ||
self.content.setContentsMargins(8, 0, 5, 0) | ||
|
||
textEdit = TextEdit(self) | ||
textEdit.setFixedWidth(int(self.width() * .6)) | ||
textEdit.setMarkdown(self.tr(info.get("body"))) | ||
textEdit.setReadOnly(True) | ||
|
||
checkBox = CheckBox() | ||
checkBox.setText("Don't remind me again") | ||
checkBox.clicked.connect(lambda: cfg.set(cfg.enableCheckUpdate, not checkBox.isChecked(), True)) | ||
|
||
self.viewLayout.addWidget(self.titleLabel) | ||
self.viewLayout.addWidget(self.content) | ||
self.viewLayout.addWidget(textEdit) | ||
self.viewLayout.addWidget(checkBox) | ||
|
||
self.yesButton.setText("Download") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.