Files
CreoMigrate/lib/CreoMigrateGui.py
T

139 lines
5.5 KiB
Python

import tkinter as tk
#import ttkbootstrap as ttk
#from ttkbootstrap.constants import *
from gui import App
from caditem import CadItem, GuiLogic
from controller import Controller
from manage_configs import Configs
import argparse
import os
import json
demo_data = """
{
"parent_children_mapping": {
"400102130": [ "400102142" ],
"400102167": [ "821116004" ],
"400102168": [ "821116001" ],
"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" ],
"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" ],
"400102235": [ "400102236", "400102237", "400102238", "400102239",
"400102268", "911021143", "911021054", "911021055" ],
"400102236": [ "MA0000006" ],
"400102267": [ "400102235", "829416159", "829416077", "829416079",
"911021260", "911021147", "911251014" ],
"400102282": [ "822066026", "822066089", "919010052" ],
"821114025": [ "911081007", "821116053" ],
"821116004": [ "822026004" ],
"822064035": [ "822066065" ],
"822064091": [ "822066212", "822064093", "822066220", "822066200",
"912011010", "911021156", "822066201", "911071027", "913011109",
"911011070", "913011001", "710005021", "919010055", "720000008", "720000007" ],
"822064093": [ "822066204", "822066205", "822066206", "822066207", "822066208" ],
"822066075": [ "822066157", "822066162", "911261023" ],
"822066160": [ "MA0000004" ],
"822066162": [ "822064013" ],
"822066196": [ "MA0000008" ],
"822066220": [ "924031033" ],
"829416159": [ "829416089" ]
},
"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" ],
"gui_data": {
"asm_id": "400102190",
"teilenummer": "400102195",
"neuaufbau": "False",
"lebenszyklus_status_neu": "Serie",
"aus_halbzeug_neu": "True",
"zusatzinfos_auto_text": "Dies sind neue Zusatzinfos"
},
"data": {}
}
"""
#"teilenummer": "400102195", assembly
class Environment:
def __init__(self):
self.lib_dir = os.environ.get('CREMIG_LIB')
self.data_dir = os.environ.get('CREMIG_DATA')
self.out_dir = os.environ.get('CREMIG_WORK')
self.cfg_dir = os.environ.get('CREMIG_CFG')
self.ruledesigner_csv_filename = os.environ.get('RD_DATABASE_NAME')
def build_gui(model, configs, sivasid, uselocal=True):
root = tk.Tk()
#root = ttk.Window()
app = App(root)
controller = Controller(model, app)
controller.set_env(configs.get_env())
controller.get_csv_files_of_asm(sivasid, uselocal)
logic = GuiLogic(model, configs)
model.add_logic(logic)
# um ohne Observer pattern auch Rückmeldungen geben zu können
app.set_controller(controller)
model.set_controller(controller)
# Daten des Modells in der Oberfläche darstellen
controller.refresh_gui()
app.mainloop()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Das Programm ermöglicht einw graphisch unterstützte Migration eines Teiles oder Assemblies von Creo nach SolidEdge. Erzeugt eine korrekte Impfdatei.', prog='CreoMigrateGui')
parser.add_argument('-s', '--sivasid', action='store', help='Eingabe der SIVAS-Teilenummer, für die der Migrationsstatus angezeigt werden soll')
parser.add_argument('-d', '--demo', action='store_true', help='arbeitet ohne Server. Lädt Testdaten ein um nur eine Oberfläche darzustellen')
parser.add_argument('-l', '--uselocal', action='store_true', help='Verbinde dich nicht zur Datenbank. Benutzer alle lokalen Dateien (falls vorhanden) für die gegebene asm-id')
args = parser.parse_args()
environment = Environment()
output_dir = environment.out_dir
data_dir = environment.data_dir
configs = Configs(environment.cfg_dir)
configs.set_env(environment)
configs.set_data_dir(data_dir)
model = CadItem()
if args.demo:
model.from_json(json.loads(demo_data))
build_gui(model, configs)
elif args.sivasid:
sivasid = args.sivasid.strip()
assembl_path = os.path.join(output_dir, sivasid + '.json')
if os.path.exists(assembl_path):
# wenn schon einmal das assembly als json abgespeichert wurde, dann dieses laden
model.load(assembl_path)
else:
# die Gui aufbauen
build_gui(model, configs, sivasid, args.uselocal)
else:
parser.print_help()