344 lines
14 KiB
Python
344 lines
14 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
#from tkinter import messagebox
|
|
#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']}
|
|
|
|
|
|
|
|
|
|
class TreeView():
|
|
def __init__(self, frame):
|
|
# a treeview
|
|
# hier Anzahl der sichtbaren Zeilen des Baums angeben:
|
|
self.tree = ttk.Treeview(frame, height=40)
|
|
# TODO hier anstatt root die Statistik rein schreiben.
|
|
self.tree.heading('#0', text='root', anchor=tk.W)
|
|
|
|
# add a scrollbar
|
|
scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL, command=self.tree.yview)
|
|
self.tree.configure(yscroll=scrollbar.set)
|
|
scrollbar.grid(row=0, column=1, sticky='ns')
|
|
|
|
self.tree.bind('<<TreeviewSelect>>', self.item_selected)
|
|
|
|
def clear(self):
|
|
self.tree.delete()
|
|
|
|
def create(self, parent_children_mapping, red_ids):
|
|
# adding data of first column after root
|
|
pool = set()
|
|
for parent,children in 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 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 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')
|
|
|
|
def item_selected(self, event):
|
|
"""callback if an item in the tree has been selected
|
|
"""
|
|
id = self.tree.selection()[0]
|
|
# for selected_item in self.tree.selection():
|
|
# item = self.tree.item(selected_item)
|
|
# record = item['values']
|
|
# messagebox.showinfo(title='Information', message=','.join(record))
|
|
|
|
|
|
|
|
def get_handle(self):
|
|
return self.tree
|
|
|
|
|
|
|
|
class App():
|
|
def __init__(self, root, controller):
|
|
|
|
self.root = root
|
|
self.controller = controller
|
|
|
|
# configure the grid
|
|
# self.root.columnconfigure(0, weight=2)
|
|
# self.root.columnconfigure(1, weight=1)
|
|
# self.root.columnconfigure(2, weight=1)
|
|
# self.root.columnconfigure(3, weight=1)
|
|
# self.root.columnconfigure(4, weight=1)
|
|
#self.root.geometry('800x800')
|
|
#self.root.resizable(0, 0)
|
|
|
|
# Create left and right frames
|
|
left_frame = ttk.Frame(self.root, width=200, height=800)
|
|
left_frame.grid(row=0, column=0, padx=10, pady=5)
|
|
|
|
right_frame = ttk.Frame(self.root, width=650, height=800)
|
|
right_frame.grid(row=0, column=1, padx=10, pady=5)
|
|
|
|
|
|
style = ttk.Style(self.root)
|
|
style.theme_use('classic')
|
|
|
|
self.tv = TreeView(left_frame)
|
|
self.tv.create(parent_children_mapping, red_ids)
|
|
gridhdl = self.tv.get_handle()
|
|
gridhdl.grid(row=0, column=0, sticky=tk.NSEW)
|
|
|
|
self.create_widgets(right_frame)
|
|
|
|
# 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))
|
|
|
|
# message = 'This is an error message!'
|
|
# error_label = ttk.Label(self.root, text=message, style='Error.TLabel')
|
|
# error_label.grid(column=2, row=3, sticky=tk.E, padx=5, pady=5)
|
|
|
|
|
|
def create_widgets(self, frame):
|
|
rownum = 0
|
|
col_left = 0
|
|
# pdmkategorie
|
|
pdmkategorie_label = ttk.Label(frame, text="PDM-Kategorie:" )
|
|
pdmkategorie_label.grid(column=col_left, row=rownum, sticky=tk.W, padx=5, pady=5)
|
|
pdmkategorie_entry = ttk.Entry(frame)
|
|
pdmkategorie_entry.grid(column=col_left+2, row=rownum, sticky=tk.W, padx=5, pady=5)
|
|
rownum += 1
|
|
|
|
# Neuaufbau
|
|
neuaufbau_label = ttk.Label(frame, text="Neuaufbau:")
|
|
neuaufbau_label.grid(column=col_left, row=rownum, sticky=tk.W, padx=5, pady=5)
|
|
|
|
self.neuaufbau = None
|
|
neuaufbau_checkbutton = ttk.Checkbutton(frame,
|
|
text='ja',
|
|
command=self.var_changed("neuaufbau"),
|
|
variable=self.neuaufbau,
|
|
onvalue=True,
|
|
offvalue=False)
|
|
neuaufbau_checkbutton.grid(column=col_left+2, row=rownum, sticky=tk.W, padx=5, pady=5)
|
|
rownum += 1
|
|
|
|
# Lebenszyklusstatus
|
|
lebenszyklusstatus_label = ttk.Label(frame, text="Lebenszyklusstatus:")
|
|
lebenszyklusstatus_label.grid(column=col_left, row=rownum, sticky=tk.W, padx=5, pady=5)
|
|
lebenszyklusstatus_entry = ttk.Entry(frame, show="*")
|
|
lebenszyklusstatus_entry.grid(column=col_left+2, row=rownum, sticky=tk.W, padx=5, pady=5)
|
|
rownum += 1
|
|
|
|
def var_changed(self, whichvar):
|
|
a = whichvar
|
|
b = self.neuaufbau
|
|
|
|
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__":
|
|
|
|
""" using the Model-View-Controller (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.
|
|
|
|
MODEL
|
|
<-updates- ^--manipulates--
|
|
VIEW CONTROLLER
|
|
--sees --> -- uses -->
|
|
USER
|
|
"""
|
|
class CadItem():
|
|
"""
|
|
This item contains all data for writing all necessary data to the solid edg cad file
|
|
"""
|
|
def __init__(self, uid):
|
|
""" is initalized with its unique id"""
|
|
self.id = uid
|
|
self.red_ids = {}
|
|
self.parent_children_mapping = {}
|
|
|
|
def set_parent_children(self, parent_children_mapping):
|
|
""" contains all id relations below, data of subassemblies etc. in
|
|
a dict of the kind parent-children
|
|
"""
|
|
self.parent_children_mapping = parent_children_mapping
|
|
def get_parent_children(self):
|
|
return self.parent_children_mapping
|
|
|
|
def set_red_ids(self, red_ids):
|
|
""" these ids are not yet known by the PDM"""
|
|
self.red_ids = red_ids
|
|
|
|
def get_red_ids(self):
|
|
return self.red_ids
|
|
|
|
def load():
|
|
pass
|
|
def save():
|
|
pass
|
|
|
|
|
|
class CadItemRepository:
|
|
"""
|
|
container class for all CadItems in the local folder
|
|
also just managed by the controller
|
|
"""
|
|
def __init__(self):
|
|
self.caditems = []
|
|
|
|
def add(self, caditem):
|
|
self.caditems.append(caditem)
|
|
|
|
def get(self, id):
|
|
for caditem in self.caditems:
|
|
if caditem.id == id:
|
|
return caditem
|
|
return None
|
|
|
|
def get_all(self):
|
|
return self.caditems
|
|
|
|
def update(self, old_item, new_item):
|
|
self.delete(old_item.id)
|
|
self.add(new_item)
|
|
raise Exception("CadItem not found")
|
|
|
|
def delete(self, id):
|
|
for p in self.caditems:
|
|
if p.id == id:
|
|
self.caditems.remove(p)
|
|
return
|
|
raise Exception("CadItem not found")
|
|
|
|
class Controller():
|
|
"""
|
|
Class for manipulating the model and returning data for the view
|
|
"""
|
|
def __init__(self, model):
|
|
self.model = model
|
|
|
|
def set_red_ids(self, red_ids):
|
|
self.red_ids = red_ids
|
|
def get_red_ids(self):
|
|
return self.red_ids
|
|
|
|
def set_parent_children(self, parent_children_mapping):
|
|
self.parent_children_mapping = parent_children_mapping
|
|
def get_parent_children(self):
|
|
return self.parent_children_mapping
|
|
|
|
|
|
#logging.basicConfig(level=logging.DEBUG)
|
|
model = CadItem("400102196")
|
|
|
|
controller = Controller(model)
|
|
controller.set_parent_children(parent_children_mapping)
|
|
controller.set_red_ids(red_ids)
|
|
|
|
root = tk.Tk()
|
|
app = App(root, controller)
|
|
app.mainloop()
|