252 lines
10 KiB
Python
252 lines
10 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
#import logging
|
|
|
|
|
|
#logger = logging.getLogger(__name__)
|
|
|
|
|
|
red_ids = ( '400102274', '400102275', '400102190', '400102198',
|
|
'400102161', '400102277', '400102163', '400102278',
|
|
'400102282', '400102284', '400102195', 'MA0000008',
|
|
'MA0000004', '929055170', '400102267', '400102235',
|
|
'400102236', 'MA0000006', '400102237', '400102238',
|
|
'400102239', '400102268', '829416159', '924031058',
|
|
'924031081', '822064091', '822066199', '822066200')
|
|
|
|
parent_children_mapping = {'400102196': ['400102125', '400102126', '400102130',
|
|
'400102161', '400102163', '400102165',
|
|
'400102166', '400102167', '400102168',
|
|
'400102190', '400102195', '400102198',
|
|
'400102246', '400102247', '400102267',
|
|
'400102272', '400102274', '400102275',
|
|
'400102277', '400102278', '400102282',
|
|
'400102284', '400102417', '720002003',
|
|
'721001034', '821114025', '822064091',
|
|
'822066085', '822996075', '829416061',
|
|
'829516004', '911021113', '911021181',
|
|
'911021259', '911091054', '911091096',
|
|
'911091097', '911251013', '912011009',
|
|
'919050006', '924031058',
|
|
'924031081'],
|
|
'400102282': ['822066026', '822066089', '919010052'],
|
|
'400102195': [ '822066075', '822066216',
|
|
'822066154', '822066101', '822064090',
|
|
'822066196', '400102129', '822066217',
|
|
'822066160', '822066215', '913041045',
|
|
'913011009', '911011057', '822064035',
|
|
'925011006', '911091041', '913051040',
|
|
'911021112', '911021166', '825006003',
|
|
'912041005', '911011014', '911011009',
|
|
'911021144', '911021001', '913011016',
|
|
'929055170', '913011010', '911021035',
|
|
'829416065', '712000151',
|
|
'712000100'],
|
|
'822066075': ['822066157', '822066162', '911261023'],
|
|
'822066162': [ '822064013'],
|
|
'822066196': ['MA0000008'],
|
|
'822066160': ['MA0000004'],
|
|
'822064035': ['822066065'],
|
|
'822064093': ['822066204', '822066205', '822066206', '822066207', '822066208'],
|
|
'822066220': ['924031033'],
|
|
'822064091': ['822066212', '822064093', '822066220',
|
|
'822066200', '912011010', '911021156',
|
|
'822066201', '911071027', '913011109',
|
|
'911011070', '913011001', '710005021',
|
|
'919010055', '720000008', '720000007'],
|
|
'400102267': ['400102235', '829416159', '829416077',
|
|
'829416079', '911021260', '911021147',
|
|
'911251014'],
|
|
'400102235': ['400102236', '400102237', '400102238',
|
|
'400102239', '400102268', '911021143',
|
|
'911021054', '911021055'],
|
|
'400102236': ['MA0000006'],
|
|
'829416159': ['829416089'],
|
|
'400102130': ['400102142'],
|
|
'821116004': ['822026004'],
|
|
'400102168': ['821116001'],
|
|
'821114025': ['911081007', '821116053'],
|
|
'400102167': ['821116004']}
|
|
|
|
|
|
|
|
""" using the MVC Pattern
|
|
- The model is responsible for managing the data of the application. It
|
|
receives user input from the controller.
|
|
- The view renders presentation of the model in a particular format.
|
|
- The controller responds to the user input and performs interactions on the
|
|
data model objects. The controller receives the input, optionally validates
|
|
it and then passes the input to the model.
|
|
"""
|
|
class Model():
|
|
def __init__(self):
|
|
pass
|
|
def set_tree_data(self, red_ids, parent_children_mapping):
|
|
self.red_ids = red_ids
|
|
self.parent_children_mapping = parent_children_mapping
|
|
def get_red_ids(self):
|
|
return self.red_ids
|
|
def get_parent_children(self):
|
|
return self.parent_children_mapping
|
|
def load():
|
|
pass
|
|
def save():
|
|
pass
|
|
|
|
class Controller():
|
|
def __init__(self):
|
|
pass
|
|
|
|
class View():
|
|
def __init__(self):
|
|
pass
|
|
|
|
|
|
class TreeView():
|
|
def __init__(self, frame):
|
|
# a treeview
|
|
self.tree = ttk.Treeview(frame)
|
|
# TODO hier anstatt root die Statistik rein schreiben.
|
|
self.tree.heading('#0', text='root', anchor=tk.W)
|
|
|
|
def set_red_ids(self, red_ids):
|
|
self.red_ids = red_ids
|
|
|
|
def set_parent_children(self, parent_children_mapping):
|
|
self.parent_children_mapping = parent_children_mapping
|
|
|
|
def clear(self):
|
|
self.tree.clipboard_clear()
|
|
|
|
def create(self):
|
|
# adding data of first column after root
|
|
pool = set()
|
|
for parent,children in self.parent_children_mapping.items():
|
|
if parent not in pool:
|
|
self.tree.insert('', tk.END, text=parent, iid=parent, open=True)
|
|
pool.add(parent)
|
|
cn = children
|
|
# sortiere die Zahlen im Baum immer aufsteigend
|
|
cn.sort(reverse=True)
|
|
for child_id in cn:
|
|
if child_id not in pool:
|
|
pool.add(child_id)
|
|
if child_id not in self.red_ids: rowtags = ('good')
|
|
else: rowtags = ('missing')
|
|
self.tree.insert('', tk.END, text=child_id, iid=child_id, tags=rowtags, open=True)
|
|
#self.tree.move(child_id, parent, 0)
|
|
|
|
# einmal über alles gehen und alle keys an die richtige Stelle schieben
|
|
for parent,children in self.parent_children_mapping.items():
|
|
for child_id in children:
|
|
self.tree.move(child_id, parent, 0)
|
|
|
|
# https://www.askpython.com/python-modules/tkinter/tkinter-colors
|
|
#self.tree.tag_configure('good', background='LawnGreen')
|
|
self.tree.tag_configure('good', background='white')
|
|
self.tree.tag_configure('missing', background='red')
|
|
|
|
# place the Treeview widget on the root window
|
|
self.tree.grid(row=0, column=0, sticky=tk.NSEW)
|
|
|
|
|
|
class PanedWindow():
|
|
"""Hauptfenster zweiteilen, um die Grösse rechts oder links zu verschieben"""
|
|
def __init__(self, frame):
|
|
self.pw = ttk.PanedWindow(frame, orient=tk.HORIZONTAL)
|
|
|
|
# Left listbox
|
|
left_list = tk.Listbox(frame)
|
|
left_list.pack(side=tk.LEFT)
|
|
self.pw.add(left_list)
|
|
self.left_list = left_list
|
|
|
|
# Right listbox
|
|
right_list = tk.Listbox(frame)
|
|
right_list.pack(side=tk.LEFT)
|
|
self.pw.add(right_list)
|
|
self.right_list = right_list
|
|
|
|
def get_handle(self):
|
|
return self.pw
|
|
|
|
def get_left(self):
|
|
return self.left_list
|
|
|
|
def get_right(self):
|
|
return self.right_list
|
|
|
|
|
|
class App():
|
|
def __init__(self, root):
|
|
|
|
self.root = root
|
|
|
|
self.root.geometry('500x700')
|
|
|
|
style = ttk.Style(self.root)
|
|
style.theme_use('classic')
|
|
|
|
# style.configure('Error.TLabel', foreground='white')
|
|
# style.configure('Error.TLabel', background='red')
|
|
# style.configure('Error.TLabel', font=('Helvetica', 12))
|
|
# style.configure('Error.TLabel', padding=(10, 10))
|
|
|
|
# paned window
|
|
self.pw = PanedWindow(self.root)
|
|
self.tv = TreeView(self.root)
|
|
|
|
left_list = self.pw.get_left()
|
|
right_list = self.pw.get_right()
|
|
# left_list.pack(side=tk.LEFT)
|
|
# right_list.pack(side=tk.LEFT)
|
|
|
|
# place the panedwindow on the root window
|
|
pw = self.pw.get_handle()
|
|
pw.pack(fill=tk.BOTH, expand=True)
|
|
|
|
message = 'This is an error message!'
|
|
label = ttk.Label(right_list, text=message, style='Error.TLabel')
|
|
label.pack(expand=True)
|
|
|
|
def set_tree_data(self, red_ids, parent_children_mapping):
|
|
self.red_ids = red_ids
|
|
self.parent_children_mapping = parent_children_mapping
|
|
self.tv.set_red_ids(self.red_ids)
|
|
self.tv.set_parent_children(self.parent_children_mapping)
|
|
self.tv.create()
|
|
|
|
def mainloop(self):
|
|
self.root.mainloop()
|
|
|
|
|
|
# class Navbar(tk.Frame): ...
|
|
# class Toolbar(tk.Frame): ...
|
|
# class Statusbar(tk.Frame): ...
|
|
# class Main(tk.Frame): ...
|
|
|
|
# class MainApp(tk.Frame):
|
|
# def __init__(self, parent, *args, **kwargs):
|
|
# tk.Frame.__init__(self, parent, *args, **kwargs)
|
|
# self.statusbar = Statusbar(self, ...)
|
|
# self.toolbar = Toolbar(self, ...)
|
|
# self.navbar = Navbar(self, ...)
|
|
# self.main = Main(self, ...)
|
|
|
|
# self.statusbar.pack(side="bottom", fill="x")
|
|
# self.toolbar.pack(side="top", fill="x")
|
|
# self.navbar.pack(side="left", fill="y")
|
|
# self.main.pack(side="right", fill="both", expand=True)
|
|
|
|
if __name__ == "__main__":
|
|
#logging.basicConfig(level=logging.DEBUG)
|
|
model = Model()
|
|
model.set_tree_data(red_ids, parent_children_mapping)
|
|
|
|
controller = Controller()
|
|
|
|
root = tk.Tk()
|
|
app = App(root)
|
|
app.set_tree_data(model.get_red_ids(), model.get_parent_children())
|
|
app.mainloop()
|