Code Style Changes

This commit is contained in:
Travis Abendshien
2024-04-27 15:59:56 -07:00
parent 276cfaf635
commit c955fb1589
3 changed files with 27 additions and 27 deletions

View File

@@ -1,33 +1,33 @@
from typing import TypedDict
class Json_Libary(TypedDict("",{"ts-version":str})):
class JsonLibary(TypedDict("",{"ts-version":str})):
#"ts-version": str
tags: "list[Json_Tag]"
collations: "list[Json_Collation]"
tags: "list[JsonTag]"
collations: "list[JsonCollation]"
fields: list #TODO
macros: "list[Json_Macro]"
entries: "list[Json_Entry]"
macros: "list[JsonMacro]"
entries: "list[JsonEntry]"
class Json_Base(TypedDict):
class JsonBase(TypedDict):
id: int
class Json_Tag(Json_Base,total=False):
class JsonTag(JsonBase,total=False):
name: str
aliases: list[str]
color: str
shorthand: str
subtag_ids: list[int]
class Json_Collation(Json_Base,total=False):
class JsonCollation(JsonBase,total=False):
title: str
e_ids_and_pages: list[list[int]]
sort_order: str
cover_id: int
class Json_Entry(Json_Base,total=False):
class JsonEntry(JsonBase,total=False):
filename: str
path: str
fields: list[dict] #TODO
class Json_Macro(Json_Base,total=False):
class JsonMacro(JsonBase,total=False):
... #TODO

View File

@@ -16,7 +16,7 @@ import xml.etree.ElementTree as ET
from enum import Enum
import ujson
from src.core.json_typing import Json_Collation, Json_Entry, Json_Libary, Json_Tag
from src.core.json_typing import JsonCollation, JsonEntry, JsonLibary, JsonTag
from src.core import ts_core
from src.core.utils.str import strip_punctuation
from src.core.utils.web import strip_web_protocol
@@ -84,12 +84,12 @@ class Entry:
and self.path == __value.path
and self.fields == __value.fields)
def compressed_dict(self) -> Json_Entry:
def compressed_dict(self) -> JsonEntry:
"""
An alternative to __dict__ that only includes fields containing
non-default data.
"""
obj: Json_Entry = {
obj: JsonEntry = {
"id": self.id
}
if self.filename:
@@ -199,12 +199,12 @@ class Tag:
else:
return (f'{self.name}')
def compressed_dict(self) -> Json_Tag:
def compressed_dict(self) -> JsonTag:
"""
An alternative to __dict__ that only includes fields containing
non-default data.
"""
obj: Json_Tag = {
obj: JsonTag = {
"id":self.id
}
if self.name:
@@ -264,12 +264,12 @@ class Collation:
and self.path == __value.path
and self.fields == __value.fields)
def compressed_dict(self) -> Json_Collation:
def compressed_dict(self) -> JsonCollation:
"""
An alternative to __dict__ that only includes fields containing
non-default data.
"""
obj: Json_Collation = {
obj: JsonCollation = {
"id":self.id
}
if self.title:
@@ -352,7 +352,7 @@ class Library:
# Map of every Tag ID to the index of the Tag in self.tags.
self._tag_id_to_index_map: dict[int, int] = {}
self.default_tags: list[Json_Tag] = [
self.default_tags: list[JsonTag] = [
{
"id": 0,
"name": "Archived",
@@ -580,12 +580,12 @@ class Library:
if not os.path.isdir(full_collage_path):
os.mkdir(full_collage_path)
def verify_default_tags(self, tag_list: list[Json_Tag]) -> list[Json_Tag]:
def verify_default_tags(self, tag_list: list[JsonTag]) -> list[JsonTag]:
"""
Ensures that the default builtin tags are present in the Library's
save file. Takes in and returns the tag dictionary from the JSON file.
"""
missing: list[Json_Tag] = []
missing: list[JsonTag] = []
for dt in self.default_tags:
if dt['id'] not in [t['id'] for t in tag_list]:
@@ -613,7 +613,7 @@ class Library:
try:
with open(os.path.normpath(f'{path}/{ts_core.TS_FOLDER_NAME}/ts_library.json'), 'r', encoding='utf-8') as f:
json_dump: Json_Libary = ujson.load(f)
json_dump: JsonLibary = ujson.load(f)
self.library_dir = str(path)
self.verify_ts_folders()
major, minor, patch = json_dump['ts-version'].split('.')
@@ -832,7 +832,7 @@ class Library:
Used in saving the library to disk.
"""
file_to_save: Json_Libary = {"ts-version": ts_core.VERSION,
file_to_save: JsonLibary = {"ts-version": ts_core.VERSION,
"ignored_extensions": [],
"tags": [],
"collations": [],
@@ -843,7 +843,7 @@ class Library:
print('[LIBRARY] Formatting Tags to JSON...')
file_to_save['ignored_extensions'] = [i for i in self.ignored_extensions if i is not '']
file_to_save['ignored_extensions'] = [i for i in self.ignored_extensions if i]
for tag in self.tags:
file_to_save["tags"].append(tag.compressed_dict())

View File

@@ -4917,15 +4917,15 @@ class FoldersToTagsModal(QWidget):
self.scroll_area.setFrameShape(QFrame.Shape.NoFrame)
self.scroll_area.setWidget(self.scroll_contents)
self.Apply_button = QPushButton()
self.Apply_button.setText('&Apply')
self.Apply_button.clicked.connect(lambda: self.folders_to_tags(self.library))
self.apply_button = QPushButton()
self.apply_button.setText('&Apply')
self.apply_button.clicked.connect(lambda: self.folders_to_tags(self.library))
self.showEvent = self.on_open
self.root_layout.addWidget(self.desc_widget)
self.root_layout.addWidget(self.scroll_area)
self.root_layout.addWidget(self.Apply_button)
self.root_layout.addWidget(self.apply_button)
def on_open(self,event):
for i in reversed(range(self.scroll_layout.count())):