Skip to content

Commit

Permalink
Merge pull request #5 from ken-morel/dev
Browse files Browse the repository at this point in the history
Improved Templating and Writeable Engines
  • Loading branch information
ken-morel authored Sep 21, 2024
2 parents 9140ee0 + 7f6f1b9 commit 813613c
Show file tree
Hide file tree
Showing 92 changed files with 10,931 additions and 28,731 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ venv/
ENV/
env.bak/
venv.bak/
Scripts/

# Spyder project settings
.spyderproject
Expand Down Expand Up @@ -160,3 +161,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

taktk.sublime-project
109 changes: 0 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +0,0 @@
# taktk

taktk from from the [bulu](https://wikipedia.com/wiki/bulu) word
_tak_, meaning to order, and _tk_ for `tkinter`.

taktk aims to give you a more orderly, easy and responsive way to build tkinter
pages.
It is currently in build(since last 2 days), but I will expose on what it can
do now.

## hello world example

Here the example in [examples/simple.py](examples/simple.py)

```python
from tkinter import Tk
from taktk.component import Component


class Comp(Component):
"""\
\\frame
\\frame pos:grid=0,0 padding=5
\\label text={label_text} pos:grid=0,0
\\button text='close >' command={close} pos:grid=1,0
\\frame pos:grid=0,1 padding=5 relief='sunken'
\\label text={{number}} pos:grid=0,0
\\ctk.button text='add +' command={add} pos:grid=1,0"""
code = __doc__

label_text = 'close the window'
number = 0

def close(self):
root.destroy()
print("closed")

def add(self):
self['number'] += 1
self.update()


root = Tk()

component = Comp()
component.render(root).grid(column=0, row=0)

root.mainloop()
```

![demo](images/example-simple.png)

> [!WARNING]
> The component building language is still in development and may be extremely
> strict

## Example 2: A todo list

```python
r"""
\frame
\ctk.frame pos:grid=0,0 width=350 pos:sticky='nsew'
\ctk.entry width=300 pos:grid=0,0 text={{entry}} pos:xweight=2
\button text='+' command={add_todo} pos:grid=1,0 pos:xweight=0
\ctk.frame pos:grid=0,1 width=350 pos:sticky='nsew'
!enum todos:(i, todo)
\ctk.label text={str(i + 1) + ') ' + todo } pos:grid={(0, i)} pos:sticky='nsw' bind:1={popper(i)}
# popper closure does popping for you
"""
from tkinter import Tk
from taktk.component import Component


class Todo(Component):
code = __doc__

todos = []
entry = "Enter todo here"

def close(self):
root.destroy()

def add_todo(self):
self.todos.append(self['entry'])
self.entry = ""
self.update()

def clear(self):
self.todos.clear()
self.update()

def popper(self, idx):
def func(e):
self.todos.pop(idx)
self.update()
return func


root = Tk()
root.title('Todo list')

editor = Todo()
editor.render(root).grid(column=0, row=0)

root.mainloop()
```

![demo](images/example-todo.png)
410 changes: 156 additions & 254 deletions Scripts/Activate.ps1

Large diffs are not rendered by default.

36 changes: 15 additions & 21 deletions Scripts/activate
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file must be used with "source bin/activate" *from bash*
# You cannot run it directly
# you cannot run it directly

deactivate () {
# reset old environment variables
Expand All @@ -14,9 +14,12 @@ deactivate () {
unset _OLD_VIRTUAL_PYTHONHOME
fi

# Call hash to forget past commands. Without forgetting
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
hash -r 2> /dev/null
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi

if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
Expand All @@ -35,27 +38,13 @@ deactivate () {
# unset irrelevant variables
deactivate nondestructive

# on Windows, a path can contain colons and backslashes and has to be converted:
case "$(uname)" in
CYGWIN*|MSYS*)
# transform D:\path\to\venv to /d/path/to/venv on MSYS
# and to /cygdrive/d/path/to/venv on Cygwin
VIRTUAL_ENV=$(cygpath "C:\taktk")
export VIRTUAL_ENV
;;
*)
# use the path as-is
export VIRTUAL_ENV="C:\taktk"
;;
esac
VIRTUAL_ENV="D:\taktk"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/Scripts:$PATH"
export PATH

VIRTUAL_ENV_PROMPT="taktk"
export VIRTUAL_ENV_PROMPT

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
Expand All @@ -68,8 +57,13 @@ if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1="(taktk) ${PS1:-}"
export PS1
VIRTUAL_ENV_PROMPT="(taktk) "
export VIRTUAL_ENV_PROMPT
fi

# Call hash to forget past commands. Without forgetting
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
hash -r 2> /dev/null
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
8 changes: 4 additions & 4 deletions Scripts/activate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" 65001 > nul
)

set VIRTUAL_ENV=C:\taktk
set VIRTUAL_ENV=D:\taktk

if not defined PROMPT set PROMPT=$P$G

if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%

set "_OLD_VIRTUAL_PROMPT=%PROMPT%"
set "PROMPT=(taktk) %PROMPT%"
set _OLD_VIRTUAL_PROMPT=%PROMPT%
set PROMPT=(taktk) %PROMPT%

if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=
Expand All @@ -25,7 +25,7 @@ if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH%

set PATH=%VIRTUAL_ENV%\Scripts;%PATH%
set VIRTUAL_ENV_PROMPT=taktk
set VIRTUAL_ENV_PROMPT=(taktk)

:END
if defined _OLD_CODEPAGE (
Expand Down
69 changes: 0 additions & 69 deletions Scripts/activate.fish

This file was deleted.

Binary file removed Scripts/pip.exe
Binary file not shown.
Binary file removed Scripts/pip3.13.exe
Binary file not shown.
Binary file removed Scripts/pip3.exe
Binary file not shown.
Binary file modified Scripts/python.exe
Binary file not shown.
Binary file removed Scripts/python3.13t.exe
Binary file not shown.
Binary file modified Scripts/pythonw.exe
Binary file not shown.
Binary file removed Scripts/pythonw3.13t.exe
Binary file not shown.
63 changes: 63 additions & 0 deletions examples/acrylic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from contextlib import contextmanager
from tkinter import *
from tkinter.ttk import *

import win32con
import win32gui
from PIL import Image, ImageFilter, ImageGrab, ImageTk
from ttkbootstrap import Window


def capture_screen_excluding_window(window):
"""Capture the entire screen, excluding the given window"""
hwnd = window.winfo_id()
x0, y0, x1, y1 = (
window.winfo_rootx(),
window.winfo_rooty(),
window.winfo_rootx() + window.winfo_width(),
window.winfo_rooty() + window.winfo_height(),
)
screen_width, screen_height = (
window.winfo_screenwidth(),
window.winfo_screenheight(),
)
with transparent(window):
img = ImageGrab.grab(bbox=(x0, y0, x1, y1))
img_blurred = img.filter(ImageFilter.GaussianBlur(radius=10))
img_tk = ImageTk.PhotoImage(img_blurred)
return img_tk


@contextmanager
def transparent(win, alpha=0.3):
win.attributes("-alpha", alpha)
yield
win.attributes("-alpha", 1)


root = Window(themename="superhero")
root.attributes("-transparentcolor", "#555")
root.geometry("500x300")

root.style.configure(
"Transparent.TFrame",
bg="#555",
)
frm = Frame(root, style="Transparent.TFrame", bootstyle=None)
label = Label(frm)
label.pack(fill="both", expand=True)
frm.pack(fill="both", expand=True)


def capture_and_display():
img_tk = capture_screen_excluding_window(root)
label.config(image=img_tk)
label.image = img_tk # keep a reference to the image


# Create a button to capture and display the screen
btn = Button(root, text="Capture", command=capture_and_display)
btn.pack()


root.mainloop()
3 changes: 0 additions & 3 deletions examples/application/main.py

This file was deleted.

Loading

0 comments on commit 813613c

Please sign in to comment.