GuiShell.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #!python3
  2. import sys
  3. import threading
  4. import time
  5. import os
  6. if sys.platform == 'linux':
  7. import readline
  8. import rlcompleter
  9. import traceback
  10. from PySide2.QtCore import QObject, QThread, Signal
  11. import gui
  12. # from GuiType import (_GuiForm,_GuiFormMulti,_GuiTreeRow,_GuiTree,_GuiWinText,
  13. # _GuiWinLinedText,_GuiWinForm,_GuiWinFormMulti,_GuiWinTree,_GuiSideBar,
  14. # _GuiMessage, _GuiMessages,)
  15. from GuiType import *
  16. class _GuiMain():
  17. Title = "NeoConstraint"
  18. WindowCount = 0
  19. History = []
  20. SideBar = None
  21. Messages = None
  22. TextFont = "Monospace"
  23. TextFontSize = 10
  24. SysFont = "FreeMono"
  25. SysFontSize = 9
  26. About = "NeoConstraint(R) 2023.03-Alpha\nChipara, Inc. Ltd" # Help-About
  27. Prompt = "nc_shell-t>" # Console-Shell
  28. def __init__(self):
  29. super().__init__()
  30. self.SideBar = _GuiSideBar(
  31. "Hierarchy", _GuiTree(["", "DFFs", "SubModules"], []))
  32. self.Messages = _GuiMessages([])
  33. def Start(self): # GUI Loop Entry, Please modify content
  34. # self.sig.emit('Start')
  35. return gui.signale('start')
  36. def Stop(self): # GUI Loop Exit, Please modify content
  37. # self.sig.emit('Stop')
  38. # return gui.StopGui()
  39. return gui.signale('stop')
  40. def Log_Print(self): # test: _GUI.Log_Print()
  41. print(1)
  42. time.sleep(1)
  43. print(2)
  44. time.sleep(1)
  45. return ""
  46. # test: _GUI.Shell_IsCmdFinished("print(1,")
  47. def Shell_IsCmdFinished(self, cmd):
  48. return cmd.count('(') == cmd.count(')') and cmd.count('"') % 2 == 0 and cmd.count("'") % 2 == 0
  49. def Shell_Execute(self, cmd):
  50. self.History.append(cmd)
  51. exec(cmd)
  52. print('demo> ', end='')
  53. def ViewGetDefault(self):
  54. # Read from disk, blah blah
  55. self.TextFont = "Monospace"
  56. self.TextFontSize = 10
  57. self.SysFont = "FreeMono"
  58. self.SysFontSize = 9
  59. def ViewSet(self, text_font_size, text_font, sys_font_size, sys_font):
  60. self.TextFont = text_font
  61. self.TextFontSize = text_font_size
  62. self.SysFont = sys_font
  63. self.SysFontSize = sys_font_size
  64. def ViewSetDefault(self, text_font_size, text_font, sys_font_size, sys_font):
  65. self.ViewSet(text_font_size, text_font, sys_font_size, sys_font)
  66. # write to disk, blahblah
  67. return
  68. def Analyze(self, type_paths):
  69. assert isinstance(type_paths, list)
  70. for tp in type_paths:
  71. assert tp[0] in ("Filelist", "Netlist", "V2001",
  72. "V2005", "SV2005", "SV2009", "SV2012", "SearchPath")
  73. assert isinstance(tp[1], str)
  74. print("Analyze:", tp[0], tp[1])
  75. time.sleep(0.1)
  76. print("Analyze Done")
  77. return
  78. def Elaborate(self, top, bbox):
  79. assert isinstance(top, str)
  80. assert isinstance(bbox, bool)
  81. if top == "":
  82. print("Elaborate: Auto Top, ", end='')
  83. else:
  84. print("Elaborate: Top is "+top+", ", end='')
  85. if bbox:
  86. print("Allow BlackBox")
  87. else:
  88. print("Do Not Allow BlackBox")
  89. time.sleep(1)
  90. self.Title = "NeoConstraint - "+top
  91. # self.SideBar = _GuiSideBar("Hierarchy", _GuiTree(["", "DFFs", "SubModules"], [_GuiTreeRow([_GuiTreeRow([], "SubDesign1", [
  92. # "12", "0"]), _GuiTreeRow([_GuiTreeRow([], "Sub3", ["5", "0"])], "SubDesign2", ["34", "1"])], "DemoDesign", ["123", "2"]),]))
  93. self.SideBar = _GuiSideBar("Hierarchy", _GuiTree(["", "DFFs", "SubModules"], [_GuiTreeRow([
  94. _GuiTreeRow([_GuiTreeRow([], "SubRow1", ["1","2"]),], "SubTreeRow1",["1","2"]),
  95. _GuiTreeRow([ ], "SubRow2", ["1","2"]),
  96. ], "DemoDesign", ["123", "2"]),]))
  97. print("Elaborate Done")
  98. return gui.signale(self.SideBar)
  99. def ReadTimingConstraint(self, filename):
  100. assert isinstance(filename, str)
  101. print("Reading Timing Constraint: "+filename)
  102. time.sleep(1)
  103. print("Read Timing Constraint Done")
  104. return
  105. def ReportExceptions(self, mcp, fp, mdp, limit):
  106. assert isinstance(mcp, bool)
  107. assert isinstance(fp, bool)
  108. assert isinstance(mdp, bool)
  109. assert isinstance(limit, int)
  110. print("Reporting Exception: ", end='')
  111. if mcp:
  112. print("MultiCycle Path, ", end='')
  113. if fp:
  114. print("False Path, ", end='')
  115. if mdp:
  116. print("Max Delay Path, ", end='')
  117. if limit > 0:
  118. print("Path Limit", limit)
  119. else:
  120. print("No Path Limit")
  121. time.sleep(1)
  122. print("Report Exception Done")
  123. self.WindowCount += 1
  124. title = "Report "+str(self.WindowCount)
  125. fixed_row = ["Startpoint", "Endpoint", "Virtual Slack"]
  126. form_mcp = _GuiForm(fixed_row, [["a1", "a2", "0.1"]])
  127. form_fp = _GuiForm(
  128. fixed_row, [["b1", "b2", "0.2"], ["c1", "c2", "0.3"]])
  129. form_mdp = _GuiForm(fixed_row, [["d1", "d2", "0.4"], [
  130. "e1", "e2", "0.5"], ["f1", "f2", "0.6"]])
  131. forms = _GuiFormMulti(
  132. [["MCP", form_mcp], ["FP", form_fp], ["MDP", form_mdp]])
  133. # return _GuiWinFormMulti(title, forms)
  134. print("Names:", forms.Names)
  135. return gui.signale(_GuiWinFormMulti(title, forms))
  136. def ReportClocks(self, start, end, exclude, autogen, include_async):
  137. assert isinstance(start, str)
  138. assert isinstance(end, str)
  139. assert isinstance(exclude, str)
  140. assert isinstance(autogen, bool)
  141. assert isinstance(include_async, bool)
  142. print("Reporting Clocks: Startpoints",
  143. start, "Endpoints", end, end='')
  144. if exclude:
  145. print("Exclude", exclude, end='')
  146. if autogen:
  147. print(", Auto Include Generated Clocks", end='')
  148. if include_async:
  149. print(", Include Async Clocks", end='')
  150. print()
  151. time.sleep(1)
  152. print("Report Clocks Done")
  153. self.WindowCount += 1
  154. title = "Report "+str(self.WindowCount)
  155. fixed_row = ["Startpoint Clock", "Startpoint",
  156. "Endpoint Clock", "Endpoint", "Type"]
  157. rows = [["CLKA", "DFFA/Q", "CLKB", "DFFB/D", "Sync"],
  158. ["CLKB", "DFFB/Q", "CLKA", "DFFA/D", "Async"]]
  159. form = _GuiForm(fixed_row, rows)
  160. return _GuiWinForm(title, form)
  161. def ReportVirtualTiming(self, from_type, from_, thru_type, thru, to_type, to, flat, limit):
  162. assert from_type in ("", "Clocks", "Pins", "Registers")
  163. assert thru_type in ("", "Pins")
  164. assert to_type in ("", "Clocks", "Pins", "Registers")
  165. assert isinstance(from_, str)
  166. assert isinstance(thru, str)
  167. assert isinstance(to, str)
  168. assert isinstance(flat, bool)
  169. assert isinstance(limit, int)
  170. print("Reporting Virtual Timing: From", from_type, from_,
  171. "Through", thru_type, thru, "To", to_type, to, end='')
  172. if flat:
  173. print(", Enabled Flat Search, ", end='')
  174. else:
  175. print(", Disabled Flat Search, ", end='')
  176. if limit > 0:
  177. print("Path Limit", limit)
  178. else:
  179. print("No Path Limit")
  180. time.sleep(1)
  181. print("Report Virtual Timing Done")
  182. self.WindowCount += 1
  183. title = "Report "+str(self.WindowCount)
  184. text = "Virtual Timing:\nFrom "+from_type+" "+from_ + \
  185. "\nThrough "+thru_type+" "+thru+"\nTo "+to_type+" "+to
  186. return _GuiWinText(title, text)
  187. def lineEdit_input(self, dat):
  188. # sys.stdout.stdout_bak.write(dat)
  189. print('input:', dat)
  190. # input(self.lineEdit.text()+'\n')
  191. # sys.stdout.stdout_bak.flush()
  192. def run(self):
  193. self.Elaborate("top", True)
  194. shell_loop()
  195. def Exit(self): # File - Exit
  196. os._exit(0)
  197. def GetHistory(self): # Console - History
  198. return ["first cmd", "last cmd"]
  199. def GetErrors(self): # Console - Message
  200. 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")]]])
  201. def GetCriticalWarnings(self): # Console - Message
  202. return _GuiMessages([])
  203. def GetWarnings(self): # Console - Message
  204. 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")]]])
  205. def GetInfos(self): # Console - Message
  206. 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"),]]])
  207. # _GUI.Analyze([["SearchPath", "../.."],["SV2009", "file.sv"]])
  208. # _GUI.Elaborate("DemoDesign", True)
  209. # _GUI.ReportExceptions(True, True, False, 10)
  210. # _GUI.ReportClocks("CLK*", "CLK*", "", True, False)
  211. # _GUI.ReportVirtualTiming("Clocks", "CLK", "Pins", "DFF/Q", "Registers", "DFF2", False, 2)
  212. _GUI = _GuiMain()
  213. ###################
  214. # Shell Loop
  215. ###################
  216. def shell_loop():
  217. if sys.platform == 'linux':
  218. # -------------------------- Shell Completer -------------------------
  219. default_completer = readline.get_completer()
  220. def completer(text, state):
  221. return default_completer(text, state)
  222. if 'libedit' in readline.__doc__:
  223. readline.parse_and_bind("bind -e")
  224. readline.parse_and_bind("bind '\t' rl_complete")
  225. else:
  226. readline.parse_and_bind('tab: complete')
  227. readline.set_completer(completer)
  228. readline.set_completer_delims('')
  229. # ---------------------------- Shell Loop ---------------------------
  230. print('\n'+' '*20+'GuiDemo\n'+' '*21 +
  231. 'V 1.1\n'+' '*14+'Copyright (c) 2022 \n')
  232. pre_exit = False
  233. stdin = ''
  234. try:
  235. while 1:
  236. try:
  237. print('demo> ', end='')
  238. stdin = input()
  239. pre_exit = False
  240. except KeyboardInterrupt:
  241. if pre_exit:
  242. os._exit(0)
  243. else:
  244. print('\n one more ctrl-c to exit')
  245. pre_exit = True
  246. except EOFError:
  247. os._exit()
  248. if stdin != '' and not pre_exit:
  249. try:
  250. # -------------- multi line --------------
  251. stdin_next = ''
  252. while stdin.endswith(':') or stdin.endswith('\\') or stdin_next.startswith(' ') or stdin_next.startswith('\t'):
  253. stdin_next = input('... ')
  254. stdin += '\n'+stdin_next
  255. # --------------- def call ---------------
  256. if stdin.endswith('('):
  257. stdout = eval(miao+')')
  258. else:
  259. try:
  260. if stdin.endswith(')'):
  261. stdout = eval(stdin)
  262. else:
  263. stdout = eval(stdin+'()')
  264. except (SyntaxError, TypeError):
  265. if stdin.endswith(')'):
  266. exec(stdin)
  267. stdout = ''
  268. else:
  269. try:
  270. stdout = eval(stdin)
  271. except (SyntaxError, TypeError):
  272. exec(stdin)
  273. stdout = ''
  274. # --------------- printer ----------------
  275. if stdout != '':
  276. if isinstance(stdout, set) and len(stdout) < 1000:
  277. print(sorted(list(stdout)))
  278. else:
  279. print('', stdout)
  280. except KeyboardInterrupt:
  281. print('\n\n ctrl-c interrupt:', miao, '\n')
  282. except NameError as e:
  283. if os.system(stdin):
  284. print(' NameError:{}'.format(e))
  285. except Exception:
  286. traceback.print_exc()
  287. finally:
  288. gui.exit()
  289. print('\n\n thank you for gui development !\n')
  290. if __name__ == '__main__':
  291. # _GUI.Start()
  292. # _GUI.Stop()
  293. # _GUI.Log_Print()
  294. t = gui.run_in_thread(_GUI)
  295. _GUI.run()