Add update checking and documentation features
- Implement UpdateChecker for version comparison and update notifications - Add menu options for documentation and update checking - Enhance AboutWindow with dynamic version display - Update requirements.txt with new dependencies - Create infrastructure for opening local documentation - Improve application menu with additional help options
This commit is contained in:
123
ComConfigCopy.py
123
ComConfigCopy.py
@@ -17,6 +17,7 @@ import re
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import webbrowser
|
||||
from getpass import getpass
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import tkinter as tk
|
||||
@@ -40,12 +41,17 @@ from about_window import AboutWindow
|
||||
from TFTPServer import TFTPServer
|
||||
# from TFTPServer import TFTPServerThread
|
||||
import socket
|
||||
from update_checker import UpdateChecker
|
||||
|
||||
# Версия программы
|
||||
VERSION = "1.1.0"
|
||||
|
||||
# Создаем необходимые папки
|
||||
os.makedirs("Logs", exist_ok=True)
|
||||
os.makedirs("Configs", exist_ok=True)
|
||||
os.makedirs("Settings", exist_ok=True)
|
||||
os.makedirs("Firmware", exist_ok=True)
|
||||
os.makedirs("docs", exist_ok=True)
|
||||
|
||||
# Файл настроек находится в папке Settings
|
||||
SETTINGS_FILE = os.path.join("Settings", "settings.json")
|
||||
@@ -643,10 +649,22 @@ class SerialAppGUI(tk.Tk):
|
||||
super().__init__()
|
||||
self.title("ComConfigCopy")
|
||||
self.geometry("900x700")
|
||||
|
||||
# Добавляем VERSION как атрибут класса
|
||||
self.VERSION = VERSION
|
||||
|
||||
# Инициализация проверки обновлений
|
||||
self.update_checker = UpdateChecker(
|
||||
VERSION,
|
||||
"https://gitea.filow.ru/LowaSC/ComConfigCopy"
|
||||
)
|
||||
|
||||
# Настройка стиля
|
||||
self.style = ttk.Style(self)
|
||||
self.style.theme_use("clam")
|
||||
default_font = ("Segoe UI", 10)
|
||||
self.option_add("*Font", default_font)
|
||||
|
||||
self.settings = settings
|
||||
self.connection = None
|
||||
self.tftp_server = None
|
||||
@@ -656,7 +674,87 @@ class SerialAppGUI(tk.Tk):
|
||||
|
||||
# Проверка первого запуска
|
||||
self.check_first_run()
|
||||
|
||||
def create_menu(self):
|
||||
menubar = tk.Menu(self)
|
||||
self.config(menu=menubar)
|
||||
|
||||
# Меню "Файл"
|
||||
file_menu = tk.Menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="Файл", menu=file_menu)
|
||||
file_menu.add_command(label="Настройки", command=self.open_settings)
|
||||
file_menu.add_separator()
|
||||
file_menu.add_command(label="Выход", command=self.quit)
|
||||
|
||||
# Меню "Справка"
|
||||
help_menu = tk.Menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="Справка", menu=help_menu)
|
||||
help_menu.add_command(label="Документация", command=self.open_documentation)
|
||||
help_menu.add_command(label="Проверить обновления", command=self.check_for_updates)
|
||||
help_menu.add_separator()
|
||||
help_menu.add_command(label="О программе", command=self.open_about)
|
||||
|
||||
def check_for_updates(self):
|
||||
"""Проверка наличия обновлений"""
|
||||
def on_update_check(update_available, error):
|
||||
if error:
|
||||
messagebox.showerror(
|
||||
"Ошибка проверки обновлений",
|
||||
f"Не удалось проверить наличие обновлений:\n{error}"
|
||||
)
|
||||
elif update_available:
|
||||
release_info = self.update_checker.get_release_notes()
|
||||
if release_info:
|
||||
response = messagebox.askyesno(
|
||||
"Доступно обновление",
|
||||
f"Доступна новая версия {release_info['version']}!\n\n"
|
||||
f"Изменения:\n{release_info['description']}\n\n"
|
||||
"Хотите перейти на страницу загрузки?",
|
||||
)
|
||||
if response:
|
||||
webbrowser.open(release_info["download_url"])
|
||||
else:
|
||||
messagebox.showerror(
|
||||
"Ошибка",
|
||||
"Не удалось получить информацию о новой версии"
|
||||
)
|
||||
else:
|
||||
messagebox.showinfo(
|
||||
"Проверка обновлений",
|
||||
"У вас установлена последняя версия программы"
|
||||
)
|
||||
|
||||
self.update_checker.check_updates(callback=on_update_check)
|
||||
|
||||
def on_settings_changed(self):
|
||||
"""Обработчик изменения настроек"""
|
||||
self.settings = settings_load()
|
||||
|
||||
def open_settings(self):
|
||||
"""Открытие окна настроек"""
|
||||
settings_window = SettingsWindow(self, self.settings, self.on_settings_changed)
|
||||
settings_window.transient(self)
|
||||
settings_window.grab_set()
|
||||
|
||||
def open_documentation(self):
|
||||
"""Открытие документации"""
|
||||
doc_path = os.path.join("docs", "user_manual.md")
|
||||
if os.path.exists(doc_path):
|
||||
try:
|
||||
os.startfile(doc_path)
|
||||
except AttributeError:
|
||||
# Для Linux и MacOS
|
||||
try:
|
||||
import subprocess
|
||||
subprocess.run(["xdg-open", doc_path])
|
||||
except:
|
||||
webbrowser.open(f"file://{os.path.abspath(doc_path)}")
|
||||
else:
|
||||
messagebox.showerror(
|
||||
"Ошибка",
|
||||
"Файл документации не найден"
|
||||
)
|
||||
|
||||
def check_first_run(self):
|
||||
"""Проверка первого запуска программы"""
|
||||
show_settings = False
|
||||
@@ -687,31 +785,6 @@ class SerialAppGUI(tk.Tk):
|
||||
if response:
|
||||
self.open_settings()
|
||||
|
||||
def create_menu(self):
|
||||
menubar = tk.Menu(self)
|
||||
self.config(menu=menubar)
|
||||
|
||||
# Меню "Файл"
|
||||
file_menu = tk.Menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="Файл", menu=file_menu)
|
||||
file_menu.add_command(label="Настройки", command=self.open_settings)
|
||||
file_menu.add_separator()
|
||||
file_menu.add_command(label="Выход", command=self.quit)
|
||||
|
||||
# Меню "Справка"
|
||||
help_menu = tk.Menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="Справка", menu=help_menu)
|
||||
help_menu.add_command(label="О программе", command=self.open_about)
|
||||
|
||||
def open_settings(self):
|
||||
settings_window = SettingsWindow(self, self.settings, self.on_settings_changed)
|
||||
settings_window.transient(self)
|
||||
settings_window.grab_set()
|
||||
|
||||
def on_settings_changed(self):
|
||||
# Обновляем настройки в основном приложении
|
||||
self.settings = settings_load()
|
||||
|
||||
def create_tabs(self):
|
||||
self.notebook = ttk.Notebook(self)
|
||||
self.notebook.pack(fill=BOTH, expand=True, padx=5, pady=5)
|
||||
|
||||
Reference in New Issue
Block a user