生物分子模拟论坛

 找回密码
 我想注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 9458|回复: 1

[Python] pymol 插件的制作流程

[复制链接]
发表于 2016-7-19 18:43:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,下载更多分子模拟资源。

您需要 登录 才可以下载或查看,没有帐号?我想注册

x
[size=1.2em]
pymol 插件的制作流程
step 1 定制你的插件
addmenuitem(menuName, itemType, statusHelp = '', traverseSpec = None, **kw)
Add a menu item to the menu menuName. The kind of menu item is given by itemType and may be one of command, separator, checkbutton, radiobutton or cascade (although cascade menus are better added using the addcascademenu() method).
Any keyword arguments present will be passed to the menu when creating the menu item.
See Tkinter.Menu for the valid options for each item type. In addition, a keyboard accelerator may be automatically given to the item, as described under hotkeys. When the mouse is moved over the menu item, the helpString will be displayed by the balloon's statuscommand.
  • 插件的位置(存放在哪个menu下面)
  • itmetype( command speractor checkbutton radiobutton cascade) 这里一般选用command,支持回调函数,弹出新的窗口
  • 插件的说明(鼠标悬停显示的文字)
    测试发现 menu 上的文字有显示,menuitem上没有显示
  • 插件上面显示的文字
  • comand 触发的回调函数
    回调函数可以是普通函数,或者是类的构造函数。通过该函数创建GUI。
    类的构造函数,方便创建复杂界面。
def __init__(self):
    # Simply add the menu entry and callback
    self.menuBar.addmenu('DDDC','some text to comment the menu for
    coder')
    self.menuBar.addmenuitem('Wizard', 'command',
                                     'text to comment the menu',


                                     label = 'PDB Loader Service',
                                     command = lambda s=self :
                                     FetchPDB(s))






step2 定制你插件的界面
这里需要你熟悉tk的各种控件,以及布局。 这里以这个控件为例。
class FetchPDB:
    def __init__(self, app):
        import tkSimpleDialog
        import tkMessageBox
        import urllib
        import gzip

        import os
        import string

        pdbCode = tkSimpleDialog.askstring('PDB Loader Service',
                                                      'Please enter
                                                      a 4-digit pdb

                                                      code:',
                                                      parent=app.ro
                                                      ot)

        if pdbCode: # None is returned for user cancel
            pdbCode = string.upper(pdbCode)

            try:
                filename =
                urllib.urlretrieve('http://www.rcsb.org/pdb/files/'
                                              + pdbCode +
                                              '.pdb.gz')[0]
            except:

                tkMessageBox.showerror('Connection Error',
                                       'Can not access to the PDB
                                       database.\n'+
                                       'Please check your Internet
                                       access.',
                                       parent=app.root)






tkSimpleDialog 最简单的对话框,获得输入的内容
-tkSimpleDialog.askstring
  • tkSimpleDialog.askinteger
  • tkSimpleDialog.askfloat
当点击ok的时候就会回调上述函数。
参考




发表于 2016-7-20 07:19:12 | 显示全部楼层
有个图就更完美了。谢谢分享
您需要登录后才可以回帖 登录 | 我想注册

本版积分规则

QQ|分迪科技|小黑屋|手机版|Archiver|生物分子模拟论坛 ( 蜀ICP备14009200号-3 )

GMT+8, 2024-9-8 10:36 , Processed in 0.052374 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表