pyipcore 0.4.5__tar.gz → 0.4.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyipcore
3
- Version: 0.4.5
3
+ Version: 0.4.8
4
4
  Summary: (PyQt5 based) Create "Ipcore" from verilog(Need iverilog). Provide "Param Value" and "Port Control" function. This kind of IpCore is not safe, only for convenience
5
5
  Author-email: 2229066748@qq.com
6
6
  Maintainer: Eagle'sBaby
@@ -0,0 +1,6 @@
1
+ from pyipcore.main import pyipc
2
+ from pyipcore.ipcore import IpCore
3
+
4
+
5
+ def cmd_pyipc():
6
+ pyipc()
@@ -20,7 +20,7 @@ IPC_VAL_GS = [
20
20
  "//+\s*\$", # 0 "// $"
21
21
  FT.VARIABLE, # 1 "a"
22
22
  "\s*=\s*", # 2 " = "
23
- ".+", # 3 "1"
23
+ "[^;/\s]+", # 3 "1"
24
24
  ]
25
25
  IPC_VAL_KVID = (1, 3) # (key, value) index in IPC_VAL_GS
26
26
 
@@ -36,13 +36,63 @@ class IpCore:
36
36
 
37
37
  VERILOG_NUMBER = f"({FT.DIGIT_CHAR}+'{FT.ALPHA})?[0-9_]+"
38
38
 
39
+ @staticmethod
40
+ def _auto_type_change(params_dict):
41
+ """
42
+ 自动转换参数类型,会自动检查str类型的int, float数据,并转换为int, float。
43
+ :param params_dict: 包含参数的字典,其中值可能是str, int, float等类型
44
+ :return: 转换后的字典
45
+ """
46
+ for key, value in params_dict.items():
47
+ # 尝试将值转换为整数
48
+ if isinstance(value, str) and value.isdigit():
49
+ params_dict[key] = int(value)
50
+ # 尝试将值转换为浮点数
51
+ elif isinstance(value, str):
52
+ try:
53
+ # 尝试转换为浮点数
54
+ params_dict[key] = float(value)
55
+ except ValueError:
56
+ # 如果转换失败,保留原始字符串
57
+ pass
58
+ return params_dict
59
+
60
+ @staticmethod
61
+ def _handle_eval(txt, params_dict):
62
+ """
63
+ 处理EVAL表达式。
64
+ 要求格式为'$(表达式)',最后将结果的str替换原表达式。
65
+ 能使用的环境只有params_dict。
66
+ :param txt: 原始文本
67
+ :param params_dict: 包含变量名和值的字典
68
+ :return: 替换后的文本
69
+ """
70
+
71
+ # 定义一个函数,用于计算表达式并返回结果
72
+ def eval_expr(match):
73
+ # 获取匹配到的表达式部分
74
+ expr = match.group(1)
75
+ try:
76
+ # 使用eval函数计算表达式,传入params_dict作为局部变量环境
77
+ result = eval(expr, {}, params_dict)
78
+ # 返回计算结果的字符串形式
79
+ return str(result)
80
+ except Exception as e:
81
+ # 如果表达式计算出错,返回原始表达式
82
+ return '$EVAL({})'.format(expr)
83
+
84
+ # 使用re.sub函数替换文本中的所有EVAL表达式
85
+ return re.sub(r'\$\((.*?)\)', eval_expr, txt)
86
+
39
87
  def build(self, **params) -> str:
40
88
  """Build the IP core with the given parameters."""
41
89
  content = self.content
42
90
  ft = FT()
43
91
  ft.login(lambda key: str(params[key]), *IPC_W_VAL_GS, areas=[IPC_W_VAL_VID])
44
92
  ft.login(lambda k, v: (v if params[k] else ""), *IPC_REMOVE_GS, areas=list(IPC_REMOVE_KVID))
45
- self._built = ft.handle(content)
93
+ _content = ft.handle(content)
94
+ _content = self._handle_eval(_content, self._auto_type_change(params))
95
+ self._built = _content
46
96
  return self._built
47
97
 
48
98
  # ----------------------------------------- Following are properties -----------------------------------------
@@ -108,7 +158,7 @@ class IpCore:
108
158
 
109
159
 
110
160
  if __name__ == '__main__':
111
- IpCore.FromVerilog("", 'test', 'counter.v')
161
+ IpCore.FromVerilog("", 'test', r'H:\FPGA_Learns\00 IPC\_raw\counter.v2.v')
112
162
  # raise
