GuiShell.py 13 KB

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