Last change
on this file since 1236 was
1198,
checked in by Maciej Komosinski, 22 months ago
|
Added simple Python GUI for Framsticks library/server
|
File size:
1.2 KB
|
Rev | Line | |
---|
[1198] | 1 | import tkinter as tk
|
---|
| 2 | import tkinter.ttk as ttk
|
---|
| 3 | import glob
|
---|
| 4 | from pathlib import Path
|
---|
| 5 | from PIL import Image, ImageTk
|
---|
| 6 |
|
---|
| 7 | class TreeView(ttk.Treeview):
|
---|
| 8 | ICON_SIZE = 32
|
---|
| 9 | def __init__(self, master=None, iconPath="", **kw) -> None:
|
---|
| 10 | kw["show"] = "tree"
|
---|
| 11 | super().__init__(master=master, **kw)
|
---|
| 12 | self.icons = {}
|
---|
| 13 | self.s = ttk.Style()
|
---|
| 14 | self.s.configure('Treeview', rowheight=self.ICON_SIZE)
|
---|
| 15 | self.iconLoader(iconPath)
|
---|
| 16 |
|
---|
| 17 | def iconLoader(self, path):
|
---|
| 18 | files = glob.glob(path + "\\*.png")
|
---|
| 19 | for file in files:
|
---|
| 20 | icon = Image.open(file)
|
---|
| 21 | icon = icon.resize((self.ICON_SIZE, self.ICON_SIZE))
|
---|
| 22 | name = Path(file).name
|
---|
| 23 | name = name[:name.index('.')]
|
---|
| 24 | self.icons[name.lower()] = ImageTk.PhotoImage(icon)
|
---|
| 25 |
|
---|
| 26 | def insert(self, parent, index, iid=None, **kw) -> str:
|
---|
| 27 | if "ico" in kw:
|
---|
| 28 | ico = kw["ico"].lower()
|
---|
| 29 | del kw["ico"]
|
---|
| 30 | else:
|
---|
| 31 | ico = None
|
---|
| 32 |
|
---|
| 33 | if ico in self.icons:
|
---|
| 34 | img = self.icons[ico]
|
---|
| 35 | return super().insert(parent, index, iid=iid, image=img, **kw)
|
---|
| 36 | return super().insert(parent, index, iid=iid, **kw) |
---|
Note: See
TracBrowser
for help on using the repository browser.