From 75deb57548110b3fe6033541f73bb21dd36758db Mon Sep 17 00:00:00 2001 From: mistangl Date: Wed, 10 Jan 2024 16:12:23 +0100 Subject: [PATCH] weiterer Protyp des gesamtfensters --- lib/CreoMigrateGui.py | 233 +++++++++++++++++++++++++----------------- 1 file changed, 139 insertions(+), 94 deletions(-) diff --git a/lib/CreoMigrateGui.py b/lib/CreoMigrateGui.py index b368b6a..124bf12 100644 --- a/lib/CreoMigrateGui.py +++ b/lib/CreoMigrateGui.py @@ -70,37 +70,6 @@ parent_children_mapping = {'400102196': ['400102125', '400102126', '400102130', -""" 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): @@ -109,19 +78,13 @@ class TreeView(): # 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): + def create(self, parent_children_mapping, red_ids): # adding data of first column after root pool = set() - for parent,children in self.parent_children_mapping.items(): + 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) @@ -131,13 +94,13 @@ class TreeView(): 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') + 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 self.parent_children_mapping.items(): + for parent,children in parent_children_mapping.items(): for child_id in children: self.tree.move(child_id, parent, 0) @@ -146,43 +109,24 @@ class TreeView(): 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 + return self.tree - def get_left(self): - return self.left_list - - def get_right(self): - return self.right_list class App(): - def __init__(self, root): + def __init__(self, root, controller): self.root = root + self.controller = controller - self.root.geometry('500x700') + # configure the grid + root.columnconfigure(0, weight=2) + root.columnconfigure(1, weight=1) + root.columnconfigure(2, weight=1) + root.columnconfigure(3, weight=1) + root.geometry('800x700') + root.resizable(0, 0) style = ttk.Style(self.root) style.theme_use('classic') @@ -192,29 +136,34 @@ class App(): # 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) + self.tv.create(parent_children_mapping, red_ids) + gridhdl = self.tv.get_handle() + gridhdl.grid(row=0, column=0, rowspan=2, sticky=tk.NSEW) - left_list = self.pw.get_left() - right_list = self.pw.get_right() - # left_list.pack(side=tk.LEFT) - # right_list.pack(side=tk.LEFT) + # message = 'This is an error message!' + # label = ttk.Label(right_list, text=message, style='Error.TLabel') + self.create_widgets() - # 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 create_widgets(self): + # username + username_label = ttk.Label(self.root, text="Username:") + username_label.grid(column=1, row=0, sticky=tk.W, padx=5, pady=5, bg="green") - 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() + username_entry = ttk.Entry(self.root) + username_entry.grid(column=2, row=0, sticky=tk.E, padx=5, pady=5) + + # password + password_label = ttk.Label(self.root, text="Password:") + password_label.grid(column=1, row=1, sticky=tk.W, padx=5, pady=5) + + password_entry = ttk.Entry(self.root, show="*") + password_entry.grid(column=2, row=1, sticky=tk.E, padx=5, pady=5) + + # login button + login_button = ttk.Button(self.root, text="Login") + login_button.grid(column=2, row=2, sticky=tk.E, padx=5, pady=5) def mainloop(self): self.root.mainloop() @@ -239,13 +188,109 @@ class App(): # 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() + """ 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) - app.set_tree_data(model.get_red_ids(), model.get_parent_children()) + app = App(root, controller) app.mainloop()