Skip to content

Commit

Permalink
更改项目结构,更正Import
Browse files Browse the repository at this point in the history
  • Loading branch information
AresConnor committed Oct 1, 2023
1 parent 118a9f7 commit d762050
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 42 deletions.
File renamed without changes.
7 changes: 3 additions & 4 deletions demo1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from PyQt5.QtWidgets import QApplication, QMainWindow, QGridLayout, QLabel, QWidget, QPushButton, QMessageBox
from pyqt5_plugins.examplebuttonplugin import QtGui

from Plugins.Mod_Plaza.Clients import CfClient
from Plugins.Mod_Plaza.curseforge import CurseForgeAPI, SchemaClasses as schemas
from Plugins.Mod_Plaza.utils.CacheDB import CacheDB
from Plugins.Mod_Plaza.utils.FetchImageManager import FetchImageManager
from Clients import CfClient
from curseforge import CurseForgeAPI, SchemaClasses as schemas
from utils.FetchImageManager import FetchImageManager


class AThread(QThread):
Expand Down
7 changes: 2 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication

from Plugins.Mod_Plaza.Clients import vacuum
from ui.plazaPage import PlazaPage
from src.ui.plazaPage import PlazaPage

if __name__ == '__main__':
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
window = PlazaPage(None)
window.setMinimumHeight(600)
window.setMinimumWidth(800)
window.show()
sys.exit(app.exec_())
sys.exit(app.exec_())
1 change: 1 addition & 0 deletions result.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Clients.py → src/Clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import requests_cache as rqc

from Plugins.Mod_Plaza.CFAPI import KEY
from Plugins.Mod_Plaza.curseforge import CurseForgeAPI, SchemaClasses as schema
from .CFAPI import KEY
from .curseforge import CurseForgeAPI, SchemaClasses as schema

curdir = os.path.abspath(os.path.dirname(__file__))
curdir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))


def vacuum():
Expand All @@ -28,11 +28,13 @@ def vacuum():
backend="sqlite",
expire_after=3600
)
# shortCachedRequest.cache.delete(expired=True)
longCachedRequest = rqc.CachedSession(
os.path.join(curdir, "cache", "CurseForgeBlob-Cache"),
backend="sqlite",
expire_after=86400 # 1day
)
# longCachedRequest.cache.delete(expired=True)
CfClient = CurseForgeAPI(KEY, shortCachedRequest, proxies={'http': '127.0.0.1:7890', 'https': '127.0.0.1:7890'})

if __name__ == '__main__':
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dataclasses import dataclass
from typing import Optional

from Plugins.Mod_Plaza.concurrent import Task, TaskManager, Future
from Plugins.Mod_Plaza.curseforge import CurseForgeAPI, SchemaClasses as schemas
from . import Task, TaskManager, Future
from ..curseforge import CurseForgeAPI, SchemaClasses as schemas


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QPixmap

from Plugins.Mod_Plaza.Clients import longCachedRequest
from Plugins.Mod_Plaza.concurrent.future import Future
from Plugins.Mod_Plaza.concurrent.task import Task
from ..Clients import longCachedRequest
from ..concurrent.future import Future
from ..concurrent.task import Task


class FetchImageTask(Task):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion concurrent/task.py → src/concurrent/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from PyQt5.QtCore import QObject, pyqtSignal, QRunnable

from Plugins.Mod_Plaza.concurrent.future import Future
from .future import Future


class Signal(QObject):
Expand Down
24 changes: 14 additions & 10 deletions concurrent/taskManager.py → src/concurrent/taskManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from typing import Dict, List

from PyQt5.QtCore import QThreadPool, QObject
from psutil import cpu_count

from Plugins.Mod_Plaza.concurrent.future import Future, FutureCancelled
from Plugins.Mod_Plaza.concurrent.task import Task
from .future import Future, FutureCancelled
from .task import Task


class TaskManager(QObject):
Expand All @@ -14,7 +15,7 @@ def __init__(self, useGlobalThreadPool=False):
self.threadPool = QThreadPool.globalInstance()
else:
self.threadPool = QThreadPool()
self.threadPool.setMaxThreadCount(4)
self.threadPool.setMaxThreadCount(2 * cpu_count()) # IO-Bound = 2*N, CPU-Bound = N + 1
self.taskMap = {}
self.tasks: Dict[int, weakref.ReferenceType] = {}
self.taskCounter = 0
Expand Down Expand Up @@ -45,14 +46,17 @@ def _taskCancel(self, fut: Future):

def _taskSingleCancel(self, fut: Future):
_id = fut.getTaskID()
task = self.tasks[_id]()
task: Task = self.tasks[_id]()
if task is not None:
try:
self.threadPool.cancel(task)
print(f"Task {_id} canceled.")
except RuntimeError:
print(f"Task {_id} already done.")

