GuiShell.py 13 KB

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