GuiShell.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 ReloadDesign(self):
  100. time.sleep(1)
  101. print("Reload Design Done")
  102. return
  103. def ReadTimingConstraint(self, filename):
  104. assert isinstance(filename, str)
  105. print("Reading Timing Constraint: "+filename)
  106. time.sleep(1)
  107. print("Read Timing Constraint Done")
  108. return
  109. def ReportExceptions(self, mcp, fp, mdp, limit):
  110. assert isinstance(mcp, bool)
  111. assert isinstance(fp, bool)
  112. assert isinstance(mdp, bool)
  113. assert isinstance(limit, int)
  114. print("Reporting Exception: ", end='')
  115. if mcp:
  116. print("MultiCycle Path, ", end='')
  117. if fp:
  118. print("False Path, ", end='')
  119. if mdp:
  120. print("Max Delay Path, ", end='')
  121. if limit > 0:
  122. print("Path Limit", limit)
  123. else:
  124. print("No Path Limit")
  125. time.sleep(1)
  126. print("Report Exception Done")
  127. self.WindowCount += 1
  128. title = "Report "+str(self.WindowCount)
  129. fixed_row = ["Startpoint", "Endpoint", "Virtual Slack"]
  130. form_mcp = _GuiForm(fixed_row, [["a1", "a2", "0.1"]])
  131. form_fp = _GuiForm(
  132. fixed_row, [["b1", "b2", "0.2"], ["c1", "c2", "0.3"]])
  133. form_mdp = _GuiForm(fixed_row, [["d1", "d2", "0.4"], [
  134. "e1", "e2", "0.5"], ["f1", "f2", "0.6"]])
  135. forms = _GuiFormMulti(
  136. [["MCP", form_mcp], ["FP", form_fp], ["MDP", form_mdp]])
  137. # return _GuiWinFormMulti(title, forms)
  138. print("Names:", forms.Names)
  139. return gui.signale(_GuiWinFormMulti(title, forms))
  140. def ReportClocks(self, start, end, exclude, autogen, include_async):
  141. assert isinstance(start, str)
  142. assert isinstance(end, str)
  143. assert isinstance(exclude, str)
  144. assert isinstance(autogen, bool)
  145. assert isinstance(include_async, bool)
  146. print("Reporting Clocks: Startpoints",
  147. start, "Endpoints", end, end='')
  148. if exclude:
  149. print("Exclude", exclude, end='')
  150. if autogen:
  151. print(", Auto Include Generated Clocks", end='')
  152. if include_async:
  153. print(", Include Async Clocks", end='')
  154. print()
  155. time.sleep(1)
  156. print("Report Clocks Done")
  157. self.WindowCount += 1
  158. title = "Report "+str(self.WindowCount)
  159. fixed_row = ["Startpoint Clock", "Startpoint",
  160. "Endpoint Clock", "Endpoint", "Type"]
  161. rows = [["CLKA", "DFFA/Q", "CLKB", "DFFB/D", "Sync"],
  162. ["CLKB", "DFFB/Q", "CLKA", "DFFA/D", "Async"]]
  163. form = _GuiForm(fixed_row, rows)
  164. return _GuiWinForm(title, form)
  165. def ReportVirtualTiming(self, from_type, from_, thru_type, thru, to_type, to, flat, limit):
  166. assert from_type in ("", "Clocks", "Pins", "Registers")
  167. assert thru_type in ("", "Pins")
  168. assert to_type in ("", "Clocks", "Pins", "Registers")
  169. assert isinstance(from_, str)
  170. assert isinstance(thru, str)
  171. assert isinstance(to, str)
  172. assert isinstance(flat, bool)
  173. assert isinstance(limit, int)
  174. print("Reporting Virtual Timing: From", from_type, from_,
  175. "Through", thru_type, thru, "To", to_type, to, end='')
  176. if flat:
  177. print(", Enabled Flat Search, ", end='')
  178. else:
  179. print(", Disabled Flat Search, ", end='')
  180. if limit > 0:
  181. print("Path Limit", limit)
  182. else:
  183. print("No Path Limit")
  184. time.sleep(1)
  185. print("Report Virtual Timing Done")
  186. self.WindowCount += 1
  187. title = "Report "+str(self.WindowCount)
  188. text = "Virtual Timing:\nFrom "+from_type+" "+from_ + \
  189. "\nThrough "+thru_type+" "+thru+"\nTo "+to_type+" "+to
  190. return _GuiWinText(title, text)
  191. def lineEdit_input(self, dat):
  192. # sys.stdout.stdout_bak.write(dat)
  193. print('input:', dat)
  194. # input(self.lineEdit.text()+'\n')
  195. # sys.stdout.stdout_bak.flush()
  196. def run(self):
  197. self.Elaborate("top", True)
  198. shell_loop()
  199. def Exit(self): # File - Exit
  200. os._exit(0)
  201. def GetHistory(self): # Console - History
  202. return ["first cmd", "last cmd"]
  203. def GetErrors(self): # Console - Message
  204. 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")]]])
  205. def GetCriticalWarnings(self): # Console - Message
  206. return _GuiMessages([])
  207. def GetWarnings(self): # Console - Message
  208. 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")]]])
  209. def GetInfos(self): # Console - Message
  210. 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"),]]])
  211. # _GUI.Analyze([["SearchPath", "../.."],["SV2009", "file.sv"]])
  212. # _GUI.Elaborate("DemoDesign", True)
  213. # _GUI.ReportExceptions(True, True, False, 10)
  214. # _GUI.ReportClocks("CLK*", "CLK*", "", True, False)
  215. # _GUI.ReportVirtualTiming("Clocks", "CLK", "Pins", "DFF/Q", "Registers", "DFF2", False, 2)
  216. _GUI = _GuiMain()
  217. ###################
  218. # Shell Loop
  219. ###################
  220. def shell_loop():
  221. if sys.platform == 'linux':
  222. # -------------------------- Shell Completer -------------------------
  223. default_completer = readline.get_completer()
  224. def completer(text, state):
  225. return default_completer(text, state)
  226. if 'libedit' in readline.__doc__:
  227. readline.parse_and_bind("bind -e")
  228. readline.parse_and_bind("bind '\t' rl_complete")
  229. else:
  230. readline.parse_and_bind('tab: complete')
  231. readline.set_completer(completer)
  232. readline.set_completer_delims('')
  233. # ---------------------------- Shell Loop ---------------------------
  234. print('\n'+' '*20+'GuiDemo\n'+' '*21 +
  235. 'V 1.1\n'+' '*14+'Copyright (c) 2022 \n')
  236. pre_exit = False
  237. stdin = ''
  238. try:
  239. while 1:
  240. try:
  241. print('demo> ', end='')
  242. stdin = input()
  243. pre_exit = False
  244. except KeyboardInterrupt:
  245. if pre_exit:
  246. os._exit(0)
  247. else:
  248. print('\n one more ctrl-c to exit')
  249. pre_exit = True
  250. except EOFError:
  251. os._exit()
  252. if stdin != '' and not pre_exit:
  253. try:
  254. # -------------- multi line --------------
  255. stdin_next = ''
  256. while stdin.endswith(':') or stdin.endswith('\\') or stdin_next.startswith(' ') or stdin_next.startswith('\t'):
  257. stdin_next = input('... ')
  258. stdin += '\n'+stdin_next
  259. # --------------- def call ---------------
  260. if stdin.endswith('('):
  261. stdout = eval(miao+')')
  262. else:
  263. try:
  264. if stdin.endswith(')'):
  265. stdout = eval(stdin)
  266. else:
  267. stdout = eval(stdin+'()')
  268. except (SyntaxError, TypeError):
  269. if stdin.endswith(')'):
  270. exec(stdin)
  271. stdout = ''
  272. else:
  273. try:
  274. stdout = eval(stdin)
  275. except (SyntaxError, TypeError):
  276. exec(stdin)
  277. stdout = ''
  278. # --------------- printer ----------------
  279. if stdout != '':
  280. if isinstance(stdout, set) and len(stdout) < 1000:
  281. print(sorted(list(stdout)))
  282. else:
  283. print('', stdout)
  284. except KeyboardInterrupt:
  285. print('\n\n ctrl-c interrupt:', miao, '\n')
  286. except NameError as e:
  287. if os.system(stdin):
  288. print(' NameError:{}'.format(e))
  289. except Exception:
  290. traceback.print_exc()
  291. finally:
  292. gui.exit()
  293. print('\n\n thank you for gui development !\n')
  294. if __name__ == '__main__':
  295. # _GUI.Start()
  296. # _GUI.Stop()
  297. # _GUI.Log_Print()
  298. t = gui.run_in_thread(_GUI)
  299. _GUI.run()