Skip to content

Commit

Permalink
on mod url click opens mod view window in program about
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiacat committed Jul 20, 2022
1 parent 56e08ef commit f0a4121
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
37 changes: 27 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import QThread, QUrl, QTimer, pyqtSignal, QObject, pyqtProperty
from PyQt5.QtWebChannel import QWebChannel
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
from PyQt5.QtWidgets import QApplication, QMainWindow, QProgressBar, QTextBrowser, QLabel, QToolButton, QLineEdit, \
QComboBox, QCheckBox
from PyQt5.QtGui import QIcon, QDesktopServices, QCursor
Expand Down Expand Up @@ -153,8 +153,14 @@ def __init__(self):
self.search(self.page.value())

def open_mod(self, item):
mod = self.projects[item.row()]
info = requests.get('https://api.modrinth.com/v2/project/' + mod.project_id)
if type(item) == QtWidgets.QTableWidgetItem:
mod = self.projects[item.row()]
project_id = mod.project_id
elif type(item) == str:
project_id = item
else:
return
info = requests.get('https://api.modrinth.com/v2/project/' + project_id)
info = info.json()
dialog = QtWidgets.QDialog()
ViewDialog().setupUi(dialog)
Expand All @@ -167,18 +173,23 @@ def open_mod(self, item):
dialog.findChild(QtWidgets.QGridLayout, 'gridLayout_2').addWidget(view)
view.page().setWebChannel(channel)
view.setUrl(QUrl.fromLocalFile(os.path.join(os.path.dirname(__file__), 'web', 'index.html')))
document.set_text(info['body'])

def check_url(url: QUrl):
if url.host() == 'modrinth.com':
if url.path().split('/')[1] == 'mod':
# i dont know better way to cancel loading
view.stop()
view.back()
self.open_mod(url.path().split('/')[2])

view.page().urlChanged.connect(check_url)
document.set_text(info['body'])

button: QToolButton = dialog.findChild(QToolButton, 'menuButton')
button.clicked.connect(lambda: self.get_menu(True, item).popup(QCursor.pos()))
label: QLabel = dialog.findChild(QLabel, 'label')
label.setText(info['title'])

#browser: QTextBrowser = dialog.findChild(QTextBrowser, 'textBrowser')
# browser.anchorClicked.connect(open_link)
# browser.setMarkdown(info['body'])
# browser.setOpenLinks(False)
dialog.exec()

def open_settings(self):
Expand Down Expand Up @@ -230,8 +241,14 @@ def open_directory_dialog(self, line_edit, callback=None):
callback()

def open_mod_download(self, item):
mod = self.projects[item.row()]
info = requests.get('https://api.modrinth.com/v2/project/' + mod.project_id + '/version')
if type(item) == QtWidgets.QTableWidgetItem:
mod = self.projects[item.row()]
project_id = mod.project_id
elif type(item) == str:
project_id = item
else:
return
info = requests.get('https://api.modrinth.com/v2/project/' + project_id + '/version')
info = info.json()
dialog = QtWidgets.QDialog()
DownloadDialog().setupUi(dialog)
Expand Down
4 changes: 2 additions & 2 deletions ui/view.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>706</width>
<height>526</height>
<width>893</width>
<height>700</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
2 changes: 1 addition & 1 deletion windows/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(706, 526)
Dialog.resize(893, 700)
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
Expand Down

0 comments on commit f0a4121

Please sign in to comment.