113
163
  ip = IpCore("", 'test')
114
164
  d = ip.dict
@@ -2,7 +2,11 @@ from pyipcore.ui_main import GUI_Main, QApplication, QMessageBox
2
2
  import sys
3
3
 
4
4
 
5
- def ipc_ui():
5
+ def pyipc():
6
+ """
7
+ Run the GUI application.
8
+ CMD主函数入口
9
+ """
6
10
  app = QApplication(sys.argv)
7
11
  gui = GUI_Main()
8
12
  gui.show()
@@ -13,4 +17,4 @@ def ipc_ui():
13
17
 
14
18
 
15
19
  if __name__ == '__main__':
16
- ipc_ui()
20
+ pyipc()
@@ -2,7 +2,7 @@ import time
2
2
 
3
3
  from pyipcore.ui_main.ui_main import Ui_MainForm
4
4
  from pyipcore.ipcore import IpCore, VAR_PARAM_TYPE, VAR_PORT_TYPE
5
- from PyQt5 import QtGui
5
+ from PyQt5 import QtGui, QtWidgets
6
6
  from PyQt5.QtCore import Qt, pyqtSignal
7
7
  from PyQt5.QtCore import QStringListModel, QAbstractListModel, QVariant, QModelIndex, QSize
8
8
  from PyQt5.QtGui import QIcon, QFont, QTextDocument, QTextCursor
@@ -15,6 +15,11 @@ from files3 import files
15
15
 
16
16
 
17
17
  class ICodeWorker(QThread):
18
+ """
19
+ 一个Worker线程,用于处理InstCode的生成。
20
+ 具体来说,它会在一个循环中,每隔dt时间,从任务队列中取出一个任务并执行。
21
+ 而任务队列中的任务目前可以理解为一个InstCode生成函数。
22
+ """
18
23
  icode_update = pyqtSignal(str)
19
24
 
20
25
  def __init__(self, dt=0.2):
@@ -49,6 +54,12 @@ class ICodeWorker(QThread):
49
54
 
50
55
  class VarItemWidget(QWidget):
51
56
  """
57
+ 用于在主窗口左侧的GroupBox中显示参数和端口的Widget。
58
+
59
+ 比如可以显示一个label和一个输入框,或者一个label和一个复选框。
60
+ 前者显示数值参数,后者显示端口选择参数。
61
+
62
+ -----------------------------------
52
63
  _fn: 初始化时传入的回调函数, 具有不定参数
53
64
  _data: list of {"var_name", "var_type", "var_value"}
54
65
  var_type: "param" or "port"
@@ -149,12 +160,12 @@ class VarItemWidget(QWidget):
149
160
  spacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
150
161
  self.vlayout.addItem(spacer)
151
162
 
152
-
153
163
  class GUI_Main(QMainWindow):
154
164
  def __init__(self):
155
165
  super(GUI_Main, self).__init__()
156
166
  self.ui = Ui_MainForm()
157
167
  self.ui.setupUi(self)
168
+ self.load_current_size()
158
169
  self.ui.tab_sc.setCurrentIndex(0)
159
170
 
160
171
  # add VarItemWidget into var_layout
@@ -167,7 +178,7 @@ class GUI_Main(QMainWindow):
167
178
  # worker
168
179
  self.worker = ICodeWorker()
169
180
  self.worker.start()
170
- self.worker.dt = 2
181
+ self.worker.dt = 1
171
182
 
172
183
  # vars
173
184
  self.ipcore = None
@@ -195,6 +206,7 @@ class GUI_Main(QMainWindow):
195
206
  """
196
207
  self.ui.action_file_open.triggered.connect(self.open_file)
197
208
  self.ui.action_file_close.triggered.connect(self.close_file)
209
+ self.ui.action_file_scs.triggered.connect(self.save_current_size)
198
210
  self.ui.action_file_quit.triggered.connect(self.close)
199
211
  self.ui.action_proj_export.triggered.connect(self.export_proj)
200
212
  self.ui.action_tool_creator.triggered.connect(self.open_creator)
@@ -294,6 +306,18 @@ class GUI_Main(QMainWindow):
294
306
  # deactive worker
295
307
  self.worker.dt = 2
296
308
 
