2025-02-22 15:53:32 +08:00
|
|
|
|
"""
|
|
|
|
|
|
工具模块初始化脚本
|
|
|
|
|
|
功能:向Axis Innovators Box注册自定义工具类别和工具项
|
|
|
|
|
|
作者:tzdwindows 7
|
|
|
|
|
|
版本:1.1
|
|
|
|
|
|
"""
|
|
|
|
|
|
from com.axis.innovators.box.python import PyLocalSide
|
2025-02-23 13:31:14 +08:00
|
|
|
|
|
|
|
|
|
|
from javax.swing import AbstractAction, JFrame,JDialog, JLabel, JButton, JPanel, JOptionPane
|
|
|
|
|
|
from java.awt import BorderLayout, Dimension
|
|
|
|
|
|
from java.awt.event import ActionListener
|
2025-02-22 15:53:32 +08:00
|
|
|
|
|
|
|
|
|
|
class MyAction(AbstractAction):
|
|
|
|
|
|
def actionPerformed(self, event):
|
|
|
|
|
|
"""工具项点击事件处理"""
|
|
|
|
|
|
print("[DEBUG] Tool item clicked! Event source:", event.getSource())
|
|
|
|
|
|
|
2025-02-23 13:31:14 +08:00
|
|
|
|
# 创建 JDialog 作为子窗口
|
|
|
|
|
|
parent_frame = event.getSource().getTopLevelAncestor() # 获取父窗口
|
|
|
|
|
|
dialog = JDialog(parent_frame, u"工具面板", True) # True 表示模态对话框
|
|
|
|
|
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE) # 关闭时释放资源
|
|
|
|
|
|
dialog.setSize(300, 200)
|
|
|
|
|
|
dialog.setLocationRelativeTo(parent_frame) # 居中于父窗口
|
|
|
|
|
|
|
|
|
|
|
|
# 创建面板并设置布局
|
|
|
|
|
|
panel = JPanel()
|
|
|
|
|
|
panel.layout = BorderLayout() # 使用边界布局
|
|
|
|
|
|
|
|
|
|
|
|
# 添加标签
|
|
|
|
|
|
label = JLabel(u"这是工具项的子面板")
|
|
|
|
|
|
panel.add(label, BorderLayout.CENTER)
|
|
|
|
|
|
|
|
|
|
|
|
# 添加关闭按钮
|
|
|
|
|
|
close_btn = JButton(u"关闭")
|
|
|
|
|
|
close_btn.addActionListener(lambda e: dialog.dispose()) # 点击关闭窗口
|
|
|
|
|
|
panel.add(close_btn, BorderLayout.SOUTH)
|
|
|
|
|
|
|
|
|
|
|
|
# 将面板添加到窗口
|
|
|
|
|
|
dialog.add(panel)
|
|
|
|
|
|
dialog.visible = True # 显示窗口
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-22 15:53:32 +08:00
|
|
|
|
def onStartup():
|
|
|
|
|
|
"""
|
|
|
|
|
|
系统启动时自动执行的初始化逻辑
|
|
|
|
|
|
功能:
|
|
|
|
|
|
1. 创建工具类别
|
|
|
|
|
|
2. 创建工具项并绑定动作
|
|
|
|
|
|
3. 注册到系统全局工具集
|
|
|
|
|
|
"""
|
|
|
|
|
|
print('[INFO] 正在初始化自定义工具...')
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------
|
|
|
|
|
|
# 创建工具类别(参数顺序:显示名称,图标资源名,描述)
|
|
|
|
|
|
# --------------------------
|
|
|
|
|
|
tool_category = PyLocalSide.getToolCategory(
|
|
|
|
|
|
u"数据分析工具", # 显示名称(GUI可见)
|
|
|
|
|
|
u"analytics_icon.png", # 图标文件名(需存在于资源目录)
|
|
|
|
|
|
u"高级数据分析功能集合" # 悬停提示描述
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------
|
|
|
|
|
|
# 创建工具项(参数顺序:显示名称,图标,描述,ID,动作对象)
|
|
|
|
|
|
# --------------------------
|
|
|
|
|
|
tool_action = MyAction()
|
|
|
|
|
|
tool_item = PyLocalSide.getToolItem(
|
|
|
|
|
|
u"数据可视化", # 工具项显示名称
|
|
|
|
|
|
u"chart_icon.png", # 工具项图标
|
|
|
|
|
|
u"生成交互式数据图表", # 工具项描述
|
|
|
|
|
|
1001, # 工具项唯一ID(需在配置中统一管理)
|
|
|
|
|
|
tool_action # 点击触发的动作
|
|
|
|
|
|
)
|
|
|
|
|
|
tool_category.addTool(tool_item)
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------
|
|
|
|
|
|
# 注册工具类别到系统(参数:类别对象,全局唯一注册名称)
|
|
|
|
|
|
# --------------------------
|
|
|
|
|
|
PyLocalSide.addToolCategory(
|
|
|
|
|
|
tool_category,
|
|
|
|
|
|
u"custom_module::data_analysis_tools" # 推荐命名规则:模块名::功能名
|
|
|
|
|
|
)
|
|
|
|
|
|
print('[SUCCESS] 工具类别注册成功')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
result = 0
|
|
|
|
|
|
errorResult = ""
|
|
|
|
|
|
|
|
|
|
|
|
# 确保Jython运行时可以访问onStartup函数
|
|
|
|
|
|
# 原理:将函数显式绑定到全局字典
|
|
|
|
|
|
globals()['onStartup'] = onStartup
|