From fe3b4ee66d331af58a3b908459cfd4df3a537eae Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Wed, 25 Oct 2023 22:39:38 +0530 Subject: [PATCH] Check update. --- config.py | 3 +++ info.json | 5 +++++ requirements.txt | 1 + window.py | 29 ++++++++++++++++++++++++----- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 info.json diff --git a/config.py b/config.py index 82df255..2c3ff49 100644 --- a/config.py +++ b/config.py @@ -11,6 +11,9 @@ default_config_file=os.path.abspath(os.path.join(os.path.dirname(os.path.realpat real_dir=os.path.dirname(os.path.realpath(sys.argv[0])) +with open(os.path.join(real_dir, "info.json")) as info_file: + info=json.loads(info_file.read()) + parser = argparse.ArgumentParser() parser.add_argument("filename", nargs="?") parser.add_argument("-c", "--config") diff --git a/info.json b/info.json new file mode 100644 index 0000000..70de0fa --- /dev/null +++ b/info.json @@ -0,0 +1,5 @@ +{ + "title": "MedScript", + "version": "0.3", + "url": "https://code.agnibho.com/medscript" +} diff --git a/requirements.txt b/requirements.txt index 951f489..07d93d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ cryptography==41.0.4 Jinja2==3.1.2 lxml==4.9.2 Markdown==3.5 +packaging==23.2 PyQt6==6.5.3 PyQt6_sip==13.6.0 python_dateutil==2.8.2 diff --git a/window.py b/window.py index 20c348d..830427c 100644 --- a/window.py +++ b/window.py @@ -5,14 +5,16 @@ # MedScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with MedScript. If not, see . -import os, sys, datetime, dateutil.parser, shutil +import os, sys, datetime, dateutil.parser, shutil, json from PyQt6.QtCore import Qt, QDateTime, QSize, pyqtSignal from PyQt6.QtWidgets import QWidget, QMainWindow, QMessageBox, QLabel, QPushButton, QLineEdit, QTextEdit, QDateTimeEdit, QListWidget, QComboBox, QCheckBox, QVBoxLayout, QHBoxLayout, QFormLayout, QToolBar, QTabWidget, QStatusBar, QFileDialog, QInputDialog, QCompleter, QSizePolicy from PyQt6.QtGui import QAction, QIcon from pathlib import Path from hashlib import md5 +from urllib import request +from packaging import version -from config import config, real_dir +from config import config, info, real_dir from prescription import Prescription from renderer import Renderer from filehandler import FileHandler @@ -198,6 +200,20 @@ class MainWindow(QMainWindow): except FileNotFoundError as e: print(e) + def cmd_update(self, silent=False): + try: + print("Current version "+info["version"]) + with request.urlopen(info["url"]+"/info.json") as response: + latest=json.loads(response.read().decode()) + print("Latest version "+latest["version"]) + if(version.parse(info["version"]) < version.parse(latest["version"])): + QMessageBox.information(self, "Check update", "New version "+latest["version"]+" available.
Visit "+latest["url"]+" to get the latest version.") + elif(not silent): + QMessageBox.information(self, "Check update", "No update available. You are using version "+info["version"]+".") + except Exception as e: + QMessageBox.critical(self, "Check update", "Failed to check available update.") + print(e) + def cmd_about(self): year=datetime.datetime.now().year if(year>2023): @@ -205,11 +221,11 @@ class MainWindow(QMainWindow): else: copy="2023" txt="

MedScript

" - txt=txt+"

Version 0.2

" + txt=txt+"

Version "+info["version"]+"

" txt=txt+"

The Prescription Writing Software

" - txt=txt+"

Website

" + txt=txt+"

Website

" txt=txt+"

Copyright © "+copy+" Dr. Agnibho Mondal

" - QMessageBox.about(self,"MedScript", txt) + QMessageBox.about(self, "MedScript", txt) def cmd_help(self): self.viewbox.md(os.path.join(real_dir, "README")) @@ -483,6 +499,8 @@ class MainWindow(QMainWindow): action_tabular.triggered.connect(self.cmd_tabular) action_index=QAction("Index", self) action_index.triggered.connect(self.cmd_index) + action_update=QAction("Update", self) + action_update.triggered.connect(self.cmd_update) action_about=QAction("About", self) action_about.triggered.connect(self.cmd_about) action_help=QAction("Help", self) @@ -511,6 +529,7 @@ class MainWindow(QMainWindow): menu_data.addAction(action_index) menu_data.addAction(action_tabular) menu_help=menubar.addMenu("Help") + menu_help.addAction(action_update) menu_help.addAction(action_about) menu_help.addAction(action_help) -- 2.39.5