309
+
310
+ def save_current_size(self):
311
+ f = files(os.getcwd())
312
+ f["prefered_size"] = self.size()
313
+
314
+
315
+ def load_current_size(self):
316
+ f = files(os.getcwd())
317
+ size = f["prefered_size"]
318
+ if size:
319
+ self.resize(size)
320
+
297
321
  def export_proj(self):
298
322
  if self.ipcore is None:
299
323
  PopWarn("警告", "请先打开一个IP核文件.")
@@ -21,10 +21,11 @@ class Ui_MainForm(object):
21
21
  sizePolicy.setHeightForWidth(MainForm.sizePolicy().hasHeightForWidth())
22
22
  MainForm.setSizePolicy(sizePolicy)
23
23
  MainForm.setMinimumSize(QtCore.QSize(960, 720))
24
- MainForm.setMaximumSize(QtCore.QSize(960, 720))
24
+ MainForm.setMaximumSize(QtCore.QSize(2560, 1440))
25
25
  icon = QtGui.QIcon()
26
26
  icon.addPixmap(QtGui.QPixmap(":/icon/verilog.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
27
27
  MainForm.setWindowIcon(icon)
28
+ MainForm.setIconSize(QtCore.QSize(32, 32))
28
29
  self.centralwidget = QtWidgets.QWidget(MainForm)
29
30
  self.centralwidget.setObjectName("centralwidget")
30
31
  self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)
@@ -32,11 +33,13 @@ class Ui_MainForm(object):
32
33
  self.horizontalLayout.setSpacing(2)
33
34
  self.horizontalLayout.setObjectName("horizontalLayout")
34
35
  self.gbox_var = QtWidgets.QGroupBox(self.centralwidget)
35
- sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
36
+ sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred)
36
37
  sizePolicy.setHorizontalStretch(10)
37
38
  sizePolicy.setVerticalStretch(0)
38
39
  sizePolicy.setHeightForWidth(self.gbox_var.sizePolicy().hasHeightForWidth())
39
40
  self.gbox_var.setSizePolicy(sizePolicy)
41
+ self.gbox_var.setMinimumSize(QtCore.QSize(320, 0))
42
+ self.gbox_var.setMaximumSize(QtCore.QSize(320, 16777215))
40
43
  font = QtGui.QFont()
41
44
  font.setFamily("Consolas")
42
45
  font.setPointSize(12)
@@ -106,8 +109,10 @@ class Ui_MainForm(object):
106
109
  self.menu_file.setObjectName("menu_file")
107
110
  self.menu_proj = QtWidgets.QMenu(self.menubar)
108
111
  self.menu_proj.setObjectName("menu_proj")
109
- self.menu = QtWidgets.QMenu(self.menubar)
110
- self.menu.setObjectName("menu")
112
+ self.menu_tool = QtWidgets.QMenu(self.menubar)
113
+ self.menu_tool.setObjectName("menu_tool")
114
+ self.menu_help = QtWidgets.QMenu(self.menubar)
115
+ self.menu_help.setObjectName("menu_help")
111
116
  MainForm.setMenuBar(self.menubar)
112
117
  self.action_file_open = QtWidgets.QAction(MainForm)
113
118
  self.action_file_open.setObjectName("action_file_open")
@@ -121,15 +126,26 @@ class Ui_MainForm(object):
121
126
  self.action_lib_path.setObjectName("action_lib_path")
122
127
  self.action_tool_creator = QtWidgets.QAction(MainForm)
123
128
  self.action_tool_creator.setObjectName("action_tool_creator")
129
+ self.action_file_scs = QtWidgets.QAction(MainForm)
130
+ self.action_file_scs.setObjectName("action_file_scs")
131
+ self.action_readme = QtWidgets.QAction(MainForm)
132
+ self.action_readme.setObjectName("action_readme")
133
+ self.action_about = QtWidgets.QAction(MainForm)
134
+ self.action_about.setObjectName("action_about")
124
135
  self.menu_file.addAction(self.action_file_open)
125
136
  self.menu_file.addAction(self.action_file_close)
126
137
  self.menu_file.addSeparator()
138
+ self.menu_file.addAction(self.action_file_scs)
139
+ self.menu_file.addSeparator()
127
140
  self.menu_file.addAction(self.action_file_quit)
128
141
  self.menu_proj.addAction(self.action_proj_export)
