wxMoleculeDrawer.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 » wxMoleculeDrawer.py
import MoleculeDrawer
from wxPython.wx import *

class wxMixin(wxScrolledWindow):
    def _init(self, parent, height=None, width=None):
        self.x0 = 0
        self.y0 = 0
        self.name = ""
        if height is None and width is None:
            size = parent.GetClientSize()
        else:
            size = (width, height)
        self.parent = parent
        wxScrolledWindow.__init__(self, parent, -1, (0,0), size,
                                  wxSUNKEN_BORDER)

        self._textFont = "HELVETICA"
        self.SetBackgroundColour(wxNamedColor("WHITE"))
        
        # flag used to redraw only when necessary
        EVT_PAINT(self, self.OnPaint)
        EVT_SIZE(self, self.OnSize)

    def _clear(self):        
        return 1
    
    def OnSize(self, event):
        self.Refresh()
        
    def OnPaint(self, event, dc=None):
        self.width, self.height = self.GetSize()

        if dc is None:
            dc = self.dc = wxPaintDC(self)
        else:
            self.dc = dc
            
        self.PrepareDC(dc)
        dc.BeginDrawing()

        if self.name:
            fontsize = min(16, self.width/len(self.name))
            self._drawText(self.name,  "Arial", fontsize, self.width/2, self.height-2*fontsize, "red")
            
        self.draw()

        dc.EndDrawing()
        # we need to clean up the dc otherwise terror ensues!
        self.dc = None

    def _drawPoly(self, coords, color="black"):
        dc = self.dc
        pen = dc.GetPen()
        brush = dc.GetBrush()
        if color is not None:
            dc.SetPen(wxPen(color, 1, wxSOLID))
            dc.SetBrush(wxBrush(color, wxSOLID))
        self.dc.DrawPolygon(coords)
        dc.SetPen(pen)
        dc.SetBrush(brush)
        
    def _drawOval(self, x, y, xh, yh):
        self.dc.DrawEllipse(self.x0+x, self.y0+y, xh-x, yh-y)
        
    def _drawLine(self, x1, y1, x2, y2, color):
        color = wxTheColourDatabase.FindColour(color)
        dc = self.dc
        pen = dc.GetPen()
        if color is not None:
            dc.SetPen(wxPen(color, 1, wxSOLID))
            
        self.dc.DrawLine(self.x0+x1, self.y0+y1, self.x0+x2, self.y0+y2)
        dc.SetPen(pen)
        
    def _drawText(self, text, font, fontsize, x, y, color, bg="white"):
        dc = self.dc
        font = wxFont(fontsize, wxDEFAULT, wxNORMAL, wxNORMAL,
                      0, self._textFont)
        dc.SetFont(font)
        w,h = dc.GetTextExtent(text)
        w+=2
        h+=2
        x -= w/2
        y -= h/2

        pen = dc.GetPen()
        # hack        
        dc.SetPen(wxWHITE_PEN)
        dc.DrawRectangle(self.x0+x, self.y0+y, w, h)
        
        dc.DrawText(text, self.x0+x, self.y0+y)
        dc.SetPen(pen)

class MoleculeDrawer(MoleculeDrawer.DrawMolHarness, wxMixin):
    pass
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.