| 1 |
DEBUG = False |
| 2 |
|
| 3 |
import sys |
| 4 |
import re |
| 5 |
import threading |
| 6 |
import os |
| 7 |
import time |
| 8 |
|
| 9 |
if True: |
| 10 |
from tkinter import * |
| 11 |
import tkinter.filedialog as tkFileDialog |
| 12 |
import tkinter.messagebox as tkMessageBox |
| 13 |
import tkinter.font as tkFont |
| 14 |
_next_method_name = '__next__' |
| 15 |
|
| 16 |
import Pmw |
| 17 |
|
| 18 |
from pymol.wizard import cleanup |
| 19 |
|
| 20 |
from pmg_tk.Setting import Setting |
| 21 |
from pmg_tk.SetEditor import SetEditor |
| 22 |
from pmg_tk.ColorEditor import ColorEditor |
| 23 |
|
| 24 |
from pmg_tk.skins import PMGSkin |
| 25 |
from .builder import Builder |
| 26 |
|
| 27 |
import pymol._gui |
| 28 |
|
| 29 |
import traceback |
| 30 |
|
| 31 |
root = None |
| 32 |
|
| 33 |
def encode(s): |
| 34 |
|
| 35 |
return s |
| 36 |
|
| 37 |
def split_tk_file_list(pattern): |
| 38 |
filenames = [] |
| 39 |
while True: |
| 40 |
pattern = pattern.strip() |
| 41 |
if not pattern: |
| 42 |
break |
| 43 |
sep = None |
| 44 |
if pattern[0] == '{': |
| 45 |
pattern = pattern[1:] |
| 46 |
sep = '}' |
| 47 |
a = pattern.split(sep, 1) |
| 48 |
filenames.append(a[0]) |
| 49 |
pattern = a[1] if len(a) == 2 else '' |
| 50 |
return filenames |
| 51 |
|
| 52 |
def asksaveasfilename(*args, **kwargs): |
| 53 |
filename = tkFileDialog.asksaveasfilename(*args, **kwargs) |
| 54 |
return encode(filename) |
| 55 |
|
| 56 |
def askopenfilename(*args, **kwargs): |
| 57 |
filename = tkFileDialog.askopenfilename(*args, **kwargs) |
| 58 |
if not filename: |
| 59 |
return filename |
| 60 |
multiple = kwargs.get('multiple', 0) |
| 61 |
if not multiple: |
| 62 |
filename = [filename] |
| 63 |
elif not isinstance(filename, (list, tuple)): |
| 64 |
filename = split_tk_file_list(filename) |
| 65 |
filename = map(os.path.normpath, filename) |
| 66 |
filename = map(encode, filename) |
| 67 |
filename = list(filename) |
| 68 |
if not multiple: |
| 69 |
return filename[0] |
| 70 |
return filename |
| 71 |
|
| 72 |
def _darwin_browser_open(url): |
| 73 |
os.popen("open "+url,'r').read() |
| 74 |
|
| 75 |
def darwin_browser_open(url): |
| 76 |
t = threading.Thread(target=_darwin_browser_open,args=(url,)) |
| 77 |
t.setDaemon(1) |
| 78 |
t.start() |
| 79 |
|
| 80 |
def _doAsync(self_cmd,cmmd,dirty=0): |
| 81 |
self_cmd.do(cmmd) |
| 82 |
if dirty: |
| 83 |
self_cmd.dirty() |
| 84 |
|
| 85 |
def _def_ext(ext): |
| 86 |
if sys.platform != 'win32': |
| 87 |
ext = None |
| 88 |
return ext |
| 89 |
|
| 90 |
class Normal(PMGSkin, pymol._gui.PyMOLDesktopGUI): |
| 91 |
|
| 92 |
pad = ' ' |
| 93 |
|
| 94 |
appname = 'The PyMOL Molecular Graphics System' |
| 95 |
appversion = '0.0.0.0' |
| 96 |
copyright = ('Copyright (C) 2003-%d\n' % (time.localtime().tm_year,) + |
| 97 |
'Schrodinger LLC.\n'+ |
| 98 |
'All rights reserved.') |
| 99 |
contactweb = 'http://www.pymol.org' |
| 100 |
contactemail = '[email protected]' |
| 101 |
|
| 102 |
def scene_panel_menu_dialog(self): |
| 103 |
print("scene_panel_menu_dialog not available in pmg_tk.") |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
def _inc_fontsize(self, delta, font): |
| 108 |
size = font.cget('size') |
| 109 |
sign = -1 if size < 0 else 1 |
| 110 |
size = max(5, abs(size) + delta) |
| 111 |
font.configure(size=size * sign) |
| 112 |
|
| 113 |
def inc_fontsize(self, delta=1): |
| 114 |
for name in tkFont.names(): |
| 115 |
self._inc_fontsize(delta, tkFont.nametofont(name)) |
| 116 |
|
| 117 |
def inc_fontsize_dialog(self): |
| 118 |
dialog = Toplevel(self.root) |
| 119 |
grid = dialog |
| 120 |
kw = {'row': 0, 'sticky': 'w', 'padx': 5, 'pady': 5} |
| 121 |
col = getattr(iter(range(5)), _next_method_name) |
| 122 |
Button(grid, text=' - ', command=lambda: self.inc_fontsize(-1)).grid(column=col(), **kw) |
| 123 |
Button(grid, text=' + ', command=lambda: self.inc_fontsize( 1)).grid(column=col(), **kw) |
| 124 |
Label(grid, text='All GUI Font Sizes').grid(column=col(), **kw) |
| 125 |
kw['row'] = 1 |
| 126 |
col = getattr(iter(range(5)), _next_method_name) |
| 127 |
Button(grid, text=' - ', command=lambda: self._inc_fontsize(-1, self.fixedfont)).grid(column=col(), **kw) |
| 128 |
Button(grid, text=' + ', command=lambda: self._inc_fontsize( 1, self.fixedfont)).grid(column=col(), **kw) |
| 129 |
Label(grid, text='Output Font Size').grid(column=col(), **kw) |
| 130 |
dialog.title('GUI Font Size') |
| 131 |
|
| 132 |
@property |
| 133 |
def initialdir(self): |
| 134 |
''' |
| 135 |
Be in sync with cd/pwd on the console until the first file has been |
| 136 |
browsed, then remember the last directory. |
| 137 |
''' |
| 138 |
return self._initialdir or os.getcwd() |
| 139 |
|
| 140 |
@initialdir.setter |
| 141 |
def initialdir(self, value): |
| 142 |
self._initialdir = value |
| 143 |
|
| 144 |
def cd_dialog(self): |
| 145 |
self.cmd.cd(encode(tkFileDialog.askdirectory( |
| 146 |
title="Change Working Directory", |
| 147 |
initialdir=self.initialdir)) or '.', quiet=0) |
| 148 |
|
| 149 |
def createDataArea(self): |
| 150 |
|
| 151 |
self.dataArea = self.app.createcomponent('dataarea', |
| 152 |
(), None, |
| 153 |
Frame, (self.app._hull,), |
| 154 |
relief=SUNKEN, |
| 155 |
bd=1) |
| 156 |
self.dataArea.pack(side=LEFT, fill=BOTH, expand=YES, |
| 157 |
padx=1, pady=1) |
| 158 |
|
| 159 |
def destroyDataArea(self): |
| 160 |
self.app.destroycomponent('dataarea') |
| 161 |
|
| 162 |
def createCommandArea(self): |
| 163 |
|
| 164 |
self.commandFrame = self.app.createcomponent('commandframe', (), None, |
| 165 |
Frame,(self.app._hull,),relief=SUNKEN,bd=1) |
| 166 |
self.commandFrame.place(width=500) |
| 167 |
self.commandFrame.pack(side=TOP, |
| 168 |
expand=NO, |
| 169 |
fill=BOTH, |
| 170 |
padx=1, |
| 171 |
pady=1) |
| 172 |
|
| 173 |
def destroyCommandArea(self): |
| 174 |
self.app.destroycomponent('commandframe') |
| 175 |
|
| 176 |
def createMessageBar(self): |
| 177 |
self.messageBar = Pmw.MessageBar(self.commandFrame, entry_width = 25, |
| 178 |
entry_relief='sunken', entry_borderwidth=1) |
| 179 |
|
| 180 |
|
| 181 |
self.abortButton=Button(self.commandFrame, |
| 182 |
text='Abort',highlightthickness=0, |
| 183 |
command=lambda s=self:self.abort(),padx=0,pady=0) |
| 184 |
self.abortButton.pack(side=RIGHT,fill=BOTH,expand=YES) |
| 185 |
|
| 186 |
self.abortButton=Button(self.commandFrame, |
| 187 |
text='Rebuild',highlightthickness=0, |
| 188 |
|
| 189 |
command=lambda s=self:self.rebuild(),padx=0,pady=0) |
| 190 |
self.abortButton.pack(side=RIGHT,fill=BOTH,expand=YES) |
| 191 |
|
| 192 |
self.messageBar.pack(side=BOTTOM, anchor=W, fill=X, expand=1) |
| 193 |
self.balloon.configure(statuscommand = self.messageBar.helpmessage) |
| 194 |
|
| 195 |
def destroyMessageBar(self): |
| 196 |
self.messageBar.destroy() |
| 197 |
|
| 198 |
def get_current_session_file(self): |
| 199 |
session_file = self.cmd.get_setting_text("session_file") |
| 200 |
session_file = session_file.replace("\\","/") |
| 201 |
return session_file |
| 202 |
|
| 203 |
def set_current_session_file(self, session_file): |
| 204 |
session_file = session_file.replace("\\","/") |
| 205 |
self.cmd.set("session_file",session_file) |
| 206 |
|
| 207 |
def confirm_quit(self,e=None): |
| 208 |
if self.cmd.get_setting_boolean("session_changed"): |
| 209 |
session_file = self.get_current_session_file() |
| 210 |
if session_file != '': |
| 211 |
message = "Save the current session '%s'?"%os.path.split(session_file)[1] |
| 212 |
else: |
| 213 |
message = "Save the current session?" |
| 214 |
check = tkMessageBox._show("Save Session", message, |
| 215 |
tkMessageBox.QUESTION, tkMessageBox.YESNOCANCEL) |
| 216 |
if check==tkMessageBox.YES: |
| 217 |
if self.session_save(): |
| 218 |
self.quit_app() |
| 219 |
elif check==tkMessageBox.NO: |
| 220 |
self.quit_app() |
| 221 |
else: |
| 222 |
self.quit_app() |
| 223 |
|
| 224 |
def quit_app(self): |
| 225 |
self.cmd.log_close() |
| 226 |
self.cmd.quit() |
| 227 |
|
| 228 |
|
| 229 |
def buttonAdd(self,frame,text,cmmd): |
| 230 |
newBtn=Button(frame, |
| 231 |
text=text,highlightthickness=0, |
| 232 |
command=cmmd,padx=0,pady=0) |
| 233 |
newBtn.pack(side=LEFT,fill=BOTH,expand=YES) |
| 234 |
return newBtn |
| 235 |
|
| 236 |
def get_view(self): |
| 237 |
self.cmd.get_view(2, quiet=0) |
| 238 |
try: |
| 239 |
str = self.cmd.get_view(3,quiet=1) |
| 240 |
self.root.clipboard_clear() |
| 241 |
self.root.clipboard_append(str) |
| 242 |
self.last_view = str |
| 243 |
self.app.selection_clear() |
| 244 |
self.app.selection_own() |
| 245 |
self.app.selection_handle(lambda a,b,s=self:s.last_view) |
| 246 |
print(" PyMOL: Viewing matrix copied to clipboard.") |
| 247 |
except: |
| 248 |
traceback.print_exc() |
| 249 |
|
| 250 |
def createButtons(self): |
| 251 |
self.buttonArea = Frame(self.root) |
| 252 |
self.buttonArea.pack(side=TOP, anchor=W) |
| 253 |
|
| 254 |
row1 = self.app.createcomponent('row1', (), None, |
| 255 |
Frame,self.commandFrame,bd=0) |
| 256 |
row1.pack(side=TOP,fill=BOTH,expand=YES) |
| 257 |
btn_reset = self.buttonAdd(row1,'Reset',lambda s=self: s.cmd.do("_ reset")) |
| 258 |
btn_reset = self.buttonAdd(row1,'Zoom',lambda s=self: s.cmd.do("_ zoom animate=-1")) |
| 259 |
btn_orient = self.buttonAdd(row1,'Orient',lambda s=self: s.cmd.do("_ orient animate=1")) |
| 260 |
btn_rtrace = self.buttonAdd(row1,'Draw',lambda s=self: s.cmd.do("_ draw")) |
| 261 |
btn_rtrace = self.buttonAdd(row1,'Ray',lambda s=self: s.cmd.do("_ ray async=1")) |
| 262 |
|
| 263 |
row2 = self.app.createcomponent('row2', (), None, |
| 264 |
Frame,self.commandFrame,bd=0) |
| 265 |
row2.pack(side=TOP,fill=BOTH,expand=YES) |
| 266 |
btn_unpick = self.buttonAdd(row2,'Unpick',lambda s=self: s.cmd.do("_ unpick")) |
| 267 |
btn_hidesele = self.buttonAdd(row2,'Deselect', lambda: self.cmd.do("_ deselect")) |
| 268 |
btn_reset = self.buttonAdd(row2,'Rock',lambda s=self: s.cmd.do("_ rock")) |
| 269 |
btn_getview = self.buttonAdd(row2,'Get View',lambda s=self: s.get_view()) |
| 270 |
|
| 271 |
|
| 272 |
row3 = self.app.createcomponent('row3', (), None, |
| 273 |
Frame,self.commandFrame,bd=0) |
| 274 |
row3.pack(side=TOP,fill=BOTH,expand=YES) |
| 275 |
btn_rewind = self.buttonAdd(row3,'|<',lambda s=self: s.cmd.do("_ rewind")) |
| 276 |
btn_back = self.buttonAdd(row3,'<',lambda s=self: s.cmd.do("_ backward")) |
| 277 |
btn_stop = self.buttonAdd(row3,'Stop',lambda s=self: s.cmd.do("_ mstop")) |
| 278 |
btn_play = self.buttonAdd(row3,'Play',lambda s=self: s.cmd.do("_ mplay")) |
| 279 |
btn_forward = self.buttonAdd(row3,'>',lambda s=self: s.cmd.do("_ forward")) |
| 280 |
btn_last = self.buttonAdd(row3,'>|',lambda s=self: s.cmd.do("_ ending")) |
| 281 |
btn_ccache = self.buttonAdd(row3,'MClear',lambda s=self: s.cmd.do("_ mclear")) |
| 282 |
|
| 283 |
row4 = self.app.createcomponent('row4', (), None, |
| 284 |
Frame,self.commandFrame,bd=0) |
| 285 |
row4.pack(side=TOP,fill=BOTH,expand=YES) |
| 286 |
self.cmdB = self.buttonAdd(row4,'Command', |
| 287 |
lambda s=self: |
| 288 |
s.toggleFrame(s.cmdFrame)) |
| 289 |
self.buildB = self.buttonAdd(row4,'Builder', |
| 290 |
lambda s=self: |
| 291 |
s.toggleFrame(s.buildFrame)) |
| 292 |
self.volB = self.buttonAdd(row4, 'Volume', |
| 293 |
self.newVolumeFrame) |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
def newVolumeFrame(self): |
| 298 |
volumes = self.cmd.get_names_of_type("object:volume", public=1) |
| 299 |
if not volumes: |
| 300 |
return |
| 301 |
if len(volumes) == 1: |
| 302 |
self.cmd.volume_panel(volumes[0]) |
| 303 |
return |
| 304 |
def callback(): |
| 305 |
sels = listbox.getcurselection() |
| 306 |
if sels: |
| 307 |
self.cmd.volume_panel(sels[0]) |
| 308 |
window.destroy() |
| 309 |
title = 'Select a volume object' |
| 310 |
window = Toplevel(self.app.root) |
| 311 |
window.title(title) |
| 312 |
listbox = Pmw.ScrolledListBox(window, |
| 313 |
labelpos='nw', |
| 314 |
label_text=title, |
| 315 |
items=volumes, |
| 316 |
selectioncommand=callback) |
| 317 |
listbox.pack(padx=5, pady=5) |
| 318 |
x, y = window.winfo_pointerxy() |
| 319 |
window.geometry('+%d+%d' % (x - 20, y - 20)) |
| 320 |
|
| 321 |
def destroyButtonArea(self): |
| 322 |
self.app.destroycomponent('row1') |
| 323 |
self.app.destroycomponent('row2') |
| 324 |
self.app.destroycomponent('row3') |
| 325 |
self.app.destroycomponent('row4') |
| 326 |
self.buttonArea.destroy() |
| 327 |
|
| 328 |
def my_show(self,win,center=1): |
| 329 |
win.show() |
| 330 |
|
| 331 |
def my_withdraw(self,win): |
| 332 |
if sys.platform!='linux2': |
| 333 |
win.withdraw() |
| 334 |
else: |
| 335 |
win.destroy() |
| 336 |
|
| 337 |
def my_activate(self,win,center=1,focus=None): |
| 338 |
if sys.platform!='linux2': |
| 339 |
win.activate() |
| 340 |
else: |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
if center: |
| 346 |
tw = win.winfo_reqwidth()+100 |
| 347 |
th = win.winfo_reqheight()+100 |
| 348 |
vw = win.winfo_vrootwidth() |
| 349 |
vh = win.winfo_vrootheight() |
| 350 |
x = max(0,(vw-tw)/2) |
| 351 |
y = max(0,(vh-tw)/2) |
| 352 |
win.geometry(newGeometry="+%d+%d"%(x,y)) |
| 353 |
win.deiconify() |
| 354 |
if focus!=None: |
| 355 |
focus.focus_set() |
| 356 |
win.mainloop() |
| 357 |
|
| 358 |
def my_deactivate(self,win): |
| 359 |
if sys.platform!='linux2': |
| 360 |
win.deactivate() |
| 361 |
else: |
| 362 |
win.destroy() |
| 363 |
|
| 364 |
def doAsync(self,cmmd): |
| 365 |
t = threading.Thread(target=_doAsync,args=(self.cmd,cmmd)) |
| 366 |
t.setDaemon(1) |
| 367 |
t.start() |
| 368 |
|
| 369 |
def command_get(self): |
| 370 |
return self.command.get() |
| 371 |
|
| 372 |
def command_set(self, v): |
| 373 |
return self.command.set(v) |
| 374 |
|
| 375 |
def command_set_cursor(self, i): |
| 376 |
self.entry.icursor(i) |
| 377 |
|
| 378 |
def dump(self,event): |
| 379 |
print(dir(event)) |
| 380 |
print(event.keysym, event.keycode) |
| 381 |
|
| 382 |
def createConsole(self): |
| 383 |
self.command = StringVar() |
| 384 |
self.lineCount = 0 |
| 385 |
self._setup_history() |
| 386 |
|
| 387 |
self.cmdFrame = Frame(self.dataArea) |
| 388 |
self.buildFrame = Builder(self.app, self.dataArea) |
| 389 |
|
| 390 |
self.toggleFrame(self.cmdFrame,startup=1) |
| 391 |
|
| 392 |
self.entryFrame = Frame(self.cmdFrame) |
| 393 |
self.entryFrame.pack(side=BOTTOM,expand=NO,fill=X) |
| 394 |
self.entry_label = Label(self.entryFrame, text="PyMOL>", padx=1, pady=1, justify=RIGHT) |
| 395 |
self.entry_label.pack(side=LEFT,expand=NO,fill=X) |
| 396 |
self.entry = Entry(self.entryFrame, justify=LEFT, width=70, |
| 397 |
textvariable=self.command) |
| 398 |
self.entry.pack(side=LEFT,expand=YES,fill=X) |
| 399 |
self.output = Pmw.ScrolledText(self.cmdFrame) |
| 400 |
self.output.pack(side=TOP, fill=BOTH, expand=YES) |
| 401 |
|
| 402 |
self.entry.bind('<Return>', lambda e, s=self: |
| 403 |
(s.doTypedCommand(s.command.get()), s.command.set(''))) |
| 404 |
self.entry.bind('<Tab>', lambda e, s=self: s.complete(e)) |
| 405 |
self.entry.bind('<Up>', lambda e, s=self: s.back()) |
| 406 |
self.entry.bind('<Down>', lambda e, s=self: s.forward()) |
| 407 |
self.entry.bind('<Control-Up>', lambda e: self.back_search()) |
| 408 |
self.root.protocol("WM_DELETE_WINDOW", lambda s=self: s.confirm_quit()) |
| 409 |
|
| 410 |
self.log_file = "log.pml" |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
text = self.output.component('text') |
| 420 |
self.text = text |
| 421 |
|
| 422 |
if sys.platform.startswith('win'): |
| 423 |
self.font = 'lucida console' |
| 424 |
self.my_fw_font=(self.font,8) |
| 425 |
self.fixedfont.configure(family=self.font, size=self.my_fw_font[1]) |
| 426 |
else: |
| 427 |
text.tk.call('tk','scaling',1) |
| 428 |
self.font = 'fixed' |
| 429 |
self.my_fw_font=(self.font,10) |
| 430 |
if sys.platform == 'darwin': |
| 431 |
self.fixedfont.configure(size=11) |
| 432 |
|
| 433 |
text.configure(width=74) |
| 434 |
|
| 435 |
self.balloon.bind(self.entry, '''Command Input Area |
| 436 |
|
| 437 |
Get the list of commands by hitting <TAB> |
| 438 |
|
| 439 |
Get the list of arguments for one command with a question mark: |
| 440 |
PyMOL> color ? |
| 441 |
|
| 442 |
Read the online help for a command with "help": |
| 443 |
PyMOL> help color |
| 444 |
|
| 445 |
Get autocompletion for many arguments by hitting <TAB> |
| 446 |
PyMOL> color ye<TAB> (will autocomplete "yellow") |
| 447 |
''') |
| 448 |
|
| 449 |
if self.app.allow_after: |
| 450 |
self.output.after(100,self.update_feedback) |
| 451 |
self.output.after(100,self.update_menus) |
| 452 |
|
| 453 |
self.output.pack(side=BOTTOM,expand=YES,fill=BOTH) |
| 454 |
self.app.bind(self.entry, 'Command Input Area') |
| 455 |
|
| 456 |
self.app.bind_all('<F1>',lambda e,s=self: s.cmd.do("cmd._special(1,0,0)")) |
| 457 |
self.app.bind_all('<F2>',lambda e,s=self: s.cmd.do("cmd._special(2,0,0)")) |
| 458 |
self.app.bind_all('<F3>',lambda e,s=self: s.cmd.do("cmd._special(3,0,0)")) |
| 459 |
self.app.bind_all('<F4>',lambda e,s=self: s.cmd.do("cmd._special(4,0,0)")) |
| 460 |
self.app.bind_all('<F5>',lambda e,s=self: s.cmd.do("cmd._special(5,0,0)")) |
| 461 |
self.app.bind_all('<F6>',lambda e,s=self: s.cmd.do("cmd._special(6,0,0)")) |
| 462 |
self.app.bind_all('<F7>',lambda e,s=self: s.cmd.do("cmd._special(7,0,0)")) |
| 463 |
self.app.bind_all('<F8>',lambda e,s=self: s.cmd.do("cmd._special(8,0,0)")) |
| 464 |
self.app.bind_all('<F9>',lambda e,s=self: s.cmd.do("cmd._special(9,0,0)")) |
| 465 |
self.app.bind_all('<F10>',lambda e,s=self: s.cmd.do("cmd._special(10,0,0)")) |
| 466 |
self.app.bind_all('<F11>',lambda e,s=self: s.cmd.do("cmd._special(11,0,0)")) |
| 467 |
self.app.bind_all('<F12>',lambda e,s=self: s.cmd.do("cmd._special(12,0,0)")) |
| 468 |
self.app.bind_all('<Control-F1>',lambda e,s=self: s.cmd.do("cmd._special(1,0,0,2)")) |
| 469 |
self.app.bind_all('<Control-F2>',lambda e,s=self: s.cmd.do("cmd._special(2,0,0,2)")) |
| 470 |
self.app.bind_all('<Control-F3>',lambda e,s=self: s.cmd.do("cmd._special(3,0,0,2)")) |
| 471 |
self.app.bind_all('<Control-F4>',lambda e,s=self: s.cmd.do("cmd._special(4,0,0,2)")) |
| 472 |
self.app.bind_all('<Control-F5>',lambda e,s=self: s.cmd.do("cmd._special(5,0,0,2)")) |
| 473 |
self.app.bind_all('<Control-F6>',lambda e,s=self: s.cmd.do("cmd._special(6,0,0,2)")) |
| 474 |
self.app.bind_all('<Control-F7>',lambda e,s=self: s.cmd.do("cmd._special(7,0,0,2)")) |
| 475 |
self.app.bind_all('<Control-F8>',lambda e,s=self: s.cmd.do("cmd._special(8,0,0,2)")) |
| 476 |
self.app.bind_all('<Control-F9>',lambda e,s=self: s.cmd.do("cmd._special(9,0,0,2)")) |
| 477 |
self.app.bind_all('<Control-F10>',lambda e,s=self: s.cmd.do("cmd._special(10,0,0,2)")) |
| 478 |
self.app.bind_all('<Control-F11>',lambda e,s=self: s.cmd.do("cmd._special(11,0,0,2)")) |
| 479 |
self.app.bind_all('<Control-F12>',lambda e,s=self: s.cmd.do("cmd._special(12,0,0,2)")) |
| 480 |
|
| 481 |
self.entry.bind('<Prior>',lambda e,s=self: s.cmd.do("cmd._special(104,0,0)")) |
| 482 |
self.entry.bind('<Next>',lambda e,s=self: s.cmd.do("cmd._special(105,0,0)")) |
| 483 |
self.entry.bind('<Control-Prior>',lambda e,s=self: s.cmd.do("cmd._special(104,0,0,2)")) |
| 484 |
self.entry.bind('<Control-Next>',lambda e,s=self: s.cmd.do("cmd._special(105,0,0,2)")) |
| 485 |
self.entry.bind('<Home>',lambda e,s=self: s.cmd.do("cmd._special(106,0,0)")) |
| 486 |
self.entry.bind('<End>',lambda e,s=self: s.cmd.do("cmd._special(107,0,0)")) |
| 487 |
|
| 488 |
def update_feedback(self): |
| 489 |
feedback = self.cmd._get_feedback(self.cmd) |
| 490 |
if feedback!=None: |
| 491 |
self.text.configure(state='normal') |
| 492 |
for a in feedback: |
| 493 |
self.output.insert(END,"\n") |
| 494 |
self.output.insert(END,a) |
| 495 |
self.output.see(END) |
| 496 |
self.lineCount = self.lineCount + 1 |
| 497 |
if self.lineCount > 10000: |
| 498 |
self.output.delete('0.0','%i.%i' % (self.lineCount-5000,0)) |
| 499 |
self.lineCount=5000 |
| 500 |
self.text.configure(state='disabled') |
| 501 |
progress = self.cmd.get_progress() |
| 502 |
if progress>=0.0: |
| 503 |
|
| 504 |
self.messageBar.message("busy","Progress %d%%..."%int(progress*100)) |
| 505 |
else: |
| 506 |
|
| 507 |
self.messageBar.resetmessages("busy") |
| 508 |
if self.app.allow_after: |
| 509 |
if feedback == None: |
| 510 |
self.output.after(10,self.update_feedback) |
| 511 |
else: |
| 512 |
self.output.after(100,self.update_feedback) |
| 513 |
|
| 514 |
def abort(self): |
| 515 |
self.cmd.interrupt() |
| 516 |
|
| 517 |
|
| 518 |
def rebuild(self): |
| 519 |
self.doAsync("_ rebuild") |
| 520 |
|
| 521 |
def toggleFrame(self, frame, startup=0): |
| 522 |
if frame not in self.dataArea.slaves(): |
| 523 |
|
| 524 |
for f in self.dataArea.slaves(): |
| 525 |
f.pack_forget() |
| 526 |
|
| 527 |
frame.pack(side=BOTTOM, fill=BOTH, expand=YES) |
| 528 |
else: |
| 529 |
|
| 530 |
if frame != self.cmdFrame: |
| 531 |
frame.pack_forget() |
| 532 |
|
| 533 |
|
| 534 |
self.cmdFrame.pack(side=BOTTOM, fill=BOTH, expand=YES) |
| 535 |
frame = self.cmdFrame |
| 536 |
if not startup: |
| 537 |
if frame == self.cmdFrame: |
| 538 |
if self.edit_mode != None: |
| 539 |
self.cmd.edit_mode(self.edit_mode) |
| 540 |
self.edit_mode = None |
| 541 |
if self.auto_overlay != None: |
| 542 |
self.cmd.set("auto_overlay",self.auto_overlay) |
| 543 |
self.auto_overlay = None |
| 544 |
if self.valence != None: |
| 545 |
self.cmd.set("valence",self.valence) |
| 546 |
elif frame == self.buildFrame: |
| 547 |
frame.deferred_activate() |
| 548 |
if "Editing" not in self.cmd.get("button_mode_name"): |
| 549 |
self.cmd.edit_mode(1) |
| 550 |
self.edit_mode = 0 |
| 551 |
self.valence = self.cmd.get("valence") |
| 552 |
self.cmd.set("valence","1") |
| 553 |
self.auto_overlay = self.cmd.get("auto_overlay") |
| 554 |
self.cmd.set("auto_overlay",1) |
| 555 |
|
| 556 |
def update_menus(self): |
| 557 |
self.setting.refresh() |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
if False: |
| 562 |
|
| 563 |
if len(self.cmd.get_names_of_type("object:volume",public=1))>0: |
| 564 |
self.volB.config(state=NORMAL) |
| 565 |
else: |
| 566 |
self.volB.config(state=DISABLED) |
| 567 |
|
| 568 |
if self.app.allow_after: |
| 569 |
self.output.after(500,self.update_menus) |
| 570 |
|
| 571 |
def file_open(self,tutorial=0): |
| 572 |
|
| 573 |
if not tutorial: |
| 574 |
initdir = self.initialdir |
| 575 |
ftypes = self.app.getLoadableFileTypes() |
| 576 |
else: |
| 577 |
initdir = os.environ['TUT'] |
| 578 |
|
| 579 |
ftypes = [("Tutorial Data","*.pdb"),] |
| 580 |
if TkVersion>8.3: |
| 581 |
ofile_list = askopenfilename(initialdir = initdir, |
| 582 |
filetypes=ftypes, |
| 583 |
multiple=1) |
| 584 |
else: |
| 585 |
ofile_list = [ askopenfilename(initialdir = initdir, |
| 586 |
filetypes=ftypes) ] |
| 587 |
|
| 588 |
for ofile in ofile_list: |
| 589 |
if len(ofile): |
| 590 |
if not tutorial: |
| 591 |
self.initialdir = os.path.dirname(ofile) |
| 592 |
try: |
| 593 |
if ofile[-4:].lower() == '.pse' and ofile != self.save_file: |
| 594 |
self.save_file = '' |
| 595 |
self.cmd.do('_ /cmd.load(%s, quiet=0)' % repr(ofile)) |
| 596 |
except self.pymol.CmdException: |
| 597 |
print("Error: unable to open file '%s'"%ofile) |
| 598 |
|
| 599 |
def log_open(self): |
| 600 |
sfile = asksaveasfilename(initialfile = self.log_file, |
| 601 |
initialdir = self.initialdir, |
| 602 |
filetypes=[ |
| 603 |
("PyMOL Script","*.pml"), |
| 604 |
("PyMOL Program","*.pym"), |
| 605 |
("Python Program","*.py"), |
| 606 |
("All Files","*.*"), |
| 607 |
("All Files","*"), |
| 608 |
]) |
| 609 |
if len(sfile): |
| 610 |
self.initialdir = os.path.dirname(sfile) |
| 611 |
self.log_file = os.path.basename(sfile) |
| 612 |
self.cmd.log_open(sfile) |
| 613 |
|
| 614 |
def log_resume(self,append_only=0): |
| 615 |
ofile = askopenfilename(initialdir = os.getcwd(), |
| 616 |
filetypes=[("All Resumable","*.pml"), |
| 617 |
("All Resumable","*.pym"), |
| 618 |
("All Resumable","*.py"), |
| 619 |
("PyMOL Script","*.pml"), |
| 620 |
("PyMOL Program","*.pym"), |
| 621 |
("Python Program","*.py"), |
| 622 |
("All Files","*.*"), |
| 623 |
("All Files","*"), |
| 624 |
]) |
| 625 |
if len(ofile): |
| 626 |
self.initialdir = os.path.dirname(ofile) |
| 627 |
self.log_file = os.path.basename(ofile) |
| 628 |
|
| 629 |
self.cmd.resume(ofile) |
| 630 |
|
| 631 |
def log_append(self,append_only=0): |
| 632 |
ofile = askopenfilename(initialdir = os.getcwd(), |
| 633 |
filetypes=[("All Appendable","*.pml"), |
| 634 |
("All Appendable","*.pym"), |
| 635 |
("All Appendable","*.py"), |
| 636 |
("PyMOL Script","*.pml"), |
| 637 |
("PyMOL Program","*.pym"), |
| 638 |
("Python Program","*.py"), |
| 639 |
("All Files","*.*"), |
| 640 |
("All Files","*"), |
| 641 |
]) |
| 642 |
if len(ofile): |
| 643 |
self.initialdir = os.path.dirname(ofile) |
| 644 |
self.log_file = os.path.basename(ofile) |
| 645 |
|
| 646 |
self.cmd.log_open(ofile,'a') |
| 647 |
|
| 648 |
def session_save(self): |
| 649 |
self.save_file = self.get_current_session_file() |
| 650 |
if self.save_file!='': |
| 651 |
self.cmd.log("save %s,format=pse\n"%(self.save_file), |
| 652 |
"cmd.save('%s',format='pse')\n"%(self.save_file)) |
| 653 |
|
| 654 |
|
| 655 |
self.cmd.do("_ cmd.save('''%s''','','pse',quiet=0)"%self.save_file) |
| 656 |
self.cmd.do("_ cmd.set('session_changed',0)") |
| 657 |
return 1 |
| 658 |
else: |
| 659 |
return self.session_save_as() |
| 660 |
|
| 661 |
def session_save_as(self): |
| 662 |
(self.initialdir, self.save_file) = os.path.split(self.get_current_session_file()) |
| 663 |
(save_file, def_ext) = os.path.splitext(self.save_file) |
| 664 |
sfile = asksaveasfilename(defaultextension = _def_ext(def_ext), |
| 665 |
initialfile = save_file, |
| 666 |
initialdir = self.initialdir, |
| 667 |
filetypes=[ |
| 668 |
("PyMOL Session File","*.pse"), |
| 669 |
("PyMOL Show File","*.psw"), |
| 670 |
]) |
| 671 |
if len(sfile): |
| 672 |
if re.search(r"\.pse$|\.PSE$|\.psw$|\.PSW$",sfile)==None: |
| 673 |
sfile=sfile+".pse" |
| 674 |
self.initialdir = os.path.dirname(sfile) |
| 675 |
self.cmd.log("save %s,format=pse\n"%(sfile), |
| 676 |
"cmd.save('%s',format='pse')\n"%(sfile)) |
| 677 |
|
| 678 |
|
| 679 |
self.save_file = sfile |
| 680 |
|
| 681 |
self.set_current_session_file(self.save_file) |
| 682 |
|
| 683 |
self.cmd.do("_ cmd.save('''%s''','','pse',quiet=0)"%self.save_file) |
| 684 |
self.cmd.do("_ cmd.set('session_changed',0)") |
| 685 |
return 1 |
| 686 |
else: |
| 687 |
return 0 |
| 688 |
|
| 689 |
|
| 690 |
def file_save(self): |
| 691 |
""" |
| 692 |
File->Save Molecule, now with filtering |
| 693 |
""" |
| 694 |
def command(result): |
| 695 |
if result == 'OK': |
| 696 |
self.file_save2( |
| 697 |
dialog.getcurselection(), |
| 698 |
multiple_files_option.getvalue(), |
| 699 |
states_option.getvalue()) |
| 700 |
self.my_withdraw(dialog) |
| 701 |
|
| 702 |
def update_save_listbox(): |
| 703 |
lst = self.cmd.get_names('public') |
| 704 |
searchstr = filter_entry.getvalue() |
| 705 |
|
| 706 |
if searchstr: |
| 707 |
lst = [x for x in lst if searchstr in x] |
| 708 |
|
| 709 |
dialog.component("scrolledlist").setlist(lst) |
| 710 |
|
| 711 |
dialog = Pmw.SelectionDialog(self.root, |
| 712 |
title="Save", |
| 713 |
buttons = ('OK', 'Cancel'), |
| 714 |
defaultbutton='OK', |
| 715 |
scrolledlist_labelpos=N, |
| 716 |
scrolledlist_listbox_selectmode=EXTENDED, |
| 717 |
label_text='Which object or selection would you like to save?', |
| 718 |
scrolledlist_items = (), |
| 719 |
command = command) |
| 720 |
|
| 721 |
filter_entry = Pmw.EntryField(dialog.interior(), |
| 722 |
labelpos='w', |
| 723 |
modifiedcommand=update_save_listbox, |
| 724 |
validate=None, |
| 725 |
value="", |
| 726 |
label_text="Filter:") |
| 727 |
filter_entry.pack(pady=6, fill='x', expand=0, padx=10) |
| 728 |
|
| 729 |
multiple_files_option = Pmw.RadioSelect( dialog.interior(), |
| 730 |
labelpos='w', |
| 731 |
orient='vertical', |
| 732 |
selectmode='single', |
| 733 |
label_text="Save to...", |
| 734 |
buttontype="radiobutton", |
| 735 |
) |
| 736 |
multiple_files_option.add("one file") |
| 737 |
multiple_files_option.add("multiple files") |
| 738 |
multiple_files_option.invoke("one file") |
| 739 |
multiple_files_option.pack(side='left', pady=8) |
| 740 |
|
| 741 |
|
| 742 |
states_option = Pmw.RadioSelect( dialog.interior(), |
| 743 |
labelpos='w', |
| 744 |
orient='vertical', |
| 745 |
selectmode='single', |
| 746 |
label_text='Saved state...', |
| 747 |
buttontype="radiobutton" |
| 748 |
) |
| 749 |
states_option.add("all") |
| 750 |
states_option.add("global") |
| 751 |
states_option.add("object's current") |
| 752 |
states_option.invoke("global") |
| 753 |
states_option.pack(side='right', pady=8) |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
update_save_listbox() |
| 759 |
|
| 760 |
if len(dialog.component('scrolledlist').get()): |
| 761 |
|
| 762 |
listbox = dialog.component('scrolledlist') |
| 763 |
listbox.selection_set(0) |
| 764 |
|
| 765 |
self.my_show(dialog) |
| 766 |
|
| 767 |
def file_save2(self, sels, multiple_files_flag, state_flag): |
| 768 |
filetypes_save = [ |
| 769 |
("PDB File","*.pdb"), |
| 770 |
("MOL File","*.mol"), |
| 771 |
("MOL2 File","*.mol2"), |
| 772 |
("MMD File","*.mmd"), |
| 773 |
("PKL File","*.pkl"), |
| 774 |
("SDF File","*.sdf"), |
| 775 |
("PDBx/mmCIF","*.cif"), |
| 776 |
("PQR","*.pqr"), |
| 777 |
("Maestro","*.mae"), |
| 778 |
("XYZ","*.xyz"), |
| 779 |
] |
| 780 |
if True: |
| 781 |
|
| 782 |
if multiple_files_flag == "one file" and len(sels)>=1: |
| 783 |
sfile = '_'.join(sels) if len(sels) < 3 else \ |
| 784 |
sels[0] + '-and-%d-more' % (len(sels) - 1) |
| 785 |
sfile = asksaveasfilename(defaultextension = _def_ext(".pdb"), |
| 786 |
initialfile = sfile, |
| 787 |
initialdir = self.initialdir, |
| 788 |
filetypes=filetypes_save) |
| 789 |
if len(sfile): |
| 790 |
|
| 791 |
self.initialdir = os.path.dirname(sfile) |
| 792 |
save_sele = ' or '.join(["("+str(x)+")" for x in sels]) |
| 793 |
self.cmd.log("save %s,(%s)\n"%(sfile,save_sele), |
| 794 |
"cmd.save('%s','(%s)')\n"%(sfile,save_sele)) |
| 795 |
if state_flag == "all": |
| 796 |
self.cmd.save(sfile,"(%s)"%save_sele,state=0,quiet=0) |
| 797 |
elif state_flag == "object's current": |
| 798 |
ap = 0 |
| 799 |
for sel in sels: |
| 800 |
s = int(self.cmd.get("state", str(sel))) |
| 801 |
self.cmd.multisave(sfile,str(sel),state=s, quiet=0, append=ap) |
| 802 |
ap = 1 |
| 803 |
else: |
| 804 |
self.cmd.save(sfile,"(%s)"%save_sele,quiet=0) |
| 805 |
return |
| 806 |
else: |
| 807 |
|
| 808 |
|
| 809 |
for curName in sels: |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
doSplit=False |
| 818 |
if state_flag=='all': |
| 819 |
stateSave = "0" |
| 820 |
if len(sels)==1: |
| 821 |
|
| 822 |
doSplit=True |
| 823 |
elif state_flag=='global': |
| 824 |
stateSave = self.cmd.get_state() |
| 825 |
elif state_flag=="object's current": |
| 826 |
stateSave = int(self.cmd.get("state",curName)) |
| 827 |
|
| 828 |
else: |
| 829 |
stateSave = "state=", self.cmd.get_state() |
| 830 |
|
| 831 |
if True: |
| 832 |
sfile = asksaveasfilename(defaultextension = _def_ext(".pdb"), |
| 833 |
initialfile = curName, |
| 834 |
initialdir = self.initialdir, |
| 835 |
filetypes = filetypes_save) |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
if len(sfile): |
| 840 |
|
| 841 |
self.initialdir = os.path.dirname(sfile) |
| 842 |
save_sele = str("("+curName+")") |
| 843 |
|
| 844 |
if doSplit: |
| 845 |
|
| 846 |
s = self.cmd.count_states(save_sele) |
| 847 |
for stateSave in range(1,int(s)+1): |
| 848 |
save_file = sfile |
| 849 |
|
| 850 |
inter = "_state" + str(stateSave).zfill(len(str(s))+1) |
| 851 |
|
| 852 |
g = re.search(r"(.*)(\..*)$", save_file) |
| 853 |
if g!=None: |
| 854 |
|
| 855 |
save_file = g.groups()[0] + inter + g.groups()[1] |
| 856 |
else: |
| 857 |
|
| 858 |
|
| 859 |
save_file = save_file + inter |
| 860 |
|
| 861 |
self.cmd.log("save %s,(%s)\n"%(save_file,save_sele), |
| 862 |
"cmd.save('%s','(%s)', state='%s')\n"%(save_file,save_sele,stateSave)) |
| 863 |
self.cmd.save(save_file,"(%s)"%save_sele,state=stateSave,quiet=0) |
| 864 |
else: |
| 865 |
save_file = sfile |
| 866 |
|
| 867 |
|
| 868 |
self.cmd.log("save %s,(%s)\n"%(save_file,save_sele), |
| 869 |
"cmd.save('%s','(%s)', state='%s')\n"%(save_file,save_sele,stateSave)) |
| 870 |
self.cmd.save(save_file,"(%s)"%save_sele,state=stateSave,quiet=0) |
| 871 |
|
| 872 |
|
| 873 |
def edit_pymolrc(self): |
| 874 |
from pmg_tk import TextEditor |
| 875 |
TextEditor.edit_pymolrc(self) |
| 876 |
|
| 877 |
def file_run(self): |
| 878 |
ofile = askopenfilename(initialdir = os.getcwd(), |
| 879 |
filetypes=[("All Runnable","*.pml"), |
| 880 |
("All Runnable","*.pym"), |
| 881 |
("All Runnable","*.py"), |
| 882 |
("All Runnable","*.pyc"), |
| 883 |
("PyMOL Script","*.pml"), |
| 884 |
("Python Program","*.py"), |
| 885 |
("Python Program","*.pyc"), |
| 886 |
("PyMOL Program","*.pym"), |
| 887 |
("All Files","*.*"), |
| 888 |
("All Files","*"), |
| 889 |
]) |
| 890 |
if len(ofile): |
| 891 |
self.__script__ = ofile |
| 892 |
if re.search(r"\.pym*$|\.PYM*$",ofile): |
| 893 |
self.cmd.do("run "+ofile); |
| 894 |
else: |
| 895 |
self.cmd.do("@"+ofile); |
| 896 |
|
| 897 |
def file_save_png(self): |
| 898 |
sfile = asksaveasfilename(defaultextension = _def_ext(".png"), |
| 899 |
initialdir = self.initialdir, |
| 900 |
filetypes=[("PNG File","*.png")]) |
| 901 |
if len(sfile): |
| 902 |
self.initialdir = os.path.dirname(sfile) |
| 903 |
self.cmd.log("png %s\n"%sfile,"cmd.png('%s')\n"%sfile) |
| 904 |
self.cmd.png(sfile,quiet=0) |
| 905 |
|
| 906 |
def file_save_wrl(self): |
| 907 |
sfile = asksaveasfilename(defaultextension = _def_ext(".wrl"), |
| 908 |
initialdir = self.initialdir, |
| 909 |
filetypes=[("VRML 2 WRL File","*.wrl")]) |
| 910 |
if len(sfile): |
| 911 |
self.initialdir = os.path.dirname(sfile) |
| 912 |
self.cmd.log("save %s\n"%sfile,"cmd.save('%s')\n"%sfile) |
| 913 |
self.cmd.save(sfile,quiet=0) |
| 914 |
|
| 915 |
def file_save_dae(self): |
| 916 |
sfile = asksaveasfilename(defaultextension = _def_ext(".dae"), |
| 917 |
initialdir = self.initialdir, |
| 918 |
filetypes=[("COLLADA File","*.dae")]) |
| 919 |
if len(sfile): |
| 920 |
self.initialdir = os.path.dirname(sfile) |
| 921 |
self.cmd.log("save %s\n"%sfile,"cmd.save('%s')\n"%sfile) |
| 922 |
self.cmd.save(sfile,quiet=0) |
| 923 |
|
| 924 |
def file_save_pov(self): |
| 925 |
sfile = asksaveasfilename(defaultextension = _def_ext(".pov"), |
| 926 |
initialdir = self.initialdir, |
| 927 |
filetypes=[("POV File","*.pov")]) |
| 928 |
if len(sfile): |
| 929 |
self.initialdir = os.path.dirname(sfile) |
| 930 |
self.cmd.log("save %s\n"%sfile,"cmd.save('%s')\n"%sfile) |
| 931 |
self.cmd.save(sfile,quiet=0) |
| 932 |
|
| 933 |
def file_save_mpeg(self): |
| 934 |
try: |
| 935 |
from pymol import mpeg_encode |
| 936 |
if not mpeg_encode.validate(): |
| 937 |
print("produce-error: Unable to validate pymol.mpeg_encode") |
| 938 |
raise |
| 939 |
except: |
| 940 |
tkMessageBox.showerror("Error", |
| 941 |
"MPEG encoder missing.\nThe FreeMOL add-ons may not be installed.") |
| 942 |
return |
| 943 |
|
| 944 |
def command(value): |
| 945 |
mQual = int(w_quality.get()) |
| 946 |
mode = 'ray' if w_ray.get() else 'draw' |
| 947 |
viewport = int(w_viewport[0].get()), int(w_viewport[1].get()) |
| 948 |
dialog.destroy() |
| 949 |
|
| 950 |
if value != 'OK': |
| 951 |
return |
| 952 |
|
| 953 |
sfile = asksaveasfilename(defaultextension = _def_ext(".mpg"), |
| 954 |
initialdir = self.initialdir, |
| 955 |
filetypes=[("MPEG movie file","*.mpg")]) |
| 956 |
if len(sfile): |
| 957 |
self.initialdir = os.path.dirname(sfile) |
| 958 |
mQual = self.cmd.get_setting_int("movie_quality") |
| 959 |
self.cmd.log("movie.produce %s,quality=%d,quiet=0\n"%(sfile,mQual), |
| 960 |
"cmd.movie.produce('''%s''',quality=%d,quiet=0)\n"%(sfile,mQual)) |
| 961 |
self.cmd.movie.produce(sfile, mode, quality=mQual, quiet=0, |
| 962 |
width=viewport[0], height=viewport[1]) |
| 963 |
|
| 964 |
dialog = Pmw.Dialog(title='Movie Settings', buttons=('OK', 'Cancel'), |
| 965 |
defaultbutton='OK', command=command) |
| 966 |
parent = dialog.interior() |
| 967 |
gridkw = {'padx': 5, 'pady': 5, 'sticky': W, 'row': 0} |
| 968 |
|
| 969 |
Label(parent, text='Encoding Quality (0-100)',).grid(column=0, **gridkw) |
| 970 |
w_quality = Pmw.Counter(parent, |
| 971 |
entryfield_value=self.cmd.get_setting_int("movie_quality"), |
| 972 |
entryfield_validate={'validator': 'integer', 'min': 0, 'max': 100}) |
| 973 |
w_quality.grid(column=1, **gridkw) |
| 974 |
|
| 975 |
gridkw['row'] += 1 |
| 976 |
Label(parent, text='Ray Trace Frames').grid(column=0, **gridkw) |
| 977 |
w_ray = BooleanVar(parent, self.cmd.get_setting_boolean('ray_trace_frames')) |
| 978 |
Checkbutton(parent, variable=w_ray).grid(column=1, **gridkw) |
| 979 |
|
| 980 |
w_viewport = [] |
| 981 |
for text, value in zip(('Width', 'Height'), self.cmd.get_viewport()): |
| 982 |
gridkw['row'] += 1 |
| 983 |
Label(parent, text=text + ' (pixels)').grid(column=0, **gridkw) |
| 984 |
w = Pmw.Counter(parent, entryfield_value=value, entryfield_validate={'validator': 'integer', 'min': 0}) |
| 985 |
w.grid(column=1, **gridkw) |
| 986 |
w_viewport.append(w) |
| 987 |
|
| 988 |
def file_save_mpng(self): |
| 989 |
sfile = asksaveasfilename(initialdir = self.initialdir, |
| 990 |
filetypes=[("Numbered PNG Files","*.png")]) |
| 991 |
if len(sfile): |
| 992 |
self.initialdir = os.path.dirname(sfile) |
| 993 |
self.cmd.log("mpng %s\n"%sfile,"cmd.mpng('%s')\n"%sfile) |
| 994 |
self.cmd.mpng(sfile,modal=-1) |
| 995 |
|
| 996 |
def cat_terms(self): |
| 997 |
for path in [ "$PYMOL_PATH/LICENSE.txt", "$PYMOL_PATH/LICENSE.TXT", "$PYMOL_PATH/LICENSE" ]: |
| 998 |
path = self.pymol.cmd.exp_path(path) |
| 999 |
if os.path.exists(path): |
| 1000 |
print(open(path).read().strip()) |
| 1001 |
return |
| 1002 |
print(" Error: no license terms found.") |
| 1003 |
|
| 1004 |
def toggleClickThrough(self, toggle): |
| 1005 |
if toggle: |
| 1006 |
os.system( |
| 1007 |
"defaults write com.apple.x11 wm_click_through -bool true") |
| 1008 |
os.system( |
| 1009 |
"defaults write org.x.X11 wm_click_through -bool true") |
| 1010 |
os.system( |
| 1011 |
"defaults write com.apple.x11 wm_ffm -bool true") |
| 1012 |
os.system( |
| 1013 |
"defaults write org.x.X11 wm_ffm -bool true") |
| 1014 |
print("Enabled wm_click_through and wm_ffm.", end=' ') |
| 1015 |
else: |
| 1016 |
os.system( |
| 1017 |
"defaults write com.apple.x11 wm_click_through -bool false") |
| 1018 |
os.system( |
| 1019 |
"defaults write org.x.X11 wm_click_through -bool false") |
| 1020 |
os.system( |
| 1021 |
"defaults write com.apple.x11 wm_ffm -bool false") |
| 1022 |
os.system( |
| 1023 |
"defaults write org.x.X11 wm_ffm -bool false") |
| 1024 |
print("Disabled wm_click_through and wm_ffm.", end=' ') |
| 1025 |
print("Please restart X11.") |
| 1026 |
|
| 1027 |
def createMenuBar(self): |
| 1028 |
self.menuBar = Pmw.MenuBar(self.root, balloon=self.balloon, |
| 1029 |
hull_relief=RAISED, hull_borderwidth=1) |
| 1030 |
self.menuBar.pack(fill=X) |
| 1031 |
|
| 1032 |
addmenuitem = self.menuBar.addmenuitem |
| 1033 |
addcascademenu = self.menuBar.addcascademenu |
| 1034 |
|
| 1035 |
self.setting = Setting(self.app) |
| 1036 |
|
| 1037 |
def _addmenu(data, parent): |
| 1038 |
for item in data: |
| 1039 |
if item[0] == 'separator': |
| 1040 |
addmenuitem(parent, 'separator', '') |
| 1041 |
elif item[0] == 'menu': |
| 1042 |
label = item[1] |
| 1043 |
menulabel = parent + '/' + label |
| 1044 |
self.menuBar.addcascademenu(parent, menulabel, |
| 1045 |
label, label=label, tearoff=FALSE) |
| 1046 |
_addmenu(item[2], menulabel) |
| 1047 |
elif item[0] == 'command': |
| 1048 |
label = item[1] |
| 1049 |
command = item[2] |
| 1050 |
if command is None: |
| 1051 |
if DEBUG: |
| 1052 |
print('warning: skipping', label, parent) |
| 1053 |
else: |
| 1054 |
if isinstance(command, str): |
| 1055 |
command = lambda c=command: self.cmd.do(c) |
| 1056 |
addmenuitem(parent, 'command', label, label=label, command=command) |
| 1057 |
elif item[0] == 'check': |
| 1058 |
label = item[1] |
| 1059 |
var = getattr(self.setting, item[2]) |
| 1060 |
if len(item) > 4: |
| 1061 |
addmenuitem(parent, 'checkbutton', label, label=label, variable=var, onvalue=item[3], offvalue=item[4]) |
| 1062 |
else: |
| 1063 |
addmenuitem(parent, 'checkbutton', label, label=label, variable=var) |
| 1064 |
elif item[0] == 'radio': |
| 1065 |
label = item[1] |
| 1066 |
var = getattr(self.setting, item[2]) |
| 1067 |
value = item[3] |
| 1068 |
addmenuitem(parent, 'radiobutton', label=label, value=value, variable=var) |
| 1069 |
elif DEBUG: |
| 1070 |
print('error:', item) |
| 1071 |
|
| 1072 |
for _, label, data in self.get_menudata(): |
| 1073 |
assert _ == 'menu' |
| 1074 |
self.menuBar.addmenu(label, label, tearoff=TRUE) |
| 1075 |
_addmenu(data, label) |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
if sys.platform == 'win32' and self.app.pymol.invocation.options.incentive_product: |
| 1147 |
self.menuBar.addmenuitem('Edit', 'separator', '') |
| 1148 |
|
| 1149 |
self.menuBar.addmenuitem('Edit', 'command', |
| 1150 |
'Copy Image', |
| 1151 |
label='Copy Image to Clipboard', |
| 1152 |
command = lambda s=self:s.cmd.copy_image(quiet=0)) |
| 1153 |
|
| 1154 |
self.menuBar.addmenuitem('Edit', 'checkbutton', |
| 1155 |
'Auto-Copy Images', |
| 1156 |
label='Auto-Copy Images', |
| 1157 |
variable = self.setting.auto_copy_images, |
| 1158 |
) |
| 1159 |
|
| 1160 |
self.menuBar.addmenuitem('Edit', 'separator', '') |
| 1161 |
|
| 1162 |
self.menuBar.addmenuitem('Edit', 'command', |
| 1163 |
'To Copy Text: Use Ctrl-C in TclTk GUI', |
| 1164 |
label='To copy text use Ctrl-C in the TclTk GUI', |
| 1165 |
state='disabled', |
| 1166 |
command = None) |
| 1167 |
|
| 1168 |
self.menuBar.addmenuitem('Edit', 'command', |
| 1169 |
'To Paste Text, Use Ctrl-V in TclTk GUI', |
| 1170 |
label='To paste text use Ctrl-V in the TckTk GUI', |
| 1171 |
state='disabled', |
| 1172 |
command = None) |
| 1173 |
|
| 1174 |
if sys.platform == 'darwin': |
| 1175 |
self.menuBar.addmenuitem('Mouse', 'separator', '') |
| 1176 |
|
| 1177 |
self.menuBar.addcascademenu('Mouse', 'MacX11Focus', 'Mac OS X11', |
| 1178 |
label='Mac OS X11') |
| 1179 |
self.menuBar.addmenuitem('MacX11Focus', 'command', |
| 1180 |
'Enable Click Through', |
| 1181 |
label='Enable Click Through', |
| 1182 |
command = lambda s=self: |
| 1183 |
s.toggleClickThrough(1)) |
| 1184 |
|
| 1185 |
self.menuBar.addmenuitem('MacX11Focus', 'command', |
| 1186 |
'Disable Click Through', |
| 1187 |
label='Disable Click Through', |
| 1188 |
command = lambda s=self: |
| 1189 |
s.toggleClickThrough(0)) |
| 1190 |
|
| 1191 |
|
| 1192 |
index = self.pymol.setting.index_dict.get('scenes_changed') |
| 1193 |
self.setting.active_dict[index] = self.update_scene_menu |
| 1194 |
|
| 1195 |
def settings_edit_all_dialog(self): |
| 1196 |
SetEditor(self) |
| 1197 |
|
| 1198 |
def edit_colors_dialog(self): |
| 1199 |
ColorEditor(self) |
| 1200 |
|
| 1201 |
def update_scene_menu(self): |
| 1202 |
scene_list = self.cmd.get_scene_list() |
| 1203 |
for action in ['recall', 'clear']: |
| 1204 |
parent = 'Scene/' + action.capitalize() |
| 1205 |
self.menuBar.deletemenuitems(parent, 0, 999) |
| 1206 |
for k in scene_list: |
| 1207 |
self.menuBar.addmenuitem(parent, 'command', k, label=k, |
| 1208 |
command=lambda k=k, a=action: self.cmd.scene(k, a)) |
| 1209 |
parent = 'Scene/Store' |
| 1210 |
self.menuBar.deletemenuitems(parent, 0, 11) |
| 1211 |
for i in range(12): |
| 1212 |
k = 'F' + str(i + 1) |
| 1213 |
self.scene_F_keys[i].set(1 if k in scene_list else 0) |
| 1214 |
self.menuBar.addmenuitem(parent, 'checkbutton', k, label=k, |
| 1215 |
variable=self.scene_F_keys[i], |
| 1216 |
command=lambda k=k: self.cmd.scene(k, 'store')) |
| 1217 |
|
| 1218 |
def show_about(self): |
| 1219 |
Pmw.aboutversion(self.appversion) |
| 1220 |
Pmw.aboutcopyright(self.copyright) |
| 1221 |
Pmw.aboutcontact( |
| 1222 |
'For more information, browse to: %s\n or send email to: %s' %\ |
| 1223 |
(self.contactweb, self.contactemail)) |
| 1224 |
self.about = Pmw.AboutDialog(self.root, applicationname=self.appname) |
| 1225 |
self.my_activate(self.about) |
| 1226 |
self.about.withdraw() |
| 1227 |
|
| 1228 |
def createInterface(self): |
| 1229 |
|
| 1230 |
self.balloon = Pmw.Balloon(self.root) |
| 1231 |
|
| 1232 |
self.createMenuBar() |
| 1233 |
|
| 1234 |
self.app.menuBar = self.menuBar |
| 1235 |
|
| 1236 |
self.app.initializePlugins() |
| 1237 |
|
| 1238 |
self.createDataArea() |
| 1239 |
|
| 1240 |
self.createCommandArea() |
| 1241 |
|
| 1242 |
self.createButtons() |
| 1243 |
|
| 1244 |
self.createMessageBar() |
| 1245 |
|
| 1246 |
self.createConsole() |
| 1247 |
|
| 1248 |
def setup(self): |
| 1249 |
|
| 1250 |
|
| 1251 |
PMGSkin.setup(self) |
| 1252 |
|
| 1253 |
|
| 1254 |
self.root.title(self.appname) |
| 1255 |
|
| 1256 |
|
| 1257 |
self.createInterface() |
| 1258 |
|
| 1259 |
|
| 1260 |
self.app._hull.pack(side=LEFT, fill=BOTH, expand=YES, anchor=CENTER) |
| 1261 |
|
| 1262 |
|
| 1263 |
if hasattr(self,'entry'): self.entry.focus_set() |
| 1264 |
|
| 1265 |
def takedown(self): |
| 1266 |
self.destroyMessageBar() |
| 1267 |
self.destroyDataArea() |
| 1268 |
self.destroyCommandArea() |
| 1269 |
self.destroyButtonArea() |
| 1270 |
self.balloon.destroy() |
| 1271 |
self.menuBar.destroy() |
| 1272 |
|
| 1273 |
def __init__(self,app): |
| 1274 |
global root |
| 1275 |
root = app.root |
| 1276 |
|
| 1277 |
PMGSkin.__init__(self,app) |
| 1278 |
Normal.appversion = app.pymol.cmd.get_version()[0] |
| 1279 |
Normal.appversion += " Incentive Product" \ |
| 1280 |
if app.pymol.invocation.options.incentive_product else \ |
| 1281 |
" Open-Source" |
| 1282 |
self.app = app |
| 1283 |
self.save_file = '' |
| 1284 |
self.cmd = app.pymol.cmd |
| 1285 |
self.util = app.pymol.util |
| 1286 |
self.movie_command = None |
| 1287 |
self.movie_start = 1 |
| 1288 |
self.auto_overlay = None |
| 1289 |
self.edit_mode = None |
| 1290 |
self.valence = None |
| 1291 |
self._initialdir = '' |
| 1292 |
self.fixedfont = tkFont.nametofont('TkFixedFont') |
| 1293 |
self.scene_F_keys = [IntVar(root) for _ in range(12)] |
| 1294 |
|
| 1295 |
def __init__(app): |
| 1296 |
return Normal(app) |
| 1297 |
|
| 1298 |
|