varoius improvements
This commit is contained in:
@@ -36,7 +36,7 @@ class generic_instruction(Iinstruction):
|
|||||||
|
|
||||||
def __init__(self, instruction_text: str) -> None:
|
def __init__(self, instruction_text: str) -> None:
|
||||||
Iinstruction.__init__(self, instruction_text)
|
Iinstruction.__init__(self, instruction_text)
|
||||||
|
|
||||||
def to_image(self, x:int, y:int, x_sz: int) -> Iterable[float]:
|
def to_image(self, x:int, y:int, x_sz: int) -> Iterable[float]:
|
||||||
return cti.draw_generic_instruction(self.instruction_text, x, y, x_sz, self.getblkheight())
|
return cti.draw_generic_instruction(self.instruction_text, x, y, x_sz, self.getblkheight())
|
||||||
|
|
||||||
@@ -74,38 +74,38 @@ class if_instruction(Iinstruction):
|
|||||||
sz += inst.getblkwidth()
|
sz += inst.getblkwidth()
|
||||||
return sz
|
return sz
|
||||||
|
|
||||||
def getblkheight(self) -> float:
|
|
||||||
return self._getblkheight() + max(self.get_trueheight(), self.get_falseheight())
|
|
||||||
|
|
||||||
def getblkwidth(self) -> float:
|
|
||||||
return max(self._getblkwidth(), self.get_truewidth() + self.get_falsewidth())
|
|
||||||
|
|
||||||
def get_truewidth(self) -> float:
|
def get_truewidth(self) -> float:
|
||||||
w = 0.0
|
w = 200.0
|
||||||
|
|
||||||
for inst in self.true_case:
|
for inst in self.true_case:
|
||||||
w += inst.getblkwidth()
|
w = max(w, inst.getblkwidth())
|
||||||
|
|
||||||
return w
|
return w
|
||||||
|
|
||||||
def get_falsewidth(self) -> float:
|
def get_falsewidth(self) -> float:
|
||||||
w = 0.0
|
w = 200.0
|
||||||
|
|
||||||
if self.false_case:
|
if self.false_case:
|
||||||
for inst in self.false_case:
|
for inst in self.false_case:
|
||||||
w += inst.getblkwidth()
|
w = max(w, inst.getblkwidth())
|
||||||
|
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
def getblkheight(self) -> float:
|
||||||
|
return max(self.get_trueheight(), self.get_falseheight())
|
||||||
|
|
||||||
|
def getblkwidth(self) -> float:
|
||||||
|
return max(self._getblkwidth(), self.get_truewidth() + self.get_falsewidth())
|
||||||
|
|
||||||
|
|
||||||
def to_image(self, x:int, y:int, x_sz: int) -> Iterable[float]:
|
def to_image(self, x:int, y:int, x_sz: int) -> Iterable[float]:
|
||||||
true_w = self.get_truewidth()
|
true_w = self.get_truewidth()
|
||||||
false_w = self.get_falseheight()
|
false_w = self.get_falsewidth()
|
||||||
true_x, true_y, true_sz_x, _, false_x, false_y, false_sz_x, _ = cti.draw_if_statement(
|
true_x, true_y, _, _, false_x, false_y, _, _ = cti.draw_if_statement(
|
||||||
self.instruction_text, x, y, true_w, false_w, self.getblkheight()
|
self.instruction_text, x, y, true_w, false_w, self.getblkheight()
|
||||||
)
|
)
|
||||||
self.draw_true_case(true_x, true_y, true_sz_x)
|
self.draw_true_case(true_x, true_y, true_w)
|
||||||
self.draw_false_case(false_x, false_y, false_sz_x)
|
self.draw_false_case(false_x, false_y, false_w)
|
||||||
blk_size = self.getblkheight()
|
blk_size = self.getblkheight()
|
||||||
return x, y + blk_size
|
return x, y + blk_size
|
||||||
|
|
||||||
|
|||||||
@@ -54,30 +54,30 @@ def draw_generic_instruction(instruction: str, x, y, xsize, ysize) -> Iterable[f
|
|||||||
|
|
||||||
return x, y + ysize
|
return x, y + ysize
|
||||||
|
|
||||||
def draw_if_statement(condition: str, x: int, y: int, true_sz: int, false_sz: int, ysize: int):
|
def draw_if_statement(condition: str, x: int, y: int, true_w: int, false_w: int, ysize: int):
|
||||||
"""Draw an if statement into the NSD"""
|
"""Draw an if statement into the NSD"""
|
||||||
if not output_img:
|
if not output_img:
|
||||||
raise Exception("Output image was not initialized! Make sure to call NSD_init first")
|
raise Exception("Output image was not initialized! Make sure to call NSD_init first")
|
||||||
|
|
||||||
text_y_size = font.getsize(condition)[1]
|
text_h = font.getsize(condition)[1] + 5
|
||||||
|
|
||||||
box_sz = true_sz + false_sz
|
box_w = true_w + false_w
|
||||||
|
|
||||||
output_img.line((x,y) + (x + box_sz/2, y + text_y_size), fill=(0))
|
output_img.line((x,y) + (x + box_w/2, y + text_h), fill=(0))
|
||||||
output_img.line((x + box_sz, y) + (x + box_sz/2, y + text_y_size), fill=(0))
|
output_img.line((x + box_w, y) + (x + box_w/2, y + text_h), fill=(0))
|
||||||
output_img.rectangle((x, y + text_y_size) + (x + box_sz, y + ysize), outline=(0), width=1)
|
output_img.rectangle((x, y + text_h) + (x + box_w, y + ysize), outline=(0), width=1)
|
||||||
output_img.rectangle((x, y) + (x + box_sz, y + text_y_size), outline=(0), width=1)
|
output_img.rectangle((x, y) + (x + box_w, y + text_h), outline=(0), width=1)
|
||||||
output_img.line((x + true_sz, y + text_y_size) + (x + true_sz, y + ysize), fill=(0))
|
output_img.line((x + true_w, y + text_h) + (x + true_w, y + ysize), fill=(0))
|
||||||
|
|
||||||
# condition text
|
# condition text
|
||||||
output_img.multiline_text((x + box_sz / 2, y + text_y_size / 2), condition, fill=(0), font=font, anchor="mm", spacing=4, align='right')
|
output_img.multiline_text((x + box_w / 2, y + text_h / 2), condition, fill=(0), font=font, anchor="mm", spacing=4, align='right')
|
||||||
|
|
||||||
# true / false
|
# true / false
|
||||||
output_img.text((x + 5, y + text_y_size), "true", font = font, fill = (0), anchor="ld")
|
output_img.text((x + 5, y + text_h), "true", font = font, fill = (0), anchor="ld")
|
||||||
output_img.text((x + box_sz - 5, y + text_y_size), "false", font = font, fill = (0), anchor="rd")
|
output_img.text((x + box_w - 5, y + text_h), "false", font = font, fill = (0), anchor="rd")
|
||||||
|
|
||||||
#first x, y, xsize and ysize of "true" label then of "false" label
|
#x, and y of "true" and "false" label
|
||||||
return x, y + text_y_size, true_sz, ysize - text_y_size, x + true_sz, y + text_y_size, false_sz, ysize - text_y_size
|
return x, y + text_h, x + true_w, y + text_h
|
||||||
|
|
||||||
def draw_while_loop_front(condition: str, x: int, y: int, xsize: int, ysize: int):
|
def draw_while_loop_front(condition: str, x: int, y: int, xsize: int, ysize: int):
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class NassiShneidermanDiagram:
|
|||||||
def convert_to_image(self, output_path: str, on_conflict: Overwrite_behaviour=OB.SKIP) -> bool:
|
def convert_to_image(self, output_path: str, on_conflict: Overwrite_behaviour=OB.SKIP) -> bool:
|
||||||
i = 0
|
i = 0
|
||||||
for scope in self.function_scopes:
|
for scope in self.function_scopes:
|
||||||
cancel = one_line_progress_meter('Progress', i+1, len(self.function_scopes), '-PROGRESSBAR-')
|
cancel = one_line_progress_meter('Progress', i, len(self.function_scopes), '-PROGRESSBAR-')
|
||||||
if not cancel:
|
if not cancel:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class Function_scope(Iterable):
|
|||||||
return int(h)
|
return int(h)
|
||||||
|
|
||||||
def get_width(self) -> int:
|
def get_width(self) -> int:
|
||||||
w = 200.0
|
w = 200.0 #minimum width for every block
|
||||||
for inst in self.contents:
|
for inst in self.contents:
|
||||||
w = max(w, inst.getblkwidth())
|
w = max(w, inst.getblkwidth())
|
||||||
return int(w)
|
return int(w)
|
||||||
|
|||||||
11
run.py
11
run.py
@@ -1,10 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from gui.gui import Gui
|
from gui.gui import Gui as gui
|
||||||
import sys
|
from sys import argv
|
||||||
|
|
||||||
do_debug = "--debug" in sys.argv
|
|
||||||
|
|
||||||
Gui(theme='DarkGrey11', debug_mode=do_debug)
|
|
||||||
|
|
||||||
|
|
||||||
|
do_debug = "--debug" in argv
|
||||||
|
|
||||||
|
gui(theme='DarkGrey11', debug_mode=do_debug)
|
||||||
Reference in New Issue
Block a user