Package gui :: Module menu
[hide private]
[frames] | no frames]

Source Code for Module gui.menu

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009 Michael Bieri                                            # 
  4  # Copyright (C) 2010-2012 Edward d'Auvergne                                   # 
  5  #                                                                             # 
  6  # This file is part of the program relax.                                     # 
  7  #                                                                             # 
  8  # relax is free software; you can redistribute it and/or modify               # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation; either version 2 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # relax is distributed in the hope that it will be useful,                    # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with relax; if not, write to the Free Software                        # 
 20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Module docstring. 
 25  """Module for the main relax menu bar.""" 
 26   
 27  # Python module imports. 
 28  import wx 
 29   
 30  # relax module imports. 
 31  from status import Status; status = Status() 
 32   
 33  # relax GUI module imports. 
 34  from gui import paths 
 35  from gui.components.menu import build_menu_item 
 36  from gui.user_functions import User_functions 
 37   
 38   
290   
291   
292   
293 -class Uf_menus:
294 """A class for the creation of specialised menu entries for the user functions.""" 295
296 - def __init__(self, parent=None, menu=None):
297 """Set up the menu entries. 298 299 @keyword parent: The parent window. 300 @type parent: wx.Window instance 301 @keyword menu: The menu to add to. 302 @type menu: wx.Menu instance 303 """ 304 305 # Store the args. 306 self.parent = parent 307 self.menu = menu 308 309 # The user functions. 310 user_functions = User_functions(self.parent) 311 312 # Initialise some data structures. 313 self.uf_names = {} 314 self.uf = {} 315 316 # Build the user function menus. 317 id = self.add_class(name="bmrb", text="&bmrb", icon=paths.icon_16x16.bmrb) 318 self.add_uf(parent_id=id, name="bmrb.citation", text="&citation", fn=user_functions.bmrb.citation) 319 320 id = self.add_class(name="bruker", text="&bruker", icon=paths.icon_16x16.bruker) 321 self.add_uf(parent_id=id, name="bruker.read", text="&read", icon=paths.icon_16x16.open, fn=user_functions.bruker.read) 322 323 id = self.add_class(name="deselect", text="&deselect", icon=None) 324 self.add_uf(parent_id=id, name="deselect.all", text="&all", icon=None, fn=user_functions.deselect.all) 325 self.add_uf(parent_id=id, name="deselect.read", text="&read", icon=paths.icon_16x16.open, fn=user_functions.deselect.read) 326 self.add_uf(parent_id=id, name="deselect.reverse", text="re&verse", icon=None, fn=user_functions.deselect.reverse) 327 self.add_uf(parent_id=id, name="deselect.spin", text="&spin", icon=paths.icon_16x16.spin, fn=user_functions.deselect.spin) 328 329 self.add_uf(parent_id=None, name="gpl", text="&gpl", icon=paths.icon_16x16.gnu_head, fn=user_functions.gpl.run) 330 331 id = self.add_class(name="grace", text="gra&ce", icon=paths.icon_16x16.grace) 332 self.add_uf(parent_id=id, name="grace.view", text="&view", icon=paths.icon_16x16.grace, fn=user_functions.grace.view) 333 self.add_uf(parent_id=id, name="grace.write", text="&write", icon=paths.icon_16x16.save, fn=user_functions.grace.write) 334 335 id = self.add_class(name="molecule", text="&molecule", icon=paths.icon_16x16.molecule) 336 self.add_uf(parent_id=id, name="molecule.copy", text="&copy", icon=paths.icon_16x16.copy, fn=user_functions.molecule.copy) 337 self.add_uf(parent_id=id, name="molecule.create", text="crea&te", icon=paths.icon_16x16.add, fn=user_functions.molecule.create) 338 self.add_uf(parent_id=id, name="molecule.delete", text="&delete", icon=paths.icon_16x16.remove, fn=user_functions.molecule.delete) 339 340 id = self.add_class(name="molmol", text="&molmol", icon=paths.icon_16x16.molmol) 341 self.add_uf(parent_id=id, name="molmol.clear_history", text="clear_&history", icon=None, fn=user_functions.molmol.clear_history) 342 self.add_uf(parent_id=id, name="molmol.command", text="&command", icon=None, fn=user_functions.molmol.command) 343 self.add_uf(parent_id=id, name="molmol.macro_apply", text="&macro_apply", icon=paths.icon_16x16.molmol, fn=user_functions.molmol.macro_apply) 344 self.add_uf(parent_id=id, name="molmol.macro_run", text="macro_&run", icon=paths.icon_16x16.open, fn=user_functions.molmol.macro_run) 345 self.add_uf(parent_id=id, name="molmol.macro_write", text="macro_&write", icon=paths.icon_16x16.save, fn=user_functions.molmol.macro_write) 346 self.add_uf(parent_id=id, name="molmol.ribbon", text="ri&bbon", icon=None, fn=user_functions.molmol.ribbon) 347 self.add_uf(parent_id=id, name="molmol.tensor_pdb", text="&tensor_pdb", icon=None, fn=user_functions.molmol.tensor_pdb) 348 self.add_uf(parent_id=id, name="molmol.view", text="&view", icon=None, fn=user_functions.molmol.view) 349 350 id = self.add_class(name="noe", text="&noe", icon=None) 351 self.add_uf(parent_id=id, name="noe.read_restraints", text="&read_restraints", icon=paths.icon_16x16.open, fn=user_functions.noe.read_restraints) 352 self.add_uf(parent_id=id, name="noe.spectrum_type", text="&spectrum_type", icon=None, fn=user_functions.noe.spectrum_type) 353 354 id = self.add_class(name="pipe", text="&pipe", icon=paths.icon_16x16.pipe) 355 self.add_uf(parent_id=id, name="pipe.copy", text="&copy", icon=paths.icon_16x16.copy, fn=user_functions.pipe.copy) 356 self.add_uf(parent_id=id, name="pipe.create", text="crea&te", icon=paths.icon_16x16.add, fn=user_functions.pipe.create) 357 self.add_uf(parent_id=id, name="pipe.delete", text="&delete", icon=paths.icon_16x16.remove, fn=user_functions.pipe.delete) 358 self.add_uf(parent_id=id, name="pipe.hybridise", text="&hybridise", icon=paths.icon_16x16.pipe_hybrid, fn=user_functions.pipe.hybridise) 359 self.add_uf(parent_id=id, name="pipe.switch", text="&switch", icon=paths.icon_16x16.pipe_switch, fn=user_functions.pipe.switch) 360 361 id = self.add_class(name="pymol", text="&pymol", icon=paths.icon_16x16.pymol) 362 self.add_uf(parent_id=id, name="pymol.clear_history", text="clear_&history", icon=None, fn=user_functions.pymol.clear_history) 363 self.add_uf(parent_id=id, name="pymol.command", text="&command", icon=None, fn=user_functions.pymol.command) 364 self.add_uf(parent_id=id, name="pymol.macro_apply", text="&macro_apply", icon=paths.icon_16x16.pymol, fn=user_functions.pymol.macro_apply) 365 self.add_uf(parent_id=id, name="pymol.macro_run", text="&macro_&run", icon=paths.icon_16x16.open, fn=user_functions.pymol.macro_run) 366 self.add_uf(parent_id=id, name="pymol.macro_write", text="macro_&write", icon=paths.icon_16x16.save, fn=user_functions.pymol.macro_write) 367 self.add_uf(parent_id=id, name="pymol.ribbon", text="ri&bbon", icon=None, fn=user_functions.pymol.ribbon) 368 self.add_uf(parent_id=id, name="pymol.tensor_pdb", text="&tensor_pdb", icon=None, fn=user_functions.pymol.tensor_pdb) 369 self.add_uf(parent_id=id, name="pymol.view", text="&view", icon=None, fn=user_functions.pymol.view) 370 371 id = self.add_class(name="relax_data", text="&relax_data", icon=paths.icon_16x16.relax_data) 372 self.add_uf(parent_id=id, name="relax_data.delete", text="&delete", icon=paths.icon_16x16.remove, fn=user_functions.relax_data.delete) 373 self.add_uf(parent_id=id, name="relax_data.read", text="&read", icon=paths.icon_16x16.open, fn=user_functions.relax_data.read) 374 375 id = self.add_class(name="relax_fit", text="relax_&fit", icon=None) 376 self.add_uf(parent_id=id, name="relax_fit.relax_time", text="&relax_time", icon=None, fn=user_functions.relax_fit.relax_time) 377 self.add_uf(parent_id=id, name="relax_fit.select_model", text="&select_model", icon=None, fn=user_functions.relax_fit.select_model) 378 379 id = self.add_class(name="residue", text="resid&ue", icon=paths.icon_16x16.residue) 380 self.add_uf(parent_id=id, name="residue.copy", text="&copy", icon=paths.icon_16x16.copy, fn=user_functions.residue.copy) 381 self.add_uf(parent_id=id, name="residue.create", text="crea&te", icon=paths.icon_16x16.add, fn=user_functions.residue.create) 382 self.add_uf(parent_id=id, name="residue.delete", text="&delete", icon=paths.icon_16x16.remove, fn=user_functions.residue.delete) 383 384 id = self.add_class(name="results", text="&results", icon=paths.icon_16x16.about_relax) 385 self.add_uf(parent_id=id, name="results.display", text="&display", icon=None, fn=user_functions.results.display) 386 self.add_uf(parent_id=id, name="results.read", text="&read", icon=paths.icon_16x16.open, fn=user_functions.results.read) 387 self.add_uf(parent_id=id, name="results.write", text="&write", icon=paths.icon_16x16.save, fn=user_functions.results.write) 388 389 self.add_uf(parent_id=None, name="script", text="s&cript", icon=paths.icon_16x16.uf_script, fn=user_functions.script.run) 390 391 id = self.add_class(name="select", text="se&lect", icon=None) 392 self.add_uf(parent_id=id, name="select.all", text="&all", icon=None, fn=user_functions.select.all) 393 self.add_uf(parent_id=id, name="select.read", text="&read", icon=paths.icon_16x16.open, fn=user_functions.select.read) 394 self.add_uf(parent_id=id, name="select.reverse", text="re&verse", icon=None, fn=user_functions.select.reverse) 395 self.add_uf(parent_id=id, name="select.spin", text="&spin", icon=paths.icon_16x16.spin, fn=user_functions.select.spin) 396 397 id = self.add_class(name="sequence", text="se&quence", icon=paths.icon_16x16.sequence) 398 self.add_uf(parent_id=id, name="sequence.copy", text="&copy", icon=paths.icon_16x16.copy, fn=user_functions.sequence.copy) 399 self.add_uf(parent_id=id, name="sequence.read", text="&read", icon=paths.icon_16x16.open, fn=user_functions.sequence.read) 400 self.add_uf(parent_id=id, name="sequence.write", text="&write", icon=paths.icon_16x16.save, fn=user_functions.sequence.write) 401 402 id = self.add_class(name="spectrum", text="s&pectrum", icon=None) 403 self.add_uf(parent_id=id, name="spectrum.baseplane_rmsd", text="&baseplane_rmsd", icon=None, fn=user_functions.spectrum.baseplane_rmsd) 404 self.add_uf(parent_id=id, name="spectrum.delete", text="&delete", icon=paths.icon_16x16.remove, fn=user_functions.spectrum.delete) 405 self.add_uf(parent_id=id, name="spectrum.error_analysis", text="&error_analysis", icon=None, fn=user_functions.spectrum.error_analysis) 406 self.add_uf(parent_id=id, name="spectrum.integration_points", text="&integration_points", icon=None, fn=user_functions.spectrum.integration_points) 407 self.add_uf(parent_id=id, name="spectrum.read_intensities", text="&read_intensities", icon=paths.icon_16x16.open, fn=user_functions.spectrum.read_intensities) 408 self.add_uf(parent_id=id, name="spectrum.replicated", text="&replicated", icon=None, fn=user_functions.spectrum.replicated) 409 410 id = self.add_class(name="spin", text="&spin", icon=paths.icon_16x16.spin) 411 self.add_uf(parent_id=id, name="spin.copy", text="&copy", icon=paths.icon_16x16.copy, fn=user_functions.spin.copy) 412 self.add_uf(parent_id=id, name="spin.create", text="crea&te", icon=paths.icon_16x16.add, fn=user_functions.spin.create) 413 self.add_uf(parent_id=id, name="spin.create_pseudo", text="create_&pseudo", icon=paths.icon_16x16.add, fn=user_functions.spin.create_pseudo) 414 self.add_uf(parent_id=id, name="spin.delete", text="&delete", icon=paths.icon_16x16.remove, fn=user_functions.spin.delete) 415 self.add_uf(parent_id=id, name="spin.display", text="displa&y", icon=None, fn=user_functions.spin.display) 416 self.add_uf(parent_id=id, name="spin.element", text="&element", icon=None, fn=user_functions.spin.element) 417 self.add_uf(parent_id=id, name="spin.name", text="&name", icon=None, fn=user_functions.spin.name) 418 self.add_uf(parent_id=id, name="spin.number", text="num&ber", icon=None, fn=user_functions.spin.number) 419 420 id = self.add_class(name="structure", text="s&tructure", icon=paths.icon_16x16.structure) 421 self.add_uf(parent_id=id, name="structure.create_diff_tensor_pdb", text="&create_diff_tensor_pdb", icon=None, fn=user_functions.structure.create_diff_tensor_pdb) 422 self.add_uf(parent_id=id, name="structure.create_vector_dist", text="&create_vector_dist", icon=None, fn=user_functions.structure.create_vector_dist) 423 self.add_uf(parent_id=id, name="structure.delete", text="&delete", icon=paths.icon_16x16.remove, fn=user_functions.structure.delete) 424 self.add_uf(parent_id=id, name="structure.get_pos", text="&get_pos", icon=None, fn=user_functions.structure.get_pos) 425 self.add_uf(parent_id=id, name="structure.load_spins", text="&load_spins", icon=paths.icon_16x16.spin, fn=user_functions.structure.load_spins) 426 self.add_uf(parent_id=id, name="structure.read_pdb", text="&read_pdb", icon=paths.icon_16x16.open, fn=user_functions.structure.read_pdb) 427 self.add_uf(parent_id=id, name="structure.read_xyz", text="&read_xyz", icon=paths.icon_16x16.open, fn=user_functions.structure.read_xyz) 428 self.add_uf(parent_id=id, name="structure.vectors", text="&vectors", icon=None, fn=user_functions.structure.vectors) 429 self.add_uf(parent_id=id, name="structure.write_pdb", text="&write_pdb", icon=paths.icon_16x16.save, fn=user_functions.structure.write_pdb) 430 431 self.add_uf(parent_id=None, name="sys_info", text="sys_&info", icon=paths.icon_16x16.help_about, fn=user_functions.sys_info.sys_info) 432 433 id = self.add_class(name="value", text="&value", icon=paths.icon_16x16.value) 434 self.add_uf(parent_id=id, name="value.set", text="&set", icon=paths.icon_16x16.add, fn=user_functions.value.set)
435 436
437 - def add_class(self, name=None, text=None, icon=None):
438 """Add the user function. 439 440 @keyword name: The name of the user function, such as 'residue.delete'. 441 @type name: str 442 @keyword text: The menu text string. 443 @type text: str 444 @keyword icon: The path to the icon image file for the menu entry. 445 @type icon: str or None 446 @return: The menu ID number. 447 @rtype: long 448 """ 449 450 # Generate a unique ID. 451 id = wx.NewId() 452 453 # Build the menu entry. 454 menu_item = build_menu_item(self.menu, id=id, text=text, icon=icon) 455 456 # The sub-menu. 457 sub_menu = wx.Menu() 458 menu_item.SetSubMenu(sub_menu) 459 460 # Append to the main menu item. 461 self.menu.AppendItem(menu_item) 462 463 # Return the ID. 464 return id
465 466
467 - def add_uf(self, parent_id=None, name=None, text=None, icon=None, fn=None):
468 """Add the user function. 469 470 @keyword parent_id: The unique ID number of the parent menu entry. 471 @type parent_id: long 472 @keyword name: The name of the user function, such as 'residue.delete'. 473 @type name: str 474 @keyword text: The menu text string. 475 @type text: str 476 @keyword icon: The path to the icon image file for the menu entry. 477 @type icon: str or None 478 @keyword fn: The user function to execute. 479 @type fn: func 480 @return: The menu ID number. 481 @rtype: long 482 """ 483 484 # Generate a unique ID. 485 id = wx.NewId() 486 487 # Store the data. 488 self.uf_names[id] = name 489 self.uf[id] = fn 490 491 # Build the menu entry. 492 if parent_id != None: 493 sub_menu = self.menu.FindItemById(parent_id).GetSubMenu() 494 item = build_menu_item(sub_menu, id=id, text=text, icon=icon) 495 sub_menu.AppendItem(item) 496 497 # No parent menu. 498 else: 499 item = build_menu_item(self.menu, id=id, text=text, icon=icon) 500 self.menu.AppendItem(item) 501 502 # Menu actions. 503 self.parent.Bind(wx.EVT_MENU, self.call, id=id) 504 505 # Return the ID. 506 return id
507 508
509 - def call(self, event):
510 """Execute the given user function. 511 512 @param event: The wx event. 513 @type event: wx event 514 """ 515 516 # Get the ID. 517 id = event.GetId() 518 519 # Call the user function. 520 apply(self.uf[id])
521