数据挖掘 发表于 2016-7-19 18:43:25

pymol 插件的制作流程


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')
            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的时候就会回调上述函数。参考
[*]http://www.pymolwiki.org/index.php/Plugins_Tutorial
[*]http://www.pymolwiki.org/index.php/Category:Plugins




xufund 发表于 2016-7-20 07:19:12

有个图就更完美了。谢谢分享
页: [1]
查看完整版本: pymol 插件的制作流程