If you need a global variable, use pymol.stored
>

Thank You Thomas -- that solves it.

Boris.

On Tue, Oct 23, 2012 at 9:28 PM, Boris Kheyfets <kheyfbo...@gmail.com>wrote:

> Found a solution.
>
> Basically it is to add
>
> pmg_tk/startup/newmenu.py
>
> file with the following content:
>
> from Tkinter import *
> from pymol import cmd
>
> def __init__(self):
>     self.menuBar.addmenu('NewMenu', 'Sample Menu')
>
>     self.menuBar.addmenuitem('NewMenu', 'command',
>                      'White background',
>                      label='White Background',
>                     command = lambda : cmd.set("bg_rgb","[1,1,1]"))
>
>     self.menuBar.addmenuitem('NewMenu', 'command',
>                      'Black background',
>                      label='Black Background',
>                      command = lambda : cmd.set("bg_rgb","[0,0,0]"))
>
> This adds the menu.
>
> I got what I wanted with:
>
>
>    - .pymolrc:
>
> # custom scripts:
> import imp
> imp.load_source('bk_pymols', os.path.expanduser('~/.pymolrc.py'))
>
>
>
>    - .pymolrc.py
>
> from pymol import cmd
>
> def bk_notW ():
>     "Makes notW selection."
>     cmd.select("notW", "not (resn W)")
>
> def bk_hides_W ():
>     "Hides W molecules."
>     cmd.hide("all")
>     cmd.show("spheres", "not (resn W)")
>
> cmd.set_key('ALT-N', bk_notW)
> cmd.set_key('ALT-W', bk_hides_W)
>
>
>    - and finally -- pmg_tk/startup/BK.py:
>
> from Tkinter import *
> from pymol import cmd
>
> # custom scripts:
> import imp, os
> imp.load_source('bk_pymols', os.path.expanduser('~/.pymolrc.py'))
> from bk_pymols import bk_notW, bk_hides_W
>
>
> def __init__(self):
>     self.menuBar.addmenu('BK', 'My menus!')
>
>     self.menuBar.addmenuitem('BK', 'command',
>                      'Makes notW [Alt-n]',
>                      label='Makes notW [Alt-n]',
>                     command = bk_notW)
>
>     self.menuBar.addmenuitem('BK', 'command',
>                      'Hides W mols [Alt-w]',
>                      label='Hides W mols [Alt-w]',
>                      command = bk_hides_W)
>
> Works like a charm: I have custom menus and I can bind any of its entries
> to a key.
>
> But I want bk_hides_W to be a toggler. So I need a way to set a state of
> my defun.
> If I do
>
> def bk_toggles_W ():
>     "Hides W molecules."
>     if cmd.get("bk_toggles_W"):
>         cmd.hide("all")
>         cmd.show("spheres", "not (resn W)")
>         cmd.set("bk_toggles_W", 0)
>     else:
>         cmd.show("spheres", "resn W")
>         cmd.set("bk_toggles_W", 1)
>
> pymol is upset -- I think it is because it doesn't know bk_toggles_Wsetting:
>
> Error: 1
> QuietException Exception in Tk callback
>   Function: <function bk_toggles_W at 0x7ff02d90cb90> (type: <type
> 'function'>)
>   Args: ()
> Traceback (innermost last):
>   File "/usr/lib/python2.7/dist-packages/Pmw/Pmw_1_3/lib/PmwBase.py", line
> 1747, in __call__
>     return apply(self.func, args)
>   File "/home/boris/.pymolrc.py", line 67, in bk_toggles_W
>     if cmd.get("bk_toggles_W"):
>   File "/home/boris/.local/lib/python2.7/site-packages/pymol/setting.py",
> line 1300, in get
>     raise QuietException
> QuietException: <pymol.parsing.QuietException instance at 0x7ff018698518>
>
> How can I add the setting to pymol?
>
> --
> Boris.
>
>
> On Tue, Oct 23, 2012 at 5:17 PM, Jason Vertrees <
> jason.vertr...@schrodinger.com> wrote:
>
>> Hi Boris,
>>
>> David Hall's suggestions are perfect.
>>
>> Let me offer one more. If you can put up with programming a little
>> Python, check out pymol/modules/pymol/menu.py and
>> pymol/modules/pymol/preset.py. In menu.py you could add a "No W" menu
>> option (or similar) to the A > Preset >
>>
>> Cheers,
>>
>> -- Jason
>>
>> On Tue, Oct 23, 2012 at 6:02 AM, Boris Kheyfets <kheyfbo...@gmail.com>
>> wrote:
>> > Hello PyMOL users,
>> >
>> > Menus
>> > =====
>> >
>> > Is there a way I can add custom menu in PyMOL?
>> >
>> > Ideally I'd like to be able to call both
>> >
>> > * pml scripts, as well as
>> > * full python pymol scrpts
>> >
>> > Shortcuts
>> > =========
>> >
>> > Similarly -- is there a way I can bind exectution of given
>> >
>> > * pml script, or
>> > * full python pymol script
>> >
>> > to a given key?
>> >
>> > The problem
>> > ===========
>> >
>> > The basic problem
>> > -----------------
>> >
>> > The basic problem is to automate tasks one repeats frequenlty. For
>> example I
>> > had to type::
>> >
>> >   select notW, not (resn W)
>> >   hide all
>> >   show spheres, notW
>> >
>> > frequently.
>> >
>> >
>> > The problem which leads to the need of menu
>> > -------------------------------------------
>> >
>> > So I make a pml or full-python pymol script and load it.
>> >
>> > But then I have to remember the name of the script. Which is terrible --
>> > because I have custom scripts in each and every program that I use.
>> >
>> >
>> > The problem which leads to the need of custom shortcuts
>> > -------------------------------------------------------
>> >
>> > Having custom menu us great as a reminder of what scripts have You
>> written.
>> > But it's terrible to click through the menus. One is much better with
>> > shorcuts (hotkeys).
>> >
>> >
>> >
>> >
>> >
>> ------------------------------------------------------------------------------
>> > Everyone hates slow websites. So do we.
>> > Make your web apps faster with AppDynamics
>> > Download AppDynamics Lite for free today:
>> > http://p.sf.net/sfu/appdyn_sfd2d_oct
>> > _______________________________________________
>> > PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
>> > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
>> > Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
>>
>>
>>
>> --
>> Jason Vertrees, PhD
>> PyMOL Product Manager
>> Schrödinger, Inc.
>>
>> (e) jason.vertr...@schrodinger.com
>> (o) +1 (603) 374-7120
>>
>
>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to