Skip to content

Commit 4f6dcfd

Browse files
authored
Merge pull request #3 from davidhozic/develop
Develop
2 parents 6dee5ed + 93a41d5 commit 4f6dcfd

Some content is hidden

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

57 files changed

+3749
-0
lines changed

.github/pull_request_template.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Pull request type:
2+
- [ ] Feature
3+
- [ ] Bug fix
4+
- [ ] Documentation
5+
- [ ] Breaking change
6+
7+
I have:
8+
- [ ] Tested the code
9+
- [ ] Wrote unit tests for the code
10+
- [ ] Documented changes:
11+
- [ ] Guide(s)
12+
- [ ] API reference
13+
- [ ] Changelog
14+
15+
Changes:
16+
-
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
version-major:
5+
type: string
6+
description: Major version (eg. x.0.0)
7+
version-minor:
8+
type: string
9+
description: Minor version (eg. 0.x.0)
10+
11+
version-bugfix:
12+
type: string
13+
description: Bug fix version (eg. 0.0.x)
14+
default: "0"
15+
16+
name: Create Release
17+
18+
jobs:
19+
build:
20+
name: Create Release
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@master
25+
- name: Create tag
26+
id: tag_version
27+
uses: mathieudutour/[email protected]
28+
with:
29+
github_token: ${{ secrets.TOKEN_GH }}
30+
custom_tag : ${{github.event.inputs.version-major}}.${{github.event.inputs.version-minor}}.${{github.event.inputs.version-bugfix}}
31+
- name: Create Release
32+
id: create_release
33+
uses: actions/create-release@latest
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.TOKEN_GH }} # This token is provided by Actions, you do not need to create your own token
36+
with:
37+
tag_name: ${{ steps.tag_version.outputs.new_tag }}
38+
release_name: ${{ steps.tag_version.outputs.new_tag }}
39+
body: "Changelog: /en/v${{github.event.inputs.version-major}}.${{github.event.inputs.version-minor}}.x/changelog.html"
40+
draft: false
41+
prerelease: false
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Publish to PyPi
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
workflow_dispatch:
8+
9+
jobs:
10+
# Build job
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: "3.x"
21+
cache: 'pip'
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
python -m pip install build
27+
28+
- name: Build
29+
run: |
30+
python -m build
31+
32+
- name: Publish package
33+
uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
34+
with:
35+
user: __token__
36+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 5 additions & 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/
@@ -158,3 +159,7 @@ cython_debug/
158159
# and can be added to the global gitignore or merged into this file. For a more nuclear
159160
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160161
#.idea/
162+
163+
164+
165+
**test.py**

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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
=========================================================
2+
TkClassWizard
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.
7+
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>`_.
13+
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+
----------------------
27+
Example
28+
----------------------
29+
30+
.. image:: docs/source/guide/images/new_define_frame_struct_new_str.png
31+
:width: 15cm
32+
33+
.. code-block:: python
34+
35+
import tkinter as tk
36+
import tkinter.ttk as ttk
37+
import tkclasswiz as wiz
38+
39+
40+
# Normal Python classes with annotations (type hints)
41+
class Wheel:
42+
def __init__(self, diameter: float):
43+
self.diameter = diameter
44+
45+
class Car:
46+
def __init__(self, name: str, speed: float, wheels: list[Wheel]):
47+
self.name = name
48+
self.speed = speed
49+
self.wheels = wheels
50+
51+
# Tkinter main window
52+
root = tk.Tk("Test")
53+
54+
# Modified tkinter Combobox that will store actual objects instead of strings
55+
combo = wiz.ComboBoxObjects(root)
56+
combo.pack(fill=tk.X, padx=5)
57+
58+
def make_car(old = None):
59+
"""
60+
Function for opening a window either in new definition mode (old = None) or
61+
edit mode (old != None)
62+
"""
63+
assert old is None or isinstance(old, wiz.ObjectInfo)
64+
65+
window = wiz.ObjectEditWindow() # The object definition window / wizard
66+
window.open_object_edit_frame(Car, combo, old_data=old) # Open the actual frame
67+
68+
def print_defined():
69+
data = combo.get()
70+
data = wiz.convert_to_objects(data) # Convert any abstract ObjectInfo objects into actual Python objects
71+
print(f"Object: {data}; Type: {type(data)}",) # Print the object and it's datatype
72+
73+
74+
# Main GUI structure
75+
ttk.Button(text="Define Car", command=make_car).pack()
76+
ttk.Button(text="Edit Car", command=lambda: make_car(combo.get())).pack()
77+
ttk.Button(text="Print defined", command=print_defined).pack()
78+
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)

0 commit comments

Comments
 (0)