GuiShell.py 11 KB

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