GuiType.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. ###################
  2. # Gui Data Types
  3. ###################
  4. # from GuiType import (_GuiForm,_GuiFormMulti,_GuiTreeRow,_GuiTree,_GuiWinText,
  5. # _GuiWinLinedText,_GuiWinForm,_GuiWinFormMulti,_GuiWinTree,_GuiSideBar,
  6. # _GuiMessage, _GuiMessages,)
  7. __all__ = ["_GuiForm","_GuiFormMulti","_GuiTreeRow","_GuiTree","_GuiWinText",
  8. "_GuiWinLinedText","_GuiWinForm","_GuiWinFormMulti","_GuiWinTree","_GuiSideBar",
  9. "_GuiMessage", "_GuiMessages",]
  10. class _GuiForm():
  11. def __init__(self, fixed_row, rows):
  12. self.FixedRow = fixed_row
  13. self.Rows = rows
  14. # Form = _GuiForm( ["Col1", "Col2"], [["a1","a2"],["b1","b2"],["c1","c2"]])
  15. class _GuiFormMulti():
  16. def __init__(self, name_forms):
  17. self.Names = []
  18. self.__Forms = []
  19. for nf in name_forms:
  20. self.Names.append(nf[0])
  21. self.__Forms.append(nf[1])
  22. def GetForm(self, index): # can be further modify to lazy eval
  23. return self.__Forms[index]
  24. # Forms = _GuiFormMulti([["Sheet1", _GuiForm( ["Col1", "Col2"], [["a1","a2"],["b1","b2"],["c1","c2"]])], ["Sheet2", _GuiForm( ["Col1", "Col2"], [["d1","d2"],["e1","e2"],["f1","f2"]])]])
  25. class _GuiTreeRow():
  26. def __init__(self, treerows, name, row):
  27. self.Name = name
  28. self.Row = row
  29. if treerows:
  30. self.HasSubTreeRows = True
  31. self.__SubTreeRows = treerows
  32. else:
  33. self.HasSubTreeRows = False
  34. self.__SubTreeRows = []
  35. def GetSubTreeRows(self):
  36. return self.__SubTreeRows
  37. def GetID(self):
  38. pass
  39. # TreeRow = _GuiTreeRow([], "SubDesign1", ["12", "0"])
  40. # TreeRow = _GuiTreeRow([_GuiTreeRow([], "Sub3", ["5", "0"])], "SubDesign2", ["34", "1"])
  41. class _GuiTree():
  42. def __init__(self, fixed_row, treerows:_GuiTreeRow):
  43. self.FixedRow = fixed_row
  44. self.TreeRows = treerows
  45. # Tree = _GuiTree(["","DFFs","SubModules"], [_GuiTreeRow([_GuiTreeRow([], "SubDesign1", ["12", "0"]),_GuiTreeRow([_GuiTreeRow([], "Sub3", ["5", "0"])], "SubDesign2", ["34", "1"])], "DemoDesign", ["123", "2"]),])
  46. #####################
  47. # Gui Window Types
  48. #####################
  49. class _GuiWinText():
  50. def __init__(self, title, text):
  51. self.Title = title
  52. self.Text = text
  53. class _GuiWinLinedText():
  54. def __init__(self, title, lined_text, line):
  55. self.Title = title
  56. self.LinedText = lined_text
  57. self.GotoLine = line
  58. class _GuiWinForm():
  59. def __init__(self, title, form):
  60. self.Title = title
  61. self.Form = form
  62. class _GuiWinFormMulti():
  63. def __init__(self, title, forms):
  64. self.Title = title
  65. self.Forms = forms
  66. class _GuiWinTree():
  67. def __init__(self, tree):
  68. self.Title = ""
  69. self.Tree = tree
  70. class _GuiSideBar():
  71. def __init__(self, title, tree:_GuiTree):
  72. self.Title = title
  73. self.Tree = tree
  74. def GetForms(self, treenames):
  75. return _GuiFormMulti([["Sheet1", _GuiForm(["Col1", "Col2"], [[treename, "ok"] for treename in treenames])], ["Sheet2", _GuiForm(["Col1", "Col2"], [[treename, "fail"] for treename in treenames])]])
  76. def CrossProbe(self, treenames, formname, formrow):
  77. assert isinstance(treenames, list)
  78. assert isinstance(formname, str) or isinstance(formname, type(None))
  79. assert isinstance(formrow, list)
  80. line = 1000
  81. return _GuiWinLinedText(str(formrow), ("Text Start\n\n"+'\n'.join(['generated line '+str(x) for x in range(3, line*2)])+'\n'.join([str(x) for x in treenames])+str(formname)+"\n\nText End").split("\n"), line)
  82. def Properties(self, treenames, formname, formrow):
  83. assert isinstance(treenames, list)
  84. assert isinstance(formname, (str, type(None)))
  85. assert isinstance(formrow, list)
  86. return _GuiWinForm(str(formname)+" Properties", _GuiForm(["Name", "Property"], [[x, "property"] for x in treenames+formrow]))
  87. class _GuiMessage(): # _GuiMessage("This is an error!!!", 100, "/x/xx.v")
  88. def __init__(self, text, line, filepath):
  89. self.Text = text
  90. self.Line = line
  91. self.FilePath = filepath
  92. def GetHint(self):
  93. return "line: "+str(self.Line)+", file: "+self.FilePath
  94. def CrossProbe(self):
  95. return _GuiWinLinedText(self.FilePath, ("Text Start\n\n"+'\n'.join(['generated line '+str(x) for x in range(3, self.Line*2)])+"\n\nText End").split("\n"), self.Line)
  96. def Properties(self):
  97. return _GuiWinForm("Message Properties", _GuiForm(["Name", "Property"], [["File", self.FilePath], ["Line", str(self.Line)]]))
  98. class _GuiMessages(): # _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")]]])
  99. def __init__(self, id_messages):
  100. self.Size = 0
  101. self._summary = []
  102. self._messages = {}
  103. for idm in id_messages:
  104. assert len(idm) == 3
  105. assert isinstance(idm[0], str) and idm[0] != "" # "Err-123"
  106. assert isinstance(idm[1], str) # "This is an error"
  107. assert isinstance(idm[2], list) and len(idm[2]) > 0 # [_GuiMessage(), _GuiMessage()]
  108. self.Size += len(idm[2])
  109. self._summary.append([idm[0], len(idm[2]), idm[1]])
  110. self._messages[idm[0]] = idm[2]
  111. def GetSummary(self): # [["Err-123", 2, "This is an error"],]
  112. return self._summary
  113. def GetMsgByID(self, ID): # [_GuiMessage(), _GuiMessage()]
  114. return self._messages[ID]