Skip to content

Commit

Permalink
documents examples black isort ruff and small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
littlewhitecloud authored Jun 30, 2023
1 parent 9aac91d commit 152851a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,33 @@
## Styles
```tkterminalwidget``` also have some styles to use such as ```Powershell``` ```Command```:
![image](https://github.com/littlewhitecloud/TkTerminal/assets/71159641/3affd018-0408-4e91-96de-4775937e0ab8)
![image](https://github.com/littlewhitecloud/TkTerminal/assets/71159641/2b43b9d0-7569-498b-932d-e18828541d47)
But also, you can create your custom style by using
```python
from tktermwidget import Config, POWERSHELL

styleconfig = Config(usetheme=True, basedon=POWERSHELL)
# if usetheme enable, the window will use sv_ttk theme
# basedon mean you can create your style based on the "basedon" style
styleconfig.mainloop()
```
![image](https://github.com/littlewhitecloud/TkTerminal/assets/71159641/09a53045-8806-4e63-9045-741bcce65e99)

After saving it, you can write down this to use the custom theme:
```python
from tkinterwidget import Terminal, CUSTOM
example = Terminal(window, style=CUSTOM) # your custom theme
example.mainloop()
```
Or use a built in theme:
```python
from tkinterwidget import Terminal, POWERSHELL # use powershell for an example
example = Terminal(window, style=POWERSHELL)
example.mainloop()
```

## Installation:
```batch
```console
pip install tktermwidget
```

Expand Down Expand Up @@ -74,4 +97,3 @@ root.deiconify()
# Start mainloop
root.mainloop()
```

29 changes: 27 additions & 2 deletions README_CH.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,35 @@

## 风格
```tkterminalwidget``` 也有一些主题可以用 比如 ```Powershell``` ```Command```
![image](https://github.com/littlewhitecloud/TkTerminal/assets/71159641/b1f7cfec-c5e7-48a0-be40-0c0f63fb959b)
![image](https://github.com/littlewhitecloud/TkTerminal/assets/71159641/3affd018-0408-4e91-96de-4775937e0ab8)
![image](https://github.com/littlewhitecloud/TkTerminal/assets/71159641/2b43b9d0-7569-498b-932d-e18828541d47)
但是,用这个你也可以创建自己的主题:
```python
from tktermwidget import Config, POWERSHELL

styleconfig = Config(usetheme=True, basedon=POWERSHELL)
# 如果usetheme启用的话,窗口会使用sv_ttk主题
# basedon意义是在基于“basedon”得到的主题上创建你自己的主题
styleconfig.mainloop()
```
![image](https://github.com/littlewhitecloud/TkTerminal/assets/71159641/09a53045-8806-4e63-9045-741bcce65e99)

在保存完它之后,你可以写下下面的代码来创建你自己的主题:

```python
from tkinterwidget import Terminal, CUSTOM
example = Terminal(window, style=CUSTOM) #你自己的主题
example.mainloop()
```
或者使用一个构建好的主题
```python
from tkinterwidget import Terminal, POWERSHELL # 用Powershell举例
example = Terminal(window, style=POWERSHELL)
example.mainloop()
```

## 安装:
```batch
```console
pip install tktermwidget
```

Expand Down
7 changes: 7 additions & 0 deletions examples/style_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""An example for style"""
from tktermwidget import POWERSHELL, Config

styleconfig = Config(usetheme=True, basedon=POWERSHELL)
# if usetheme enable, the window will use sv_ttk theme
# basedon mean you can create your style based on the "basedon" style
styleconfig.mainloop()
7 changes: 7 additions & 0 deletions examples/style_example_ch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""An exmaple for style"""
from tktermwidget import POWERSHELL, Config

styleconfig = Config(usetheme=True, basedon=POWERSHELL)
# 如果usetheme启用的话,窗口会使用sv_ttk主题
# basedon意义是在基于“basedon”得到的主题上创建你自己的主题
styleconfig.mainloop()
2 changes: 1 addition & 1 deletion tktermwidget/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(self, usetheme: bool = False, basedon: dict[str] = DEFAULT):
self.withdraw()
self.deiconify()

self.style: dict[str] = basedon if load_style() == {} else load_style()
self.style: dict[str] = basedon if basedon != DEFAULT else load_style() if load_style() != {} else DEFAULT

# Color choose or input widgets
# TODO: check the hex color is it vaild
Expand Down
7 changes: 6 additions & 1 deletion tktermwidget/tkterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from tkinter.ttk import Frame, Scrollbar

from platformdirs import user_cache_dir
from style import DEFAULT

dev: bool = False
if dev:
from style import DEFAULT
else:
from .style import DEFAULT # noqa: F401

# Set constants
HISTORY_PATH = Path(user_cache_dir("tktermwidget"))
Expand Down

0 comments on commit 152851a

Please sign in to comment.