aber nicht beides verwenden. Ich verwende z.B. nur
.
verwenden.
Widgets verwenden.
Habe anhand der vorhergehenden Beiträgen versucht das folgende Skript zu erstellen. Konnte aber mit der Klassenmethode
abbrechen müssen da ich eine nähere Beschreibung der ganzen Rechnerei und deiner Anwendung benötige. Was ist in deinem Skript der Unterschied zwischen
Code: Alles auswählen
import os
import time
from functools import partial
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import filedialog
APP_TITLE = "COG Tool"
APP_XPOS = 50
APP_YPOS = 50
APP_WIDTH = 800 #1800
APP_HEIGHT = 400 #800
class ModelVector(object):
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def __str__(self):
return '({0.x}, {0.y}, {0.z})'.format(self)
def __add__(self, other):
return ModelVector(
self.x + other.x, self.y + other.y, self.z + other.z)
class ModelMain(object):
DDY = -365
def __init__(self, app):
self.app = app
self.ddy = self.DDY
def export(self, filename, row_index, point_values):
x, y, z = point_values
with open(filename, 'a') as out_file:
out_file.write('$Erstellt durch COG-Tool am: {0}\n'.format(
time.strftime('%d.%m.%Y %H:%M:%S')))
hdpa_points = self.hdpa_berechnen(ModelVector(x, y, z), self.ddy)
self.hdpa_ausgabe(
ModelVector(x, self.ddy, z),
row_index, #self.sitzreihe
row_index, #self.i,
hdpa_points,
out_file)
out_file.write('ENDDATA\n')
def hdpa_berechnen(self, point, ddy):
return [
point + ModelVector(126 - 82, ddy, 594 - 58),
point + ModelVector(147 + 82, ddy, 594 - 52),
point + ModelVector(126 - 82, ddy, 693 + 82),
point + ModelVector(147 + 82, ddy, 693 + 82)]
def hdpa_ausgabe(self, h_point, sitzreihe, i_start, node_points, out_file):
print("Hier bricht meine Unterstützung ab!")
return
out_file.write(
'$H-Punkt: {0}\n'
'$HDPA-Feld fuer die {1}. Sitzreihe:\n'.format(h_point, sitzreihe)
)
i = None
for i, point in enumerate(node_points, i_start):
out_file.write(
'NODE / 1000000{0}{1.x:16.6f}{1.y:16.6f}{1.z:16.6f}\n'.format(
i, point
)
)
indices = [0, 1, 3, 2]
print("Check:", len(indices), i)
if len(indices) != i:
raise ValueError(
'wrong number of node points ({} != {})'.format(len(indices), i)
)
out_file.write(
'SHELL / 1000000{0} 11000000{1} \n'
'PART / 1000000{0}SHELL 1 \n'
'NAMEDefault HDPA_Feld_{0}.Sitzreihe\n'
' \n'
' \n'
' 1. 3 \n\n'
'END_PART\n'.format(
sitzreihe,
'1000000'.join(str(i_start + j) for j in indices),
)
)
class GuiSeatRow(tk.Frame):
ROW_NR_FONT = "Helvetica 22 bold"
def __init__(self, gui, row):
self.gui = gui
self.row = row
self.build()
def build(self):
tk.Frame.__init__(self, self.gui.main_frame)
self.row_var = tk.IntVar(self.gui.app.main_win, self.row+1)
tk.Label(self, textvariable= self.row_var, bg='blue',
fg='white', font=self.ROW_NR_FONT, width=2
).pack(pady=(5, 10))
self.box = tk.IntVar(self.gui.app.main_win, False)
tk.Checkbutton(self, text="HDPA Feld", variable=self.box
).pack()
self.hdpa = tk.Label(self, text="H-Punkt WS50%")
self.hdpa.pack(pady=5)
entry_frame = tk.Frame(self)
entry_frame.pack(pady=5)
label_frame = tk.LabelFrame(entry_frame, text="X:", relief='flat')
label_frame.pack(side='left')
self.hx_var = tk.StringVar(self.gui.app.main_win, 0)
tk.Entry(label_frame, textvariable=self.hx_var).pack()
label_frame = tk.LabelFrame(entry_frame, text="Z:", relief='flat')
label_frame.pack(side='left')
self.hz_var = tk.StringVar(self.gui.app.main_win, 0)
tk.Entry(label_frame, textvariable=self.hz_var).pack()
label_text = "Y-Abstand:\nCOG/H-Punkt zu Airbag"
label_frame = tk.LabelFrame(self, text=label_text,
relief='flat')
label_frame.pack(anchor='w', pady=5)
self.dy_var = tk.StringVar(self.gui.app.main_win, 0)
tk.Entry(label_frame, textvariable=self.dy_var).pack()
tk.Button(self, text="Export", command=partial(
self.gui.export, self.row)).pack(pady=5)
class GuiMain(object):
NOTEBOOK_TAB_FONT = ("Helvetica", 12, "bold")
ANZAHL_SITZREIHEN = 5
def __init__(self, app):
self.app = app
self.seat_rows = list()
self.build()
for row in range(self.ANZAHL_SITZREIHEN):
seat_row = GuiSeatRow(self, row)
seat_row.pack()
self.note_book.add(seat_row, text="Sitzreihe-{}".format(row+1),
sticky='nw', padding=10)
self.seat_rows.append(seat_row)
def build(self):
self.main_frame = tk.Frame(self.app.main_win)
self.main_frame.pack(fill='both', expand=True, padx=5, pady=5)
self.note_book = ttk.Notebook(self.main_frame)
self.note_book.pack(fill='both', expand=True)
def file_dialog(self):
filename = filedialog.asksaveasfilename(
initialdir=os.getcwd(),
title='Speichern der Include-Datei',
filetypes=(('all files', '*.*'), ('inc files', '*.inc')))
return filename
def export(self, row_index):
if self.seat_rows[row_index].box.get():
hx_var = self.seat_rows[row_index].hx_var
dy_var = self.seat_rows[row_index].dy_var
hz_var = self.seat_rows[row_index].hz_var
self.app.export(row_index, (float(entry_var.get())
for entry_var in [hx_var, dy_var, hz_var]))
else:
print("Kein HDPA-Feld")
print(self.seat_rows[row_index].hx_var.get())
class App(object):
def __init__(self, main_win):
self.main_win = main_win
self.main_win.protocol("WM_DELETE_WINDOW", self.close)
self.model = ModelMain(self)
self.gui = GuiMain(self)
def export(self, row_index, point_values):
filename = self.gui.file_dialog()
if filename != ():
self.model.export(filename, row_index, point_values)
else:
print("Filedialog wurde abgebrochen")
def close(self):
print("Application-Shutdown")
self.main_win.withdraw()
self.main_win.destroy()
def main():
main_win = tk.Tk()
main_win.title(APP_TITLE)
#main_win.geometry("+{}+{}".format(APP_XPOS, APP_YPOS))
main_win.geometry("{}x{}".format(APP_WIDTH, APP_HEIGHT))
main_win.option_add("*highlightThickness", 0)
ttk_style = ttk.Style()
ttk_style.configure('TNotebook.Tab', font="Helvetica 10 bold",
foreground='blue', background='gray75')
app = App(main_win)
main_win.mainloop()
if __name__ == '__main__':
main()