# try:
# self.threadPool.cancel(task)
# print(f"Task {_id} canceled.")
# except RuntimeError:
# print(f"Task {_id} already done.")
task.setAutoDelete(False)
if self.threadPool.tryTake(task):
del self.tasks[_id]
task.setAutoDelete(True)

def cancelTask(self, fut: Future):
self._taskCancel(fut)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/ui/__init__.py
Empty file.
File renamed without changes.
28 changes: 18 additions & 10 deletions ui/plazaPage.py → src/ui/plazaPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
TitleLabel, TransparentPushButton, BodyLabel,
)

import Plugins.Mod_Plaza.curseforge.SchemaClasses as schemas
from Plugins.Mod_Plaza.Clients import CfClient
from Plugins.Mod_Plaza.concurrent import Future
from Plugins.Mod_Plaza.concurrent.curseforgeTask import GetMinecraftInfoManager, CurseForgeSearchBody, \
from ..curseforge import SchemaClasses as schemas
from ..Clients import CfClient
from ..concurrent import Future
from ..concurrent.curseforgeTask import (
GetMinecraftInfoManager,
CurseForgeSearchBody,
MinecraftModSearchManager
from Plugins.Mod_Plaza.curseforge.Utils import getStructureCategories
from Plugins.Mod_Plaza.ui.singleModWidget import SingleModWidget
from Plugins.Mod_Plaza.utils.FetchImageManager import FetchImageManager
)
from ..curseforge.Utils import getStructureCategories
from .singleModWidget import SingleModWidget
from ..utils.FetchImageManager import FetchImageManager

CLASS_ID = schemas.MinecraftClassId.BukkitPlugin
CLASS_ID = schemas.MinecraftClassId.Mod
CLASS_NAME = CLASS_ID.name


Expand All @@ -49,6 +52,7 @@ def __init__(self, parent):
# UI
self.pageLineEdit.setAlignment(Qt.AlignCenter)


# mod repository
self.searchSrcComboBox.addItem("CurseForge")
self.sortTypeComboBox.addItem("Any")
Expand Down Expand Up @@ -87,6 +91,7 @@ def __init__(self, parent):

@pyqtSlot(object)
def getCurseForgeInfo(self, data):
self.titleLabel.setText(f"{CLASS_NAME}广场")
minecraftVersions: List[schemas.MinecraftGameVersion] = data["minecraftVersions"]
modCategories: List[schemas.Category] = getStructureCategories(data["modCategories"], 6) # Mod
pluginCategories: List[schemas.Category] = getStructureCategories(data["pluginCategories"], 5) # Plugin
Expand Down Expand Up @@ -189,7 +194,10 @@ def searchMod(self):
except TypeError: # 上次搜索无结果
pass
print("Canceled last page task.")
self.lastPageTaskFuture.deleteLater() # delete last page task
try:
self.lastPageTaskFuture.deleteLater() # delete last page task
except RuntimeError as e:
print(e)
self.thumbnailImages = 0

self.titleLabel.setText(f"{CLASS_NAME}广场 (正在搜索...)")
Expand Down Expand Up @@ -449,7 +457,7 @@ def setupUI(self):

self.gridLayout.addLayout(self.horizontalLayout_5, 5, 1, 1, 3)

self.titleLabel.setText(f"{CLASS_NAME}广场")
self.titleLabel.setText(f"{CLASS_NAME}广场 (正在加载...)")
self.sortTypeTitle.setText("排序方式 ")
self.mcVersionTitle.setText("Minecraft版本")
self.searchSrcTitle.setText("搜索源 ")
Expand Down
2 changes: 1 addition & 1 deletion ui/singleModWidget.py → src/ui/singleModWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
CardWidget,
)

from Plugins.Mod_Plaza.curseforge import SchemaClasses as schemas
from ..curseforge import SchemaClasses as schemas


class SingleModWidget(CardWidget):
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions utils/FetchImageManager.py → src/utils/FetchImageManager.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from typing import Callable, List, Tuple, Optional, Dict

from PyQt5.QtCore import QSize
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget

from Plugins.Mod_Plaza.concurrent import TaskManager, Task, Future, FetchImageTask
from ..concurrent import TaskManager, Task, Future, FetchImageTask


class FetchImageManager(TaskManager):

def __init__(self, useGlobalThreadPool=False):
super().__init__(useGlobalThreadPool)
self.threadPool.setMaxThreadCount(16)
# self.threadPool.setMaxThreadCount(16)

def asyncFetch(
self,
Expand Down
Empty file added src/utils/__init__.py
Empty file.

0 comments on commit d762050

Please sign in to comment.