This a dummy extension that contains and lists all the necessary files to build a Chimera extension. It also encourages good practices to maintain in all the components of Plume. Please, read the docstrings and comments, and do the same for your developments!
Created
November 4, 2017 12:29
-
-
Save jaimergp/3f9b2dceaec48736108e6f447dff4e36 to your computer and use it in GitHub Desktop.
Blank extension for UCSF Chimera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
# This file should be blank, unless you want to expose some parts of the extension | |
# to other programs. In that case, import those explicitly, and only those. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
# get used to importing this in your Py27 projects! | |
from __future__ import print_function, division | |
import chimera.extension | |
""" | |
This is the file that Chimera searches for to load new extensions | |
at runtime. Normally, you will only need to edit: | |
- the returned strings in name() and description() methods | |
- the name of the class in both the class statement and the | |
registerExtension() call at the end of the file. | |
""" | |
class BlankExtension(chimera.extension.EMO): | |
def name(self): | |
return 'Plume Blank' | |
def description(self): | |
return "Boilerplate code for new Chimera extensions" | |
def categories(self): | |
return ['InsiliChem'] | |
def icon(self): | |
return | |
def activate(self): | |
self.module('gui').showUI() | |
chimera.extension.manager.registerExtension(BlankExtension(__file__)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
# Get used to importing this in your Py27 projects! | |
from __future__ import print_function, division | |
# Python stdlib | |
# Chimera stuff | |
# Additional 3rd parties | |
# Own | |
""" | |
This module contains the business logic of your extension. Normally, it should | |
contain the Controller and the Model. Read on MVC design if you don't know about it. | |
""" | |
class Controller(object): | |
""" | |
The controller manages the communication between the UI (graphic interface) | |
and the data model. Actions such as clicks on buttons, enabling certain areas, | |
or running external programs, are the responsibility of the controller. | |
""" | |
def __init__(self, *args, **kwargs): | |
return | |
class Model(object): | |
""" | |
The model controls the data we work with. Normally, it'd be a Chimera molecule | |
and some input files from other programs. The role of the model is to create | |
a layer around those to allow the easy access and use to the data contained in | |
those files | |
""" | |
def __init__(self, *args, **kwargs): | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
# Get used to importing this in your Py27 projects! | |
from __future__ import print_function, division | |
# Python stdlib | |
import Tkinter as tk | |
# Chimera stuff | |
import chimera | |
from chimera.baseDialog import ModelessDialog | |
# Additional 3rd parties | |
# Own | |
from core import Controller, Model | |
""" | |
The gui.py module contains the interface code, and only that. | |
It should only 'draw' the window, and should NOT contain any | |
business logic like parsing files or applying modifications | |
to the opened molecules. That belongs to core.py. | |
""" | |
# Make UI a singleton to prevent extra instances (optional) | |
ui = None | |
def showUI(): | |
if chimera.nogui: | |
tk.Tk().withdraw() | |
global ui | |
if not ui: # Edit this to reflect the name of the class! | |
ui = BlankDialog() | |
model = Model() | |
controller = Controller(gui=ui, model=model) | |
ui.enter() | |
class BlankDialog(ModelessDialog): | |
""" | |
To display a new dialog on the interface, you will normally inherit from | |
ModelessDialog class of chimera.baseDialog module. Being modeless means | |
you can have this dialog open while using other parts of the interface. | |
If you don't want this behaviour and instead you want your extension to | |
claim exclusive usage, use ModalDialog. | |
""" | |
buttons = ('OK', 'Close') | |
default = 'OK' | |
help = 'https://www.insilichem.com' | |
def __init__(self, *args, **kwarg): | |
# GUI init | |
self.title = 'Plume Blank Dialog' | |
self.controller = None | |
# Fire up | |
ModelessDialog.__init__(self) | |
if not chimera.nogui: # avoid useless errors during development | |
chimera.extension.manager.registerInstance(self) | |
def _initialPositionCheck(self, *args): | |
try: | |
ModelessDialog._initialPositionCheck(self, *args) | |
except Exception as e: | |
if not chimera.nogui: # avoid useless errors during development | |
raise e | |
def fillInUI(self, parent): | |
""" | |
This is the main part of the interface. With this method you code | |
the whole dialog, buttons, textareas and everything. | |
""" | |
# Create main window | |
self.canvas = tk.Frame(parent) | |
self.canvas.pack(expand=True, fill='both') | |
tk.Label(self.canvas, text="This is just a dummy extension.").pack(padx=5, pady=5, expand=True) | |
def Apply(self): | |
""" | |
Default! Triggered action if you click on an Apply button | |
""" | |
pass | |
def OK(self): | |
""" | |
Default! Triggered action if you click on an OK button | |
""" | |
self.Apply() | |
self.Close() | |
def Close(self): | |
""" | |
Default! Triggered action if you click on the Close button | |
""" | |
chimera.extension.manager.deregisterInstance(self) | |
ModelessDialog.Close(self) | |
Quit = Close | |
# Below this line, implement all your custom methods for the GUI. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment