#!python3 import sys import threading import time import os if sys.platform == 'linux': import readline import rlcompleter import traceback from PySide2.QtCore import QObject, QThread, Signal import gui from GuiType import * class _GuiMain(): Title = "NeoConstraint" WindowCount = 0 History = [] SideBar = None Messages = None TextFont = "Monospace" TextFontSize = 13 SysFont = "FreeMono" SysFontSize = 15 About = "NeoConstraint(R) 2023.03-Alpha\nChipara, Inc. Ltd" # Help-About Prompt = "nc_shell-t>" # Console-Shell def __init__(self): super().__init__() self.SideBar = _GuiSideBar( "Hierarchy", _GuiTree(["", "DFFs", "SubModules"], [])) self.Messages = _GuiMessages([]) def Start(self): # GUI Loop Entry, Please modify content return gui.signale('start') def Stop(self): # GUI Loop Exit, Please modify content # self.sig.emit('Stop') # return gui.StopGui() return gui.signale('stop') def Log_Print(self): # test: _GUI.Log_Print() gui.signale("Busy") print(1) time.sleep(1) print(2) time.sleep(1) gui.signale("Ready") return "" # test: _GUI.Shell_IsCmdFinished("print(1,") def Shell_IsCmdFinished(self, cmd): return cmd.count('(') == cmd.count(')') and cmd.count('"') % 2 == 0 and cmd.count("'") % 2 == 0 def Shell_Execute(self, cmd): self.History.append(cmd) exec(cmd) print('demo> ', end='') def ViewGetDefault(self): # Read from disk, blah blah self.TextFont = "Monospace" self.TextFontSize = 10 self.SysFont = "FreeMono" self.SysFontSize = 9 def ViewSet(self, text_font_size, text_font, sys_font_size, sys_font): self.TextFont = text_font self.TextFontSize = text_font_size self.SysFont = sys_font self.SysFontSize = sys_font_size def ViewSetDefault(self, text_font_size, text_font, sys_font_size, sys_font): self.ViewSet(text_font_size, text_font, sys_font_size, sys_font) # write to disk, blahblah return def Analyze(self, type_paths): assert isinstance(type_paths, list) gui.signale("Busy") for tp in type_paths: assert tp[0] in ("Filelist", "Netlist", "V2001", "V2005", "SV2005", "SV2009", "SV2012", "SearchPath") assert isinstance(tp[1], str) print("Analyze:", tp[0], tp[1]) time.sleep(0.1) print("Analyze Done") gui.signale("Ready") return def Elaborate(self, top, bbox): assert isinstance(top, str) assert isinstance(bbox, bool) gui.signale("Busy") if top == "": print("Elaborate: Auto Top, ", end='') else: print("Elaborate: Top is "+top+", ", end='') if bbox: print("Allow BlackBox") else: print("Do Not Allow BlackBox") time.sleep(1) self.Title = "NeoConstraint - "+top # self.SideBar = _GuiSideBar("Hierarchy", _GuiTree(["", "DFFs", "SubModules"], [_GuiTreeRow([_GuiTreeRow([], "SubDesign1", [ # "12", "0"]), _GuiTreeRow([_GuiTreeRow([], "Sub3", ["5", "0"])], "SubDesign2", ["34", "1"])], "DemoDesign", ["123", "2"]),])) self.SideBar = _GuiSideBar("Hierarchy", _GuiTree(["", "DFFs", "SubModules"], [_GuiTreeRow([ _GuiTreeRow([_GuiTreeRow([], "SubRow1", ["1","2"]),], "SubTreeRow1",["1","2"]), _GuiTreeRow([ ], "SubRow2", ["1","2"]), ], "DemoDesign", ["123", "2"]),])) print("Elaborate Done") gui.signale("Ready") return gui.signale(self.SideBar) def ReloadDesign(self): gui.signale("Busy") time.sleep(1) print("Reload Design Done") gui.signale("Ready") return def ReadTimingConstraint(self, filename): assert isinstance(filename, str) print("Reading Timing Constraint: "+filename) gui.signale("Busy") time.sleep(1) print("Read Timing Constraint Done") gui.signale("Ready") return def ReportExceptions(self, mcp, fp, mdp, limit): assert isinstance(mcp, bool) assert isinstance(fp, bool) assert isinstance(mdp, bool) assert isinstance(limit, int) gui.signale("Busy") print("Reporting Exception: ", end='') if mcp: print("MultiCycle Path, ", end='') if fp: print("False Path, ", end='') if mdp: print("Max Delay Path, ", end='') if limit > 0: print("Path Limit", limit) else: print("No Path Limit") time.sleep(1) print("Report Exception Done") self.WindowCount += 1 title = "Report "+str(self.WindowCount) fixed_row = ["Startpoint", "Endpoint", "Virtual Slack"] form_mcp = _GuiForm(fixed_row, [["a1", "a2", "0.1"]]) form_fp = _GuiForm( fixed_row, [["b1", "b2", "0.2"], ["c1", "c2", "0.3"]]) form_mdp = _GuiForm(fixed_row, [["d1", "d2", "0.4"], [ "e1", "e2", "0.5"], ["f1", "f2", "0.6"]]) forms = _GuiFormMulti( [["MCP", form_mcp], ["FP", form_fp], ["MDP", form_mdp]]) print("Names:", forms.Names) gui.signale("Ready") return gui.signale(_GuiWinFormMulti(title, forms, "Timing")) def ReportClocks(self, start, end, exclude, autogen, include_async): assert isinstance(start, str) assert isinstance(end, str) assert isinstance(exclude, str) assert isinstance(autogen, bool) assert isinstance(include_async, bool) gui.signale("Busy") print("Reporting Clocks: Startpoints", start, "Endpoints", end, end='') if exclude: print("Exclude", exclude, end='') if autogen: print(", Auto Include Generated Clocks", end='') if include_async: print(", Include Async Clocks", end='') print() time.sleep(1) print("Report Clocks Done") gui.signale("Ready") self.WindowCount += 1 title = "Report "+str(self.WindowCount) fixed_row = ["Startpoint Clock", "Startpoint", "Endpoint Clock", "Endpoint", "Type"] rows = [["CLKA", "DFFA/Q", "CLKB", "DFFB/D", "Sync"], ["CLKB", "DFFB/Q", "CLKA", "DFFA/D", "Async"]] form = _GuiForm(fixed_row, rows) return gui.signale(_GuiWinForm(title, form, "Clock")) def ReportVirtualTiming(self, from_type, from_, thru_type, thru, to_type, to, flat, limit): assert from_type in ("", "Clocks", "Pins", "Registers") assert thru_type in ("", "Pins") assert to_type in ("", "Clocks", "Pins", "Registers") assert isinstance(from_, str) assert isinstance(thru, str) assert isinstance(to, str) assert isinstance(flat, bool) assert isinstance(limit, int) gui.signale("Busy") print("Reporting Virtual Timing: From", from_type, from_, "Through", thru_type, thru, "To", to_type, to, end='') if flat: print(", Enabled Flat Search, ", end='') else: print(", Disabled Flat Search, ", end='') if limit > 0: print("Path Limit", limit) else: print("No Path Limit") time.sleep(1) print("Report Virtual Timing Done") gui.signale("Ready") self.WindowCount += 1 title = "Report "+str(self.WindowCount) text = "Virtual Timing:\nFrom "+from_type+" "+from_ + \ "\nThrough "+thru_type+" "+thru+"\nTo "+to_type+" "+to return gui.signale(_GuiWinText(title, text)) def lineEdit_input(self, dat): # sys.stdout.stdout_bak.write(dat) print('input:', dat) # input(self.lineEdit.text()+'\n') # sys.stdout.stdout_bak.flush() def run(self): shell_loop() def Exit(self): # File - Exit os._exit(0) def GetHistory(self): # Console - History return ["first cmd", "last cmd"] def GetErrors(self): # Console - Message return _GuiMessages([["Err-123","This is an error",[_GuiMessage("This is an error!", 100, "/x/x.v"),_GuiMessage("This is an error!!", 200, "/xx/xx.v")]]]) def GetCriticalWarnings(self): # Console - Message return _GuiMessages([]) def GetWarnings(self): # Console - Message return _GuiMessages([["Warn-234","This is a warning",[_GuiMessage("This is a warning!", 100, "/x/x.v"),_GuiMessage("This is a warning!!", 200, "/xx/xx.v")]]]) def GetInfos(self): # Console - Message return _GuiMessages([["Info-345","This is an info",[_GuiMessage("This is an info!", 100, "/x/x.v"),]],["Info-456","This is another info",[_GuiMessage("This is another info!", 200, "/xx/xx.v"),]]]) # _GUI.Analyze([["SearchPath", "../.."],["SV2009", "file.sv"]]) # _GUI.Elaborate("DemoDesign", True) # _GUI.ReportExceptions(True, True, False, 10) # _GUI.ReportClocks("CLK*", "CLK*", "", True, False) # _GUI.ReportVirtualTiming("Clocks", "CLK", "Pins", "DFF/Q", "Registers", "DFF2", False, 2) _GUI = _GuiMain() ################### # Shell Loop ################### def shell_loop(): if sys.platform == 'linux': # -------------------------- Shell Completer ------------------------- default_completer = readline.get_completer() def completer(text, state): return default_completer(text, state) if 'libedit' in readline.__doc__: readline.parse_and_bind("bind -e") readline.parse_and_bind("bind '\t' rl_complete") else: readline.parse_and_bind('tab: complete') readline.set_completer(completer) readline.set_completer_delims('') # ---------------------------- Shell Loop --------------------------- print('\n'+' '*20+'GuiDemo\n'+' '*21 + 'V 1.1\n'+' '*14+'Copyright (c) 2022 \n') pre_exit = False stdin = '' try: while 1: try: print('demo> ', end='') stdin = input() pre_exit = False except KeyboardInterrupt: if pre_exit: os._exit(0) else: print('\n one more ctrl-c to exit') pre_exit = True except EOFError: os._exit() if stdin != '' and not pre_exit: try: # -------------- multi line -------------- stdin_next = '' while stdin.endswith(':') or stdin.endswith('\\') or stdin_next.startswith(' ') or stdin_next.startswith('\t'): stdin_next = input('... ') stdin += '\n'+stdin_next # --------------- def call --------------- if stdin.endswith('('): stdout = eval(miao+')') else: try: if stdin.endswith(')'): stdout = eval(stdin) else: stdout = eval(stdin+'()') except (SyntaxError, TypeError): if stdin.endswith(')'): exec(stdin) stdout = '' else: try: stdout = eval(stdin) except (SyntaxError, TypeError): exec(stdin) stdout = '' # --------------- printer ---------------- if stdout != '': if isinstance(stdout, set) and len(stdout) < 1000: print(sorted(list(stdout))) else: print('', stdout) except KeyboardInterrupt: print('\n\n ctrl-c interrupt:', miao, '\n') except NameError as e: if os.system(stdin): print(' NameError:{}'.format(e)) except Exception: traceback.print_exc() finally: gui.exit() print('\n\n thank you for gui development !\n') if __name__ == '__main__': # _GUI.Start() # _GUI.Stop() # _GUI.Log_Print() t = gui.run_in_thread(_GUI) _GUI.run()