TkMoleculeDrawer.py :  » Development » Frowns » frowns » Depict » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Frowns 
Frowns » frowns » Depict » TkMoleculeDrawer.py
from MoleculeDrawer import DrawMolHarness
from Tkinter import *

class TkMixin:    
    def _init(self, master, height, width):
        frame = self.frame = Frame(master, height=height, width=width)
        canvas = self.canvas = Canvas(frame, bg="white", height=height,
                                      width=width)
        self.width = width or int(master.cget("width"))
        self.height = height or int(master.cget("height"))

        canvas.pack(fill=BOTH, expand=1)
        self.canvas.bind("<Configure>", self._resize)

    def _drawOval(self, x, y, xh, yh):
        self.canvas.create_oval(x, y, xh, yh)
        
    def _drawText(self, text, font, fontsize, x, y, color, bg="white"):
            current = self.canvas.create_text(x,
                                              y,
                                              font=("Helvetica", fontsize),
                                              text=text,
                                              fill=color)
            bbox = self.canvas.bbox(current)
            i = self.canvas.create_rectangle(bbox,
                                             fill=bg,
                                             outline=bg,
                                             tag="marker")
            self.canvas.lower(i, current)

    def _clear(self):
        # returns -1 on failure
        for item in self.canvas.find_all():
            self.canvas.delete(item)

        if not self.molecule:
            self.canvas.create_text(
                self.width/2,
                self.height/2,
                text="UNABLE TO DEPICT", fill="red")
            return -1

        
        self.canvas.create_text(self.width/2,
                                self.height-self.border, 
                                text=self.name, fill="red")

        return 0
        
    def _resize(self, event):
        """(event) -> resive the drawing to event.height, event.width"""
        # the label might dissappear but so what for now...
        self.height = event.height
        self.width = event.width
        self.draw()
        
    def _drawLine(self, x1, y1, x2, y2, color):
        self.canvas.create_line(x1, y1, x2, y2, fill=color)
        
    def pack(self, *a, **kw):
        apply(self.frame.pack, a, kw)#

    def pack_forget(self):
        self.frame.pack_forget()
        
    def grid(self, *a, **kw):
        apply(self.frame.grid, a, kw)

    def postscript(self, *a, **kw):
        """return a postscript image of the current molecule arguments
        are sent to the Tkinter canvas postscript method"""
        return apply(self.canvas.postscript, a, kw)



class TkDrawer(DrawMolHarness, TkMixin): pass

MoleculeDrawer = TkDrawer

if __name__ == "__main__":
    from frowns import MDL,Smiles
    from ScrollingFrame import ScrollingFrame
    reader = MDL.mdlin(open("../test/data/bad.sdf"))
    #reader = MDL.mdlin(open("../apps/SaltFinder/SAVED_MOLECULE0.sdf"))

    mol = reader.next()
    tk = Tk()
    frame = Frame(tk)
    
    frame.pack(expand=1, fill=BOTH)

    drawer = MoleculeDrawer(frame, mol, drawAromatic=1)
    drawer.grid(row=0, column=0, sticky=N+E+W+S)
    frame.rowconfigure(0, weight=1)
    frame.columnconfigure(0, weight=1)
    
    
##    mol = reader.next()
##    components = getComponents(mol)
##    for component in range(len(components)):
##        f = Frame(frame, border=2, relief="sunken")
##        f.pack()
##        b = Button(f, text="keep", command=lambda x=None:x)
##        b.pack(side=LEFT)
##        d = DrawMolHarness(f, mol, name=mol.name,
##                           component=component)
##        d.pack(expand=1, fill=BOTH, side=LEFT)

    mainloop()
        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.