-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path__init__.py
100 lines (74 loc) · 2.59 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'''
PyMOL Demo Plugin
The plugin resembles the old "Rendering Plugin" from Michael Lerner, which
was written with Tkinter instead of PyQt.
(c) Schrodinger, Inc.
License: BSD-2-Clause
'''
from __future__ import absolute_import
from __future__ import print_function
# Avoid importing "expensive" modules here (e.g. scipy), since this code is
# executed on PyMOL's startup. Only import such modules inside functions.
import os
def __init_plugin__(app=None):
'''
Add an entry to the PyMOL "Plugin" menu
'''
from pymol.plugins import addmenuitemqt
addmenuitemqt('Demo "Render" Plugin', run_plugin_gui)
# global reference to avoid garbage collection of our dialog
dialog = None
def run_plugin_gui():
'''
Open our custom dialog
'''
global dialog
if dialog is None:
dialog = make_dialog()
dialog.show()
def make_dialog():
# entry point to PyMOL's API
from pymol import cmd
# pymol.Qt provides the PyQt5 interface, but may support PyQt4
# and/or PySide as well
from pymol.Qt import QtWidgets
from pymol.Qt.utils import loadUi
from pymol.Qt.utils import getSaveFileNameWithExt
# create a new Window
dialog = QtWidgets.QDialog()
# populate the Window from our *.ui file which was created with the Qt Designer
uifile = os.path.join(os.path.dirname(__file__), 'demowidget.ui')
form = loadUi(uifile, dialog)
# callback for the "Ray" button
def run():
# get form data
height = form.input_height.value()
width = form.input_width.value()
dpi = form.input_dpi.value()
filename = form.input_filename.text()
units = form.input_units.currentText()
# calculate dots per centimeter or inch
if units == 'cm':
dots_per_unit = dpi * 2.54
else:
dots_per_unit = dpi
# convert image size to pixels
width *= dots_per_unit
height *= dots_per_unit
# render the image
if filename:
cmd.png(filename, width, height, dpi=dpi, ray=1, quiet=0)
else:
cmd.ray(width, height, quiet=0)
print('No filename selected, only rendering on display')
# callback for the "Browse" button
def browse_filename():
filename = getSaveFileNameWithExt(
dialog, 'Save As...', filter='PNG File (*.png)')
if filename:
form.input_filename.setText(filename)
# hook up button callbacks
form.button_ray.clicked.connect(run)
form.button_browse.clicked.connect(browse_filename)
form.button_close.clicked.connect(dialog.close)
return dialog