Skip to content

Commit

Permalink
File descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodion Sarygin committed Nov 4, 2022
1 parent 174c199 commit a090233
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 38 deletions.
6 changes: 5 additions & 1 deletion client/config.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
27 changes: 16 additions & 11 deletions client/main.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -31,6 +35,7 @@
QMenu,
)


TOOLS = [AddImageTool, TableTool, BoldTool,
ItalicTool, HeaderTool, DeleteHeaderTool]
DEFAULT_SETTINGS = {
Expand Down
9 changes: 7 additions & 2 deletions client/language.py → client/managers/language.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions client/managers/plugins.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions client/managers/recent_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Recent files manager - loads recent files pathes from database
and gives api for them.
"""
import sqlite3

DATABASE_INITIALIZING_SCRIPT = """
Expand Down
4 changes: 4 additions & 0 deletions client/managers/settings.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion client/notes/INote.py → client/notes/BaseNote.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand Down
9 changes: 7 additions & 2 deletions client/notes/LocalNote.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 7 additions & 2 deletions client/notes/RemoteNote.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
10 changes: 6 additions & 4 deletions client/plugins/BasePlugin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 6 additions & 7 deletions client/text_edit_tools/BaseTool.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"""
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

@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()
4 changes: 4 additions & 0 deletions client/text_edit_tools/Tools.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions client/threads/MarkdownTranslator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Thread for markdown convertion into html
"""

from PyQt5.QtCore import QThread, pyqtSignal

from util.markdown import get_rendered_markdown
Expand Down
4 changes: 4 additions & 0 deletions client/util/debug.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Debug functions
"""

DEBUG_MESSAGES = True


Expand Down
4 changes: 4 additions & 0 deletions client/util/decorators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Decorators file
"""

from config import LANG_MANAGER
from util.pyqt import alert_message_box

Expand Down
4 changes: 4 additions & 0 deletions client/util/files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Utils for filesystem
"""

from importlib import util
import os
from types import ModuleType
Expand Down
5 changes: 4 additions & 1 deletion client/util/markdown.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 4 additions & 0 deletions client/util/pyqt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Small functions based on pyqt
"""

from PyQt5.QtWidgets import QMessageBox


Expand Down
4 changes: 4 additions & 0 deletions client/util/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Utils for server api
"""

import requests
import json
from random import choices
Expand Down
4 changes: 4 additions & 0 deletions client/widgets/InfoWidget.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 5 additions & 3 deletions client/widgets/SettingsDialog.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
6 changes: 4 additions & 2 deletions client/widgets/TableDialog.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 5 additions & 2 deletions client/widgets/TextBrowser.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,8 +12,6 @@

import requests

# QTextBrowser with custom resource loading, setText method and anchors opening


class TextBrowser(QTextBrowser):
def __init__(self, parent) -> None:
Expand Down

0 comments on commit a090233

Please sign in to comment.