From a090233637b71422e6f9fe1b604fb1f5f1ec6a52 Mon Sep 17 00:00:00 2001 From: Rodion Sarygin Date: Fri, 4 Nov 2022 12:29:57 +0700 Subject: [PATCH] File descriptions --- client/config.py | 6 +++++- client/main.py | 27 +++++++++++++++----------- client/{ => managers}/language.py | 9 +++++++-- client/managers/plugins.py | 3 +++ client/managers/recent_files.py | 4 ++++ client/managers/settings.py | 4 ++++ client/notes/{INote.py => BaseNote.py} | 9 ++++++++- client/notes/LocalNote.py | 9 +++++++-- client/notes/RemoteNote.py | 9 +++++++-- client/plugins/BasePlugin.py | 10 ++++++---- client/text_edit_tools/BaseTool.py | 13 ++++++------- client/text_edit_tools/Tools.py | 4 ++++ client/threads/MarkdownTranslator.py | 4 ++++ client/util/debug.py | 4 ++++ client/util/decorators.py | 4 ++++ client/util/files.py | 4 ++++ client/util/markdown.py | 5 ++++- client/util/pyqt.py | 4 ++++ client/util/server.py | 4 ++++ client/widgets/InfoWidget.py | 4 ++++ client/widgets/SettingsDialog.py | 8 +++++--- client/widgets/TableDialog.py | 6 ++++-- client/widgets/TextBrowser.py | 7 +++++-- 23 files changed, 123 insertions(+), 38 deletions(-) rename client/{ => managers}/language.py (92%) rename client/notes/{INote.py => BaseNote.py} (67%) diff --git a/client/config.py b/client/config.py index 1c71917..f94157a 100644 --- a/client/config.py +++ b/client/config.py @@ -1,6 +1,10 @@ +""" +Global constants for program +""" + import os -from language import LanguageManager +from managers.language import LanguageManager ROOT_DIR_PATH = os.path.dirname(__file__) diff --git a/client/main.py b/client/main.py index 680ad12..0192346 100755 --- a/client/main.py +++ b/client/main.py @@ -1,25 +1,29 @@ -#!/bin/python3 +""" +Main class of program, UI logic. +""" +# STD Lib from functools import partial import sys +# Managers from managers.recent_files import RecentFilesManager -from widgets.InfoWidget import InfoWidget +from managers.settings import SettingsManager, SettingsNamesEnum from managers.plugins import PluginManager -from widgets.SettingsDialog import SettingsDialog - +# Widgets and ui from ui import main_ui -from util.server import generate_user_token +from widgets.InfoWidget import InfoWidget +from widgets.SettingsDialog import SettingsDialog +# Utils from util.decorators import try_function - +from util.server import generate_user_token +# Note classes from notes.LocalNote import LocalNote from notes.RemoteNote import RemoteNote - +# Config constants from config import DEFAULT_SERVER, SETTINGS_FILE_PATH, PLUGINS_DIR_PATH, MAX_RECENT_FILES_IN_DB, RECENT_FILES_DB_PATH, LANG_MANAGER - -from managers.settings import SettingsManager, SettingsNamesEnum - +# text editing tools from text_edit_tools.Tools import * - +# PyQt5 includes from PyQt5.QtWidgets import ( QMainWindow, QApplication, @@ -31,6 +35,7 @@ QMenu, ) + TOOLS = [AddImageTool, TableTool, BoldTool, ItalicTool, HeaderTool, DeleteHeaderTool] DEFAULT_SETTINGS = { diff --git a/client/language.py b/client/managers/language.py similarity index 92% rename from client/language.py rename to client/managers/language.py index 8b60c05..0573cd1 100644 --- a/client/language.py +++ b/client/managers/language.py @@ -1,7 +1,12 @@ +""" +Language manager - loads phrases for program from json file into dictionary, +and gives small api for getting values from this dict. + +""" + from json import load from util.debug import debug -from util.pyqt import alert_message_box class LanguageManager: @@ -40,7 +45,7 @@ def __init__(self, json_file_path: str) -> None: except Exception as e: print("Can not load language file " + json_file_path + ".\nRename one of files in language directory into \"default.json\" to start program.") - exit(-1) + self.lang = {} def get(self, string_id: str): res = self.lang.get(string_id, None) diff --git a/client/managers/plugins.py b/client/managers/plugins.py index 8a9f822..c1d7b5b 100644 --- a/client/managers/plugins.py +++ b/client/managers/plugins.py @@ -1,3 +1,6 @@ +"""Plugins manager - loads plugins modules from given directory +and gives all Plugin classes from this modules""" + from os import path from util.debug import debug from util.files import list_dirs_in_dir, load_module_from_file diff --git a/client/managers/recent_files.py b/client/managers/recent_files.py index 6cd3026..eda3653 100644 --- a/client/managers/recent_files.py +++ b/client/managers/recent_files.py @@ -1,3 +1,7 @@ +""" +Recent files manager - loads recent files pathes from database +and gives api for them. +""" import sqlite3 DATABASE_INITIALIZING_SCRIPT = """ diff --git a/client/managers/settings.py b/client/managers/settings.py index 4fa7d15..0266fab 100644 --- a/client/managers/settings.py +++ b/client/managers/settings.py @@ -1,3 +1,7 @@ +""" +Settings manager - loads settings from json file +and gives small api for getting variables from setting files +""" from pathlib import Path import json from util.debug import debug diff --git a/client/notes/INote.py b/client/notes/BaseNote.py similarity index 67% rename from client/notes/INote.py rename to client/notes/BaseNote.py index 10c80f0..450de7f 100644 --- a/client/notes/INote.py +++ b/client/notes/BaseNote.py @@ -1,4 +1,11 @@ -class INote: +""" +Base class for notes. +Do not have implementation for saving notes, instead throws NotImplementedError. +DO NOT USE THIS CLASS IN ANY OTHER MODULES INSTEAD OF REALIZATIONS OF THIS CLASS +""" + + +class BaseNote: """ Base class for note edits """ diff --git a/client/notes/LocalNote.py b/client/notes/LocalNote.py index 2ad7758..077f070 100644 --- a/client/notes/LocalNote.py +++ b/client/notes/LocalNote.py @@ -1,12 +1,17 @@ +""" +Realization of BaseNote class. +Gives api for saving and loading files from local computer. +""" + from pathlib import Path -from notes.INote import INote +from notes.BaseNote import BaseNote def is_file_exists(file_path: str): return Path(file_path).is_file() -class LocalNote(INote): +class LocalNote(BaseNote): def __init__(self, file_path, text: str, readonly=False) -> None: self.file_path = file_path diff --git a/client/notes/RemoteNote.py b/client/notes/RemoteNote.py index 09192dd..910af18 100644 --- a/client/notes/RemoteNote.py +++ b/client/notes/RemoteNote.py @@ -1,8 +1,13 @@ -from notes.INote import INote +""" +Realization of BaseNote class. +Gives api for loading and saving remote notes on server. +""" + +from notes.BaseNote import BaseNote from util.server import * -class RemoteNote(INote): +class RemoteNote(BaseNote): def __init__( self, user_token: str, diff --git a/client/plugins/BasePlugin.py b/client/plugins/BasePlugin.py index 8d05868..4ca2d49 100644 --- a/client/plugins/BasePlugin.py +++ b/client/plugins/BasePlugin.py @@ -1,12 +1,14 @@ +""" +BasePlugin - class that every plugin must realise. +To create your own plugin you need to create new folder (with any name) in folder ./plugins/installed/ +In this folder you need to create file plugin.py, where you will make class Plugin(BasePlugin) +""" + from PyQt5.QtWidgets import QPlainTextEdit class BasePlugin: """ - Base plugin class for fastnote plugins. - Realise this class in new file in folder plugins with class called "Plugin" - - Static attributes that you may change: NAME - NAME OF YOUR PLUGIN THAT SHOWS IN EDITOR SHORTCUT - SHORTCUT FOR FUNCTION "on_call". MAY BE NONE AUTHOR - AUTHOR CREDITS diff --git a/client/text_edit_tools/BaseTool.py b/client/text_edit_tools/BaseTool.py index e48efc3..a61adf2 100644 --- a/client/text_edit_tools/BaseTool.py +++ b/client/text_edit_tools/BaseTool.py @@ -1,7 +1,11 @@ +""" +Base class for tools on "EditTools" row in editor. +It is very similar to BasePlugin, instead this class do not have on_init() method and AUTHOR field. +""" + from PyQt5.QtWidgets import QPlainTextEdit -from PyQt5.QtGui import QTextCursor -# FOR HELP IN ADDING TOOLS: https://doc.qt.io/qt-5/richtext-cursor.html#cursor-based-editing + class BaseTool: NAME = "BaseTool" SHORTCUT = None @@ -9,8 +13,3 @@ class BaseTool: @classmethod def on_call(cls, text_edit: QPlainTextEdit, parent=None): raise NotImplementedError() - # cursor = text_edit.textCursor() - # cursor.beginEditBlock() - # cursor.movePosition(QTextCursor.MoveOperation.StartOfLine) - # cursor.insertText("[BASETOOL]") - # cursor.endEditBlock() diff --git a/client/text_edit_tools/Tools.py b/client/text_edit_tools/Tools.py index e85f9ab..b48226f 100644 --- a/client/text_edit_tools/Tools.py +++ b/client/text_edit_tools/Tools.py @@ -1,3 +1,7 @@ +""" +Basic tools for editing at row "EditTools" in editor +""" + from util.markdown import table_to_markdown from text_edit_tools.BaseTool import BaseTool from PyQt5.QtWidgets import QPlainTextEdit, QInputDialog diff --git a/client/threads/MarkdownTranslator.py b/client/threads/MarkdownTranslator.py index 57f1dc7..236868c 100644 --- a/client/threads/MarkdownTranslator.py +++ b/client/threads/MarkdownTranslator.py @@ -1,3 +1,7 @@ +""" +Thread for markdown convertion into html +""" + from PyQt5.QtCore import QThread, pyqtSignal from util.markdown import get_rendered_markdown diff --git a/client/util/debug.py b/client/util/debug.py index e406327..349f078 100644 --- a/client/util/debug.py +++ b/client/util/debug.py @@ -1,3 +1,7 @@ +""" +Debug functions +""" + DEBUG_MESSAGES = True diff --git a/client/util/decorators.py b/client/util/decorators.py index d2d5168..c3dce17 100644 --- a/client/util/decorators.py +++ b/client/util/decorators.py @@ -1,3 +1,7 @@ +""" +Decorators file +""" + from config import LANG_MANAGER from util.pyqt import alert_message_box diff --git a/client/util/files.py b/client/util/files.py index 62456f6..e62f59f 100644 --- a/client/util/files.py +++ b/client/util/files.py @@ -1,3 +1,7 @@ +""" +Utils for filesystem +""" + from importlib import util import os from types import ModuleType diff --git a/client/util/markdown.py b/client/util/markdown.py index 65292e9..253deeb 100644 --- a/client/util/markdown.py +++ b/client/util/markdown.py @@ -1,8 +1,11 @@ +""" +Utils for markdown content +""" + from jinja2 import Template from typing import List from markdown import markdown from config import ROOT_DIR_PATH -import os _FILE_RENDER_TEMPLATE = Template( open( diff --git a/client/util/pyqt.py b/client/util/pyqt.py index 3b75c5c..108aac2 100644 --- a/client/util/pyqt.py +++ b/client/util/pyqt.py @@ -1,3 +1,7 @@ +""" +Small functions based on pyqt +""" + from PyQt5.QtWidgets import QMessageBox diff --git a/client/util/server.py b/client/util/server.py index 466de57..69aca95 100644 --- a/client/util/server.py +++ b/client/util/server.py @@ -1,3 +1,7 @@ +""" +Utils for server api +""" + import requests import json from random import choices diff --git a/client/widgets/InfoWidget.py b/client/widgets/InfoWidget.py index b91095c..97e91ab 100644 --- a/client/widgets/InfoWidget.py +++ b/client/widgets/InfoWidget.py @@ -1,3 +1,7 @@ +""" +Widget with title and markdown text as body +""" + from PyQt5.QtWidgets import QWidget from ui.plugin_details_item import Ui_Form diff --git a/client/widgets/SettingsDialog.py b/client/widgets/SettingsDialog.py index c87dcc7..82c7907 100644 --- a/client/widgets/SettingsDialog.py +++ b/client/widgets/SettingsDialog.py @@ -1,8 +1,10 @@ -from PyQt5.QtWidgets import QDialog +""" +Dialog for changing dict values +""" -from ui.settings_dialog_ui import Ui_Dialog +from PyQt5.QtWidgets import QLineEdit, QDialog -from PyQt5.QtWidgets import QLineEdit +from ui.settings_dialog_ui import Ui_Dialog class SettingsDialog(QDialog, Ui_Dialog): diff --git a/client/widgets/TableDialog.py b/client/widgets/TableDialog.py index a3c8fac..6d06818 100644 --- a/client/widgets/TableDialog.py +++ b/client/widgets/TableDialog.py @@ -1,9 +1,11 @@ +""" +Dialog for table creating +""" + from PyQt5.QtWidgets import QDialog from ui.table_dialog_ui import Ui_Dialog -from PyQt5.QtWidgets import QLineEdit - class TableDialog(QDialog, Ui_Dialog): def __init__(self, on_ok_function, parent=None) -> None: diff --git a/client/widgets/TextBrowser.py b/client/widgets/TextBrowser.py index 7a6011c..ff2cfe5 100644 --- a/client/widgets/TextBrowser.py +++ b/client/widgets/TextBrowser.py @@ -1,3 +1,8 @@ +""" +TextBrowser with custom resource loading, anchors opening and +text set method +""" + from PyQt5.QtWidgets import QTextBrowser from PyQt5.QtCore import QUrl from PyQt5.QtGui import QPixmap, QDesktopServices @@ -7,8 +12,6 @@ import requests -# QTextBrowser with custom resource loading, setText method and anchors opening - class TextBrowser(QTextBrowser): def __init__(self, parent) -> None: