Dateien hochladen nach „“

main
Justus Jan Nico Wolff 2023-01-07 22:32:50 +01:00
parent 167a5fcd1e
commit c6eb8e0502
3 changed files with 310 additions and 0 deletions

1
combinations.txt 100644
View File

@ -0,0 +1 @@
{1: {'name': 'variable erstellen', 'code': '#executor\n#block\n#args\nexecutor.makevariable(args[0], args[1])', 'args': 2}, 2: {'name': 'bekomme den variablen value', 'code': '#executor\n#block\n#args\nexecutor.getvariable(args[0])', 'args': 1}, 3: {'name': 'setze variablen value', 'code': '#executor\n#block\n#args\nexecutor.setvariable(args[0], args[1])', 'args': 2}, 4: {'name': 'l<>sche variable', 'code': '#executor\n#block\n#args\nexecutor.deletevariable(args[0])', 'args': 1}, 5: {'name': 'gebe variable value aus', 'code': '#executor\n#block\n#args\nprint(executor.getvariable(args[0]))', 'args': 1}, 7: {'name': 'plus rechnen test bla bla bla nervig BRUH', 'code': '#executor\n#block\n#args\nprint(int(args[0])+int(args[1]))', 'args': 2}}

38
errors.md 100644
View File

@ -0,0 +1,38 @@
# fehler im BP executor
## was sind fehler?
fehler im BP executor werden nur angezeigt wenn sie kritisch sind. sie werden als ersetzungstext genutzt um den BP executor vor dem crashen zu schützen.
# die fehler und ihre bedeutungen
## dieser part beschreibt die fehler texte/namen und ihre bedeutungen.
## fehler text:
ERROR 1
## bedeutung:
der typ des blockes ist unbekannt.
## fehler text:
ERROR 2: <fehler information>
## bedeutung:
irgendetwas ist schiefgelaufen beim ausführen eines blockes. die fehler information erläutert mehr
## fehler text:
ERROR 3: block type: <block typ>
## bedeutung:
spoiler: es hat was mit ERROR 1 zu tun, ERROR 3 passiert wenn versucht wird denn block auszuführen aber der typ des blockes
ist unbekannt. block typ erläutert den block typ.
## fehler text:
ERROR 4
## bedeutung:
ERROR 4 passiert wenn der executor versucht den text des types wieder in eine zahl umzuwandeln, und währenddessen was schiefläuft. in dem fall kann der executor kein passenden typ zu diesem text finden.
## fehler text:
ERROR 5
## bedeutung:
ein block versucht eine variable zu editieren, zu löschen oder zu lesen die nicht existiert.
## fehler text:
ERROR 6
## bedeutung:
bei der argumenten abfrage wurde auf cancel gedrückt.

271
main.py 100644
View File

@ -0,0 +1,271 @@
from tkinter import messagebox
import tkinter as tk
import ast
import easygui
from tkinter import filedialog
class block():
def __init__(self, combinations, executor, type=-1, args=[]):
self.type = type
self.combinations = combinations
self.executor = executor
self.args = args
def gettypeintext(self):
if self.type in self.combinations:
return self.combinations[self.type]["name"]
else:
return "ERROR 1"
def execute(self):
preparedargs = []
for i in self.args:
if "<variable>" in i:
temp = i.replace("<variable>", "")
temp = self.executor.getvariable(temp)
preparedargs.append(temp)
else:
preparedargs.append(i)
if self.type in self.combinations:
temp2 = {"executor": self.executor, "block": self, "args": preparedargs}
try:
exec(self.combinations[self.type]["code"], temp2)
except Exception as e:
messagebox.showerror("fehler", "ERROR 2: block type: {} error information: {}".format(self.type, e))
else:
messagebox.showerror("fehler", "ERROR 3: block type: {}".format(self.type))
def converttotext(self):
temp = {"type": self.type, "args": self.args}
return temp
class blockstream():
def __init__(self, blocks):
self.blocks = blocks
def addblock(self, block):
self.blocks.append(block)
def execute(self):
for i in self.blocks:
i.execute()
def executespecblock(self, index):
try:
self.blocks[index].execute()
except:
pass
def getnames(self):
temp = []
for i in self.blocks:
temp.append(i.gettypeintext())
return temp
def getargs(self):
temp = []
for i in self.blocks:
temp.append(i.args)
return temp
class executor():
def __init__(self, combinations):
self.blockstream = blockstream([])
self.combinations = combinations
self.container = tk.Tk()
self.buttons = []
self.block = 0
self.runloop = False
self.variables = {}
self.update()
def startloop(self):
self.container.mainloop()
def addblock(self, type, args):
self.blockstream.addblock(block(self.combinations, self, type=type, args=args))
def delete(self, index):
self.blockstream.blocks.remove(self.blockstream.blocks[index])
self.update()
def executespecblock(self, index):
self.blockstream.executespecblock(index)
def execute(self):
self.variables = {}
self.block = 0
while self.block <= len(self.blockstream.blocks):
self.executespecblock(self.block)
self.block += 1
def texttointtype(self, type):
temp = "ERROR 4"
for i in self.combinations:
if self.combinations[i]["name"] == type:
temp = i
return temp
def getallblocknames(self):
temp = []
for i in self.combinations:
temp.append(self.combinations[i]["name"])
return temp
def addblockprepare(self, selected, container):
selected = selected.get()
args = []
for i in range(self.combinations[self.texttointtype(selected)]["args"]):
reply = easygui.enterbox("argument nummer {}".format(i+1), "argumenten abfrage")
if reply:
if reply[0] == "*" and reply[-1] == "*":
temp = reply
temp = temp[1:]
temp = temp[:-1]
args.append("<variable>{}".format(temp))
else:
args.append(reply)
else:
args.append("ERROR 6")
self.addblock(self.texttointtype(selected), args)
self.update()
container.destroy()
def setargs(self, index, blocktype, container):
args = []
for i in range(self.combinations[self.texttointtype(blocktype)]["args"]):
reply = easygui.enterbox("argument nummer {}".format(i+1), "argumenten abfrage")
if reply:
if reply[0] == "*" and reply[-1] == "*":
temp = reply
temp = temp[1:]
temp = temp[:-1]
args.append("<variable>{}".format(temp))
else:
args.append(reply)
else:
args.append("ERROR 6")
self.blockstream.blocks[index].args = args
self.update()
container.destroy()
def delete2(self, index, container):
self.blockstream.blocks.remove(self.blockstream.blocks[index])
self.update()
container.destroy()
def blockmenu(self, index):
container = tk.Tk()
temp = self.blockstream.getnames()
tempargs = self.blockstream.getargs()
info = tk.Label(container, text="block information: {}".format("'{}' args: {}".format(temp[index], tempargs[index])))
info.grid()
deletebutton = tk.Button(container, text="block löschen", command=lambda: self.delete2(index, container))
deletebutton.grid()
argsset = tk.Button(container, text="argumente neu setzen", command=lambda: self.setargs(index, temp[index], container))
argsset.grid()
back = tk.Button(container, text="zurück", command=container.destroy)
back.grid()
container.mainloop()
def menu(self):
container = tk.Tk()
selectable = self.getallblocknames()
selected = tk.StringVar(container)
selected.set(selectable[0])
menu = tk.OptionMenu(container, selected, *selectable)
menu.grid()
addbutton = tk.Button(container, text="block hinzufügen", command=lambda: self.addblockprepare(selected, container))
addbutton.grid()
container.mainloop()
def makevariable(self, variablename, value="0"):
self.variables[variablename] = value
def deletevariable(self, variablename):
if variablename in self.variables:
del self.variables[variablename]
else:
messagebox.showerror("fehler", "ERROR 5")
def getvariable(self, variablename):
try:
return self.variables[variablename]
except:
messagebox.showerror("fehler", "ERROR 5")
return "ERROR 5"
def setvariable(self, variablename, value):
if variablename in self.variables:
self.variables[variablename] = value
else:
messagebox.showerror("fehler", "ERROR 5")
def manuelsave(self, path):
temp = []
for i in self.blockstream.blocks:
temp.append(i.converttotext())
file = open(path, 'w')
file.write(str(temp))
file.close()
def manuelload(self, path):
file = open(path, 'r')
file = file.read()
file = ast.literal_eval(file)
self.blockstream.blocks = []
for i in file:
self.addblock(i["type"], i["args"])
self.update()
def save(self):
temp = []
for i in self.blockstream.blocks:
temp.append(i.converttotext())
file = open(filedialog.asksaveasfilename(defaultextension=".BPE"), 'w')
file.write(str(temp))
file.close()
messagebox.showinfo("fertig", "speichern abgeschlossen")
def load(self):
file = open(filedialog.askopenfilename(), 'r')
file = file.read()
file = ast.literal_eval(file)
self.blockstream.blocks = []
for i in file:
self.addblock(i["type"], i["args"])
self.update()
def update(self):
try:
self.executebutton.grid_forget()
self.addblockn.grid_forget()
self.savebutton.grid_forget()
self.loadbutton.grid_forget()
except:
pass
for i in self.buttons.copy():
i.grid_forget()
self.buttons.remove(i)
temp = self.blockstream.getnames()
tempargs = self.blockstream.getargs()
for i in range(len(temp)):
index = i
i = temp[i]
temp2 = tk.Button(self.container, text="'{}' args: {}".format(i, tempargs[index]), command=lambda index=index: self.blockmenu(index))
temp2.grid()
self.buttons.append(temp2)
self.executebutton = tk.Button(self.container, text="ausführen", command=self.execute)
self.executebutton.grid()
self.addblockn = tk.Button(self.container, text="block hinzufügen", command=self.menu)
self.addblockn.grid()
self.savebutton = tk.Button(self.container, text="speichern", command=self.save)
self.savebutton.grid()
self.loadbutton = tk.Button(self.container, text="laden", command=self.load)
self.loadbutton.grid()
combinations = open("combinations.txt", 'r')
combinations = combinations.read()
combinations = ast.literal_eval(combinations)
temp = executor(combinations)
temp.startloop()