GuiShell.py 11 KB

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