129
- self.menu.addAction(self.action_tool_creator)
142
+ self.menu_tool.addAction(self.action_tool_creator)
143
+ self.menu_help.addAction(self.action_about)
144
+ self.menu_help.addAction(self.action_readme)
130
145
  self.menubar.addAction(self.menu_file.menuAction())
131
146
  self.menubar.addAction(self.menu_proj.menuAction())
132
- self.menubar.addAction(self.menu.menuAction())
147
+ self.menubar.addAction(self.menu_tool.menuAction())
148
+ self.menubar.addAction(self.menu_help.menuAction())
133
149
 
134
150
  self.retranslateUi(MainForm)
135
151
  self.tab_sc.setCurrentIndex(0)
@@ -137,18 +153,22 @@ class Ui_MainForm(object):
137
153
 
138
154
  def retranslateUi(self, MainForm):
139
155
  _translate = QtCore.QCoreApplication.translate
140
- MainForm.setWindowTitle(_translate("MainForm", "IP Generator Wizade"))
156
+ MainForm.setWindowTitle(_translate("MainForm", "IP Generator Wizard"))
141
157
  self.gbox_var.setTitle(_translate("MainForm", "Variables"))
142
158
  self.tab_sc.setTabText(self.tab_sc.indexOf(self.tab_rc), _translate("MainForm", "RawCode"))
143
159
  self.tab_sc.setTabText(self.tab_sc.indexOf(self.tab_cc), _translate("MainForm", "CurrentCode"))
144
160
  self.tab_sc.setTabText(self.tab_sc.indexOf(self.tab_ic), _translate("MainForm", "InstCode"))
145
161
  self.menu_file.setTitle(_translate("MainForm", "文件"))
146
162
  self.menu_proj.setTitle(_translate("MainForm", "项目"))
147
- self.menu.setTitle(_translate("MainForm", "工具"))
163
+ self.menu_tool.setTitle(_translate("MainForm", "工具"))
164
+ self.menu_help.setTitle(_translate("MainForm", "帮助"))
148
165
  self.action_file_open.setText(_translate("MainForm", "打开"))
149
166
  self.action_file_close.setText(_translate("MainForm", "关闭"))
150
167
  self.action_file_quit.setText(_translate("MainForm", "退出"))
151
168
  self.action_proj_export.setText(_translate("MainForm", "导出"))
152
169
  self.action_lib_path.setText(_translate("MainForm", "lib_path"))
153
170
  self.action_tool_creator.setText(_translate("MainForm", "Ip Creator Wizade"))
154
- import pyipcore.icon_rc
171
+ self.action_file_scs.setText(_translate("MainForm", "保存尺寸"))
172
+ self.action_readme.setText(_translate("MainForm", "帮助文档"))
173
+ self.action_about.setText(_translate("MainForm", "关于"))
174
+ import icon_rc
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyipcore
3
- Version: 0.4.5
3
+ Version: 0.4.8
4
4
  Summary: (PyQt5 based) Create "Ipcore" from verilog(Need iverilog). Provide "Param Value" and "Port Control" function. This kind of IpCore is not safe, only for convenience
5
5
  Author-email: 2229066748@qq.com
6
6
  Maintainer: Eagle'sBaby
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pyipc = pyipcore:cmd_pyipc
@@ -13,7 +13,7 @@ from setuptools.command.install import install
13
13
 
14
14
  setup(
15
15
  name='pyipcore',
16
- version='0.4.5',
16
+ version='0.4.8',
17
17
  description='(PyQt5 based) Create "Ipcore" from verilog(Need iverilog). Provide "Param Value" and "Port Control" function. This kind of IpCore is not safe, only for convenience',
18
18
  # long_description=long_description,
19
19
  author_email='2229066748@qq.com',
@@ -38,7 +38,7 @@ setup(
38
38
  # CMD: ipc_ui -> cmd_ipc_ui
39
39
  entry_points={
40
40
  'console_scripts': [
41
- 'ipc_ui=pyipcore:cmd_ipc_ui',
41
+ 'pyipc=pyipcore:cmd_pyipc',
42
42
  ]
43
43
  },
44
44
  )
@@ -1,6 +0,0 @@
1
- from pyipcore.main import ipc_ui
2
- from pyipcore.ipcore import IpCore
3
-
4
-
5
- def cmd_ipc_ui():
6
- ipc_ui()
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- ipc_ui = pyipcore:cmd_ipc_ui
File without changes
File without changes
File without changes
File without changes