[Bio] / Detour / DetourCanvas.py Repository:
ViewVC logotype

View of /Detour/DetourCanvas.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (download) (as text) (annotate) (vendor branch)
Thu Sep 9 20:02:51 2004 UTC (15 years, 1 month ago) by sheradon
Branch: init, MAIN
CVS Tags: v0, HEAD
Changes since 1.1: +0 -0 lines
init load

import string, math
import wxPython.wx
from wxPython.wx			import *
from wxPython.glcanvas	import *
from OpenGL.GL				import *
from OpenGL.GLU			import *
from pydot					import Node, Edge

from Speck.DotCanvas		import DotCanvas
import Speck.PixFont 		 as pixFont


# -----------------------------
class DetourCanvas(DotCanvas):
# -----------------------------
	"""OpenGL canvas that goes inside the renderWindow. Has all the event-handling
		and drawing functionality of the viewer.
	"""
	# -----------------------------
	def __init__(self, parent, d, **kwargs):
	# -----------------------------
		"""@type d: Dot
			@rtype: DotCanvas
		"""
		DotCanvas.__init__(self, parent, d, **kwargs)
	
	# -------------------------------
	def OnLeftUp(self, event):
	# -------------------------------
		"""Pick a node or edge and display some info on it
			@type event: wxMouseEvent
			@rtype: None
		"""
		wc = gluUnProject(event.GetX(), self.GetSize()[1]-event.GetY(), 0,
			glGetDoublev(GL_MODELVIEW_MATRIX), glGetDoublev(GL_PROJECTION_MATRIX), glGetIntegerv(GL_VIEWPORT))
		x = self.getThingAt(wc[0], wc[1])
		self.overlayText = []
		if isinstance(x, Node):
			label = string.replace(x.label, r'\n', ' ')
			# TODO: Only look at edges conn. to neighboring invis-nodes.
			for e in self.dot.get_edge_list():
				try:
					if e.tooltip.find(label) > -1: self.overlayText.append(e.tooltip)
				except AttributeError: continue
			self.overlayText.append('')
			self.overlayText.append(label + ' is present in these reactions:')
		elif isinstance(x, Edge):
			self.overlayText = [x.tooltip]
		self.OnPaint()


	# ------------------------------
	def OnPaint(self, event = None):
	# ------------------------------
		"""The window painting callback. Main rendering function. Handles display lists
			and calls out to the subroutines to draw various parts of the graph picture.
			@rtype: None
		"""
		self.SetCurrent()
		if self.zoom < 0.25: self.zoom = 0.25		# Don't get TOO close or it can crash X
		elif self.zoom * self.winSize[0] > self.boxSize[0] * 2.5: 
			self.zoom = 2.5 * float(self.boxSize[0]) / float(self.winSize[0])
		dc = wxPaintDC(self)
		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()
		glOrtho(	self.center[0] - self.zoom * self.winSize[0] / 2,
					self.center[0] + self.zoom * self.winSize[0] / 2,
					self.center[1] - self.zoom * self.winSize[1] / 2,
					self.center[1] + self.zoom * self.winSize[1] / 2, -1, 100)

		glClearColor(0, 0, 0, 1)
		glClear(GL_COLOR_BUFFER_BIT)
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glShadeModel(GL_SMOOTH)
		glEnable(GL_POINT_SMOOTH)
		glEnable(GL_LINE_SMOOTH)
		# Put this here so it gets updated @ diff zooms:
		glLineWidth(2.0 / self.zoom)

		# Ensure display lists exist and we're using the right one:
		if self.DL == 0: self.DL = glGenLists(1)
		if self.DL == 0: return

		# Only do computationally intensive calculations if something's changed.
		if self.needUpdate:
			wxBeginBusyCursor()
			glNewList(self.DL, GL_COMPILE)
			self.drawBox()
			self.drawGraph(self.dot)
			glEndList()
			wxEndBusyCursor()
			self.needUpdate = false
		glCallList(self.DL)

		self.drawOverlay()
		# If on chromium, we need to draw a mouse cursor.
		if self.cr: self.drawCursor()

		glFlush()
		self.SwapBuffers()



MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3