在slicer中编写scripted模块
本文要实现的是在按下两个按钮,分别打印两句话
步骤1:先通过Extension Wizard建立出scripted模块
将模块的名字命名为Test
步骤2:找到名为Test.py的文件
将里面的代码修改成下面这样
import logging
import osimport vtkimport slicer
from slicer.ScriptedLoadableModule import *
from slicer.util import VTKObservationMixinclass Test(ScriptedLoadableModule):"""Uses ScriptedLoadableModule base class, available at:https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py"""def __init__(self, parent):ScriptedLoadableModule.__init__(self, parent)self.parent.title = "Test" # TODO: make this more human readable by adding spacesself.parent.categories = ["Examples"] # TODO: set categories (folders where the module shows up in the module selector)self.parent.dependencies = [] # TODO: add here list of module names that this module requiresself.parent.contributors = ["John Doe (AnyWare Corp.)"] # TODO: replace with "Firstname Lastname (Organization)"# TODO: update with short description of the module and a link to online module documentationself.parent.helpText = """
This is an example of scripted loadable module bundled in an extension.
See more information in <a href="https://github.com/organization/projectname#Test">module documentation</a>.
"""# TODO: replace with organization, grant and thanksself.parent.acknowledgementText = """
This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc., Andras Lasso, PerkLab,
and Steve Pieper, Isomics, Inc. and was partially funded by NIH grant 3P41RR013218-12S1.
"""class TestWidget(ScriptedLoadableModuleWidget, VTKObservationMixin):"""Uses ScriptedLoadableModuleWidget base class, available at:https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py"""def __init__(self, parent=None):"""Called when the user opens the module the first time and the widget is initialized."""ScriptedLoadableModuleWidget.__init__(self, parent)VTKObservationMixin.__init__(self) # needed for parameter node observationself.logic = Noneself._parameterNode = Noneself._updatingGUIFromParameterNode = Falsedef setup(self):"""Called when the user opens the module the first time and the widget is initialized."""ScriptedLoadableModuleWidget.setup(self)
可以看到此时的界面中什么也没有
步骤3:往代码中添加按钮的代码
import logging
import osimport vtkimport slicer
from slicer.ScriptedLoadableModule import *
from slicer.util import VTKObservationMixinclass Test(ScriptedLoadableModule):"""Uses ScriptedLoadableModule base class, available at:https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py"""def __init__(self, parent):ScriptedLoadableModule.__init__(self, parent)self.parent.title = "Test" # TODO: make this more human readable by adding spacesself.parent.categories = ["Examples"] # TODO: set categories (folders where the module shows up in the module selector)self.parent.dependencies = [] # TODO: add here list of module names that this module requiresself.parent.contributors = ["John Doe (AnyWare Corp.)"] # TODO: replace with "Firstname Lastname (Organization)"# TODO: update with short description of the module and a link to online module documentationself.parent.helpText = """
This is an example of scripted loadable module bundled in an extension.
See more information in <a href="https://github.com/organization/projectname#Test">module documentation</a>.
"""# TODO: replace with organization, grant and thanksself.parent.acknowledgementText = """
This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc., Andras Lasso, PerkLab,
and Steve Pieper, Isomics, Inc. and was partially funded by NIH grant 3P41RR013218-12S1.
"""class TestWidget(ScriptedLoadableModuleWidget, VTKObservationMixin):"""Uses ScriptedLoadableModuleWidget base class, available at:https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py"""def __init__(self, parent=None):"""Called when the user opens the module the first time and the widget is initialized."""ScriptedLoadableModuleWidget.__init__(self, parent)VTKObservationMixin.__init__(self) # needed for parameter node observationself.logic = Noneself._parameterNode = Noneself._updatingGUIFromParameterNode = Falsedef setup(self):"""Called when the user opens the module the first time and the widget is initialized."""ScriptedLoadableModuleWidget.setup(self)import qt#设添加两个按钮self.button_1 = qt.QPushButton("button1")self.button_1.enabled = Trueself.button_2 = qt.QPushButton("button2")self.button_2.enabled = True#添加到界面中self.layout.addWidget(self.button_1)self.layout.addWidget(self.button_2)#信号和槽函数self.button_1.connect('clicked(bool)', self.button_1_clicked)self.button_2.connect('clicked(bool)', self.button_2_clicked)#垂直布局self.layout.addStretch(1)def button_1_clicked(self):print("button1 clicked===>")def button_2_clicked(self):print("button2 clicked===>")
可以看到界面最终变成了下图这样
点击两个按钮,将会进行打印
在slicer中编写scripted模块相关推荐
- Slicer学习笔记(三十九)slicer中Markups模块
Slicer学习笔记(三十九)slicer中Markups模块 1.概念 1.1.Markups模块简介 1.2.应用方向 1.3.界面面板 1.Markups List 2.Buttons And ...
- Magento中如何在模块中使用多张数据表并配置多个model?
功能介绍: 引用magento开发人员的一句话: Magento has basic one resource to one table resource. 也即是一个资源对应一张数据表. 当有时候, ...
- python io模块_python中的StringIO模块
原博文 2015-10-23 15:21 − # python中的StringIO模块 标签:python StringIO --- > 此模块主要用于在内存缓冲区中读写数据.模块是用类编写的, ...
- 如何编写Python模块/包?
本文翻译自:How to write a Python module/package? I've been making Python scripts for simple tasks at work ...
- [转]使用 C 编写 Lua 模块
Lua 作为一种小巧的语言,一般都是嵌入到 C/C++ 中作为扩展语言,但是也可以作为独立的脚本语言使用,并且可以使用 C/C++ 编写扩展模块.在参考资料 [1] 中有怎样用 C/C++ 编写模块的 ...
- python中模块和函数_Python中函数和模块的体验与使用
函数基础 目标 函数的快速体验 函数的基本使用 函数的参数 函数的返回值 函数的嵌套调用 在模块中定义函数 01. 函数的快速体验 1.1 快速体验 所谓函数,就是把 具有独立功能的代码块 组织为一个 ...
- windows编写linux脚本,Windows PowerShell:共享您的脚本 - 在脚本中编写 Cmdlet | Microsoft Docs...
Windows PowerShell:在脚本中编写 Cmdlet 08/17/2016 本文内容 Don Jones Windows PowerShell v2 中一项很酷的新功能是能够编写性能明显改 ...
- python 利用pyinstaller 编译.exe文件过程中编写完的.exe文件执行过程中闪退
问题描述: python 利用pyinstaller 编译.exe文件过程中编写完的.exe文件执行过程中闪退,并提示no module named 'pyproj.datadir' 解决方法: 闪退 ...
- WebService大讲堂之Axis2(9):编写Axis2模块(Module)
Axis2可以通过模块(Module)进行扩展.Axis2模块至少需要有两个类,这两个类分别实现了Module和Handler接口.开发和使用一个Axis2模块的步骤如下: 1. 编写实现Module ...
最新文章
- Oracle数据库备份与恢复1\Oracle数据库备份与恢复(1)exp和imp 之三
- 50+篇《神经架构搜索NAS》2020论文合集
- linux svn安装
- array,arraylist,string的总结
- python-字符串·文件·集合操作
- 读书笔记《集体智慧编程》Chapter 2 : Make Recommendations
- mysql连接非常慢的觖决办法及其它常见问题解决办法
- Mybatis面试题-日更
- 短视频矩阵系统,抖音矩阵系统,抖音获客系统源码。look
- 2021 年人工智能全球最具影响力学者榜单 AI 2000 发布
- 公共关系与人际交往能力
- python手把手教你创作趣味词云(保姆级贴心)
- 华硕装鸿蒙系统,智能家居 篇八:解决华硕路由器设置不当造成传感器延迟
- Linux中实现定时任务详解
- TxtView 手机文本阅读器
- 如何根据vin码查询_vin查配置 车辆VIN码查询车辆基本配置信息 知道车辆vin码怎么查配置...
- CTF SSTI模板注入详解
- Inno Setup汉化方法
- Nvidia显卡驱动与Cuda关系,Cuda的driver API 和runtime API
- table表格中实现圆角效果