First commit
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
__pycache__
|
||||||
|
venv
|
||||||
|
form.py
|
||||||
|
*.json
|
||||||
298
form.ui
Normal file
298
form.ui
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>720</width>
|
||||||
|
<height>380</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>720</width>
|
||||||
|
<height>330</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Просмотр списка мультиков с Shikimori</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<widget class="QWidget" name="gridLayoutWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>280</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>431</width>
|
||||||
|
<height>311</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QTextEdit" name="target_title">
|
||||||
|
<property name="undoRedoEnabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="acceptRichText">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QTextEdit" name="target_title_ru">
|
||||||
|
<property name="undoRedoEnabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="acceptRichText">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="lbl_rewatches">
|
||||||
|
<property name="text">
|
||||||
|
<string>Количество
|
||||||
|
пересмотров:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="lbl_target_title_ru">
|
||||||
|
<property name="text">
|
||||||
|
<string>Название
|
||||||
|
(рус.)</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="lbl_target_title">
|
||||||
|
<property name="text">
|
||||||
|
<string>Название
|
||||||
|
(англ.)</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="lbl_status">
|
||||||
|
<property name="text">
|
||||||
|
<string>Статус</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="lbl_score">
|
||||||
|
<property name="text">
|
||||||
|
<string>Оценка</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="lbl_note">
|
||||||
|
<property name="text">
|
||||||
|
<string>Заметка:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="2">
|
||||||
|
<widget class="QTextEdit" name="note"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="2">
|
||||||
|
<widget class="QComboBox" name="status"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QSpinBox" name="score">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="2">
|
||||||
|
<widget class="QSpinBox" name="rewatches">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>5000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QListWidget" name="anime_list">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>261</width>
|
||||||
|
<height>311</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="showDropIndicator" stdset="0">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>280</x>
|
||||||
|
<y>330</y>
|
||||||
|
<width>354</width>
|
||||||
|
<height>19</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_1">
|
||||||
|
<property name="text">
|
||||||
|
<string>1</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>2</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>3</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>4</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>5</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_6">
|
||||||
|
<property name="text">
|
||||||
|
<string>6</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>7</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_8">
|
||||||
|
<property name="text">
|
||||||
|
<string>8</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_9">
|
||||||
|
<property name="text">
|
||||||
|
<string>9</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="score_10">
|
||||||
|
<property name="text">
|
||||||
|
<string>10</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menuBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>720</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuOpen">
|
||||||
|
<property name="title">
|
||||||
|
<string>Файл</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionOpen"/>
|
||||||
|
<addaction name="actionSave"/>
|
||||||
|
<addaction name="actionClose"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionExit"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuOpen"/>
|
||||||
|
</widget>
|
||||||
|
<action name="actionOpen">
|
||||||
|
<property name="text">
|
||||||
|
<string>Открыть</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSave">
|
||||||
|
<property name="text">
|
||||||
|
<string>Сохранить</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionClose">
|
||||||
|
<property name="text">
|
||||||
|
<string>Закрыть файл</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionExit">
|
||||||
|
<property name="text">
|
||||||
|
<string>Закрыть программу</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>target_title</tabstop>
|
||||||
|
<tabstop>target_title_ru</tabstop>
|
||||||
|
<tabstop>score_1</tabstop>
|
||||||
|
<tabstop>score_2</tabstop>
|
||||||
|
<tabstop>score_3</tabstop>
|
||||||
|
<tabstop>score_4</tabstop>
|
||||||
|
<tabstop>score_5</tabstop>
|
||||||
|
<tabstop>score_6</tabstop>
|
||||||
|
<tabstop>score_7</tabstop>
|
||||||
|
<tabstop>score_8</tabstop>
|
||||||
|
<tabstop>score_9</tabstop>
|
||||||
|
<tabstop>score_10</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
35
jsonIO.py
Normal file
35
jsonIO.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from json import decoder, load, dump
|
||||||
|
|
||||||
|
|
||||||
|
class JsonIO:
|
||||||
|
@staticmethod
|
||||||
|
def _read_json(filename):
|
||||||
|
with open(filename, encoding="utf-8") as f:
|
||||||
|
data = load(f)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def is_valid_json(self, filename):
|
||||||
|
"""Verifies if json file exists / is readable"""
|
||||||
|
try:
|
||||||
|
self._read_json(filename)
|
||||||
|
return True
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
except decoder.JSONDecodeError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def load_json(self, filename):
|
||||||
|
"""Loads json file"""
|
||||||
|
return self._read_json(filename)
|
||||||
|
|
||||||
|
def save_json(self, filename, data):
|
||||||
|
"""Atomically saves json file"""
|
||||||
|
with open(filename, encoding="utf-8", mode="w") as f:
|
||||||
|
dump(data, f, indent=4, separators=(",", " : "))
|
||||||
|
return self.is_valid_json(filename)
|
||||||
|
|
||||||
|
|
||||||
|
jsonIO = JsonIO()
|
||||||
12
run.py
Normal file
12
run.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from sys import argv, exit
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from window import MainWindow
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(argv)
|
||||||
|
win = MainWindow()
|
||||||
|
win.show()
|
||||||
|
exit(app.exec())
|
||||||
82
window.py
Normal file
82
window.py
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from PyQt5.QtCore import Qt
|
||||||
|
from PyQt5.QtWidgets import QMainWindow, QListWidgetItem, QFileDialog
|
||||||
|
from form import Ui_MainWindow
|
||||||
|
from jsonIO import jsonIO
|
||||||
|
|
||||||
|
|
||||||
|
statuses = {
|
||||||
|
"none": "",
|
||||||
|
"planned": "Запланировано",
|
||||||
|
"watching": "Смотрю",
|
||||||
|
"completed": "Просмотрено",
|
||||||
|
"on_hold": "Отложено",
|
||||||
|
"dropped": "Брошено"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QMainWindow.__init__(self, parent, flags=Qt.Window)
|
||||||
|
Ui_MainWindow.__init__(self)
|
||||||
|
self.ui = Ui_MainWindow()
|
||||||
|
self.ui.setupUi(self)
|
||||||
|
|
||||||
|
# self.file_list = jsonIO.load_json("JDM17_animes.json")
|
||||||
|
|
||||||
|
# for data in self.file_list:
|
||||||
|
# item = QListWidgetItem(data["target_title_ru"])
|
||||||
|
# item.setData(1, data["target_id"])
|
||||||
|
# self.ui.anime_list.addItem(item)
|
||||||
|
for key, value in statuses.items():
|
||||||
|
self.ui.status.addItem(value, key)
|
||||||
|
|
||||||
|
self.ui.anime_list.currentItemChanged.connect(self.show_info)
|
||||||
|
|
||||||
|
self.ui.actionOpen.triggered.connect(self.action_open_file)
|
||||||
|
self.ui.actionSave.triggered.connect(self.action_save_file)
|
||||||
|
self.ui.actionExit.triggered.connect(self.action_close_window)
|
||||||
|
|
||||||
|
def clear_fields(self):
|
||||||
|
self.ui.target_title.clear()
|
||||||
|
self.ui.target_title_ru.clear()
|
||||||
|
self.ui.score.setValue(0)
|
||||||
|
self.ui.status.setCurrentIndex(self.ui.status.findData("none"))
|
||||||
|
self.ui.rewatches.setValue(0)
|
||||||
|
self.ui.note.clear()
|
||||||
|
|
||||||
|
def show_info(self, item):
|
||||||
|
self.clear_fields()
|
||||||
|
target_id = item.data(1)
|
||||||
|
for data in self.file_list:
|
||||||
|
if data["target_id"] == target_id:
|
||||||
|
self.ui.target_title.setText(data["target_title"])
|
||||||
|
self.ui.target_title_ru.setText(data["target_title_ru"])
|
||||||
|
self.ui.score.setValue(data["score"])
|
||||||
|
self.ui.status.setCurrentIndex(self.ui.status.findData(data["status"]))
|
||||||
|
self.ui.rewatches.setValue(data["rewatches"])
|
||||||
|
self.ui.note.setText(data["text"])
|
||||||
|
break
|
||||||
|
|
||||||
|
def action_open_file(self):
|
||||||
|
file_path, file_name = QFileDialog.getOpenFileName(parent=self,
|
||||||
|
caption=self.tr("Выберите ваш файл со списком"),
|
||||||
|
filter=self.tr("*.json"))
|
||||||
|
if file_path == "":
|
||||||
|
return
|
||||||
|
if jsonIO.is_valid_json(file_path):
|
||||||
|
self.clear_fields()
|
||||||
|
self.file_path = file_path
|
||||||
|
self.file_list = jsonIO.load_json(file_path)
|
||||||
|
for data in self.file_list:
|
||||||
|
item = QListWidgetItem(data["target_title_ru"])
|
||||||
|
item.setData(1, data["target_id"])
|
||||||
|
self.ui.anime_list.addItem(item)
|
||||||
|
|
||||||
|
def action_save_file(self):
|
||||||
|
jsonIO.save_json(self.file_path, self.file_list)
|
||||||
|
|
||||||
|
def action_close_window(self):
|
||||||
|
self.close()
|
||||||
Reference in New Issue
Block a user