Skip to content

Commit e140060

Browse files
authored
Documentation (#1)
* docs * Basic docs * Documentation, bugfix * delete reference * Defining objects * Reducing example * Parameter validation * Annotations docs * Finish writing docs
1 parent 0976a48 commit e140060

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1400
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ instance/
7070

7171
# Sphinx documentation
7272
docs/_build/
73+
docs/source/reference/
7374

7475
# PyBuilder
7576
.pybuilder/

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
graft tkclasswiz

README.rst

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
1-
=================
1+
=========================================================
22
TkClassWizard
3-
=================
3+
=========================================================
4+
TkClassWizard - define objects graphically based on class annotations.
5+
The library allows users to create abstract "ObjectInfo" objects based on the class's parameters, which
6+
can later be converted to real Python objects and vice versa.
47

5-
Library for graphically defining objects based on class annotations.
6-
Works with Tkinter / TTKBootstrap
8+
---------------------
9+
Links
10+
---------------------
11+
- `Releases <https://github.com/davidhozic/TkClassWizard/releases>`_
12+
- Need help? Contact me in my `Discord server <https://discord.gg/DEnvahb2Sw>`_.
713

14+
----------------------
15+
Installation
16+
----------------------
17+
DAF can be installed though command prompt/terminal using the bottom commands.
18+
19+
Pre-requirement: `Python (minimum v3.8) <https://www.python.org/downloads/>`_
20+
21+
22+
.. code-block:: bash
23+
24+
pip install tkclasswiz
25+
26+
----------------------
827
Example
9-
============
28+
----------------------
29+
30+
.. image:: guide/images/new_define_frame_struct_new_str.png
31+
:width: 15cm
1032

1133
.. code-block:: python
34+
:linenos:
35+
:emphasize-lines: 11-15, 31-32
1236
37+
import tkinter as tk
38+
import tkinter.ttk as ttk
1339
import tkclasswiz as wiz
1440
1541
42+
# Normal Python classes with annotations (type hints)
1643
class Wheel:
1744
def __init__(self, diameter: float):
1845
self.diameter = diameter
@@ -23,7 +50,31 @@ Example
2350
self.speed = speed
2451
self.wheels = wheels
2552
53+
# Tkinter main window
54+
root = tk.Tk("Test")
55+
56+
# Modified tkinter Combobox that will store actual objects instead of strings
57+
combo = wiz.ComboBoxObjects(root)
58+
combo.pack(fill=tk.X, padx=5)
59+
60+
def make_car(old = None):
61+
"""
62+
Function for opening a window either in new definition mode (old = None) or
63+
edit mode (old != None)
64+
"""
65+
assert old is None or isinstance(old, wiz.ObjectInfo)
66+
67+
window = wiz.ObjectEditWindow() # The object definition window / wizard
68+
window.open_object_edit_frame(Car, combo, old_data=old) # Open the actual frame
69+
70+
def print_defined():
71+
data = combo.get()
72+
data = wiz.convert_to_objects(data) # Convert any abstract ObjectInfo objects into actual Python objects
73+
print(f"Object: {data}; Type: {type(data)}",) # Print the object and it's datatype
74+
2675
27-
combo = wiz.ComboBoxObjects()
28-
window = ObjectEditWindow()
29-
window.open_object_edit_frame(Car, combo)
76+
# Main GUI structure
77+
ttk.Button(text="Define Car", command=make_car).pack()
78+
ttk.Button(text="Edit Car", command=lambda: make_car(combo.get())).pack()
79+
ttk.Button(text="Print defined", command=print_defined).pack()
80+
root.mainloop()

docs/Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR ?= source
9+
BUILDDIR ?= build
10+
USE_LANGUAGE ?= sl
11+
12+
export LANGUAGE=$(USE_LANGUAGE)
13+
14+
_BUILD_DIR = $(BUILDDIR)/$(SOURCEDIR)
15+
16+
# OS specific commands
17+
ifeq ($(OS), Windows_NT)
18+
LATEX_CMD := \
19+
cp $(CURDIR)/build-latex-win.sh $(CURDIR)/$(_BUILD_DIR)/latex/ &&\
20+
wsl --cd $(CURDIR)/$(_BUILD_DIR)/latex sh build-latex-win.sh
21+
22+
else
23+
LATEX_CMD := cd $(CURDIR)/$(_BUILD_DIR)/latex && make all-pdf
24+
endif
25+
26+
27+
# Put it first so that "make" without argument is like "make help".
28+
help:
29+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
30+
31+
.PHONY: help Makefile
32+
33+
# Catch-all target: route all unknown targets to Sphinx using the new
34+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
35+
36+
clean:
37+
python3 ./setup.py --clean --start-dir $(SOURCEDIR)
38+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(_BUILD_DIR)" $(SPHINXOPTS) $(O)
39+
40+
pdf: latex
41+
mkdir -p $(CURDIR)/$(_BUILD_DIR)/pdf/
42+
$(LATEX_CMD)
43+
cp $(CURDIR)/$(_BUILD_DIR)/latex/*.pdf $(CURDIR)/$(_BUILD_DIR)/pdf/
44+
45+
%: Makefile
46+
python3 ./setup.py --start-dir $(SOURCEDIR)
47+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(_BUILD_DIR)" $(SPHINXOPTS) $(O)

docs/build-latex-win.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Script is created to speed up the latex compilation on the windows system though wsl.
2+
# It copis all latex files to a wsl directory, runs the latex compiler and then copies them back
3+
# to the orignal path.
4+
5+
ORIGIN_DIR=$(pwd)
6+
LATEX_BUILD_PATH=~/latex-build/
7+
8+
# Copy the current folder (latex build folder) contents to our home folder
9+
echo Creating dir $LATEX_BUILD_PATH
10+
mkdir -p $LATEX_BUILD_PATH
11+
12+
echo Copying files to $LATEX_BUILD_PATH
13+
cp -r $ORIGIN_DIR/** $LATEX_BUILD_PATH
14+
15+
echo Building latex
16+
cd $LATEX_BUILD_PATH
17+
make all-pdf
18+
cp -r $LATEX_BUILD_PATH/** $ORIGIN_DIR
19+
20+
echo Cleaning up $LATEX_BUILD_PATH
21+
rm -rf $LATEX_BUILD_PATH

docs/dep_local.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"copy": [],
3+
"scripts": []
4+
}

docs/setup.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""
2+
Script that setups the environment before build.
3+
"""
4+
5+
from pathlib import Path
6+
from argparse import ArgumentParser
7+
8+
import runpy
9+
import re
10+
import os
11+
import glob
12+
import shutil
13+
import json
14+
15+
16+
parse = ArgumentParser()
17+
parse.add_argument("--clean", action="store_true", default=False, help="If given, it will only clean instead of copy and run")
18+
parse.add_argument("--start-dir", default="./", dest="start_dir", help="Where to start looking for dep_local.json")
19+
args = parse.parse_args()
20+
21+
22+
CLEAN_ARG: bool = args.clean
23+
START_DIR_ARG: str = args.start_dir
24+
25+
# Work relatively to the setup script location
26+
os.chdir(os.path.dirname(__file__))
27+
28+
for path, dirs, files in os.walk(START_DIR_ARG):
29+
for file in files:
30+
if file == "dep_local.json":
31+
file = os.path.join(path, file)
32+
# Copy files
33+
setup_file_data: dict = None
34+
with open(file, 'r', encoding="utf-8") as setup_file:
35+
setup_file_data = json.load(setup_file)
36+
37+
# While copying change to dep-files cwd
38+
cwd = os.getcwd()
39+
os.chdir(os.path.abspath(os.path.dirname(file)))
40+
# [(from, to), (from, to)]
41+
destinations = setup_file_data["copy"]
42+
for dest in destinations:
43+
cp_from = dest["from"]
44+
cp_to = dest["to"]
45+
if re.search(r"\.[A-z]+$", cp_to) is None: # The path does not have extension -> assume a dir
46+
_src = [x for x in glob.glob(cp_from, recursive=True) if os.path.isfile(x)]
47+
_dest = [os.path.join(cp_to, os.path.basename(m)) for m in _src]
48+
else:
49+
_src = [cp_from]
50+
_dest = [cp_to]
51+
52+
srcdest = zip(_src, _dest)
53+
for fromf, tof in srcdest:
54+
if CLEAN_ARG:
55+
if os.path.exists(tof):
56+
os.remove(tof)
57+
else:
58+
tof_dir = Path(os.path.dirname(tof))
59+
tof_dir.mkdir(parents=True, exist_ok=True)
60+
shutil.copy2(fromf, tof)
61+
62+
# Run scripts
63+
if CLEAN_ARG:
64+
os.chdir(cwd)
65+
continue
66+
67+
scripts = setup_file_data["scripts"]
68+
for script in scripts:
69+
runpy.run_path(script)
70+
71+
# Change cwd back to original
72+
os.chdir(cwd)

docs/source/conf.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
14+
import sys
15+
import os
16+
17+
os.environ["DOCUMENTATION"] = "True"
18+
sys.path.insert(0, os.path.abspath('../../src/'))
19+
sys.path.insert(0, os.path.abspath('.'))
20+
21+
from tkclasswiz import __version__
22+
23+
24+
# -- Project information -----------------------------------------------------
25+
project = 'TkClassWizard'
26+
copyright = '2023, David Hozic'
27+
author = 'David Hozic'
28+
version = __version__
29+
30+
31+
# -- General configuration ---------------------------------------------------
32+
root_doc = 'index'
33+
34+
numfig = True
35+
36+
# Add any Sphinx extension module names here, as strings. They can be
37+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
38+
# ones.
39+
extensions = [
40+
"sphinx.ext.autodoc",
41+
"sphinx.ext.napoleon",
42+
"sphinx.ext.autosectionlabel",
43+
"sphinx.ext.intersphinx",
44+
"sphinx_copybutton",
45+
"enum_tools.autoenum",
46+
"sphinx_design",
47+
"sphinx_search.extension",
48+
"sphinxcontrib.inkscapeconverter"
49+
]
50+
51+
52+
source_suffix = {
53+
'.rst': 'restructuredtext',
54+
'.txt': 'markdown',
55+
'.md': 'markdown',
56+
}
57+
58+
# Add any paths that contain templates here, relative to this directory.
59+
templates_path = ['_templates']
60+
61+
# List of patterns, relative to source directory, that match files and
62+
# directories to ignore when looking for source files.
63+
# This pattern also affects html_static_path and html_extra_path.
64+
exclude_patterns = []
65+
66+
67+
# Autodoc
68+
autodoc_typehints = "signature"
69+
autodoc_typehints_format = "short"
70+
71+
72+
developement_build = os.environ.get("DOC_DEVELOPMENT", default="False")
73+
developement_build = True if developement_build == "True" else False
74+
75+
autodoc_default_options = {
76+
'member-order': 'bysource',
77+
"private-members": developement_build
78+
}
79+
80+
81+
# Intersphinx
82+
intersphinx_mapping = {
83+
"Python" : ("https://docs.python.org/3/", None)
84+
}
85+
86+
# ----------- HTML ----------- #
87+
html_title = project
88+
html_theme = 'furo'
89+
html_static_path = ['_static']
90+
html_theme_options = {
91+
"navigation_with_keys": True,
92+
"top_of_page_button": "edit",
93+
"source_repository": "https://github.com/davidhozic/TkClassWizard",
94+
"source_branch": "develop",
95+
"source_directory": "docs/source",
96+
"footer_icons": [
97+
{
98+
"name": "GitHub",
99+
"url": "https://github.com/davidhozic/TkClassWizard",
100+
"html": '<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg>',
101+
"class": "",
102+
}
103+
],
104+
}
105+
106+
# ----------- Latex ----------- #
107+

docs/source/dep_local.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"copy": [
3+
],
4+
"scripts": ["./scripts/generate_autodoc.py"]
5+
}

0 commit comments

Comments
 (0)