GuiShell.py 13 KB

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