[Bio] / Speck / SpeckRemoteControl.py Repository:
ViewVC logotype

View of /Speck/SpeckRemoteControl.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (download) (as text) (annotate) (vendor branch)
Thu Sep 9 19:54:06 2004 UTC (15 years, 2 months ago) by sheradon
Branch: init, MAIN
CVS Tags: v0, HEAD
Changes since 1.1: +0 -0 lines
Initial load to CVS

#!/usr/bin/env python

from wxPython.wx import *
from xmlrpclib import *


class remoteControlWindow(wxFrame):
	# ------------------------------
	def __init__(self, title, size):
	# ------------------------------
		wxFrame.__init__(self, None, wxID_ANY, title, size=size)

		self.addressBox = wxTextCtrl(self, wxID_ANY, 'http://chromium.mcs.anl.gov:8008')
		self.serverBtn = wxButton(self, 3, 'Set Server')
		self.rcp = remoteControlPanel(self)
		EVT_BUTTON(self.serverBtn, 3, self.rcp.setServer)

		self.flipButtons = wxCheckBox(self, wxID_ANY, 'Reverse mouse buttons')
		self.zoomOut = wxButton(self, 1, '-')
		self.zoomIn = wxButton(self, 2, '+')
		EVT_BUTTON(self.zoomOut, 1, self.rcp.zoomOut)
		EVT_BUTTON(self.zoomIn, 2, self.rcp.zoomIn)

		# Assemble sizers
		sizer = wxBoxSizer(wxVERTICAL)
		sizer2 = wxBoxSizer(wxHORIZONTAL)
		sizer3 = wxBoxSizer(wxHORIZONTAL)
		sizer.Add(self.rcp, 1, wxEXPAND|wxALL, 5)
		sizer.Add(sizer2, 0, wxEXPAND|wxALL, 5)
		sizer.Add(sizer3, 0, wxALIGN_BOTTOM|wxEXPAND|wxALL, 5)
		sizer2.Add(self.flipButtons, 1, wxEXPAND)
		sizer2.Add(self.zoomOut, 0, wxLEFT, 10)
		sizer2.Add(self.zoomIn, 0)
		sizer3.Add(self.addressBox, 1, wxEXPAND)
		sizer3.Add(self.serverBtn, 0, wxALIGN_RIGHT|wxLEFT, 10)
		self.SetAutoLayout(1)
		self.SetSizer(sizer)

class remoteControlPanel(wxPanel):
	# -------------------------
	def __init__(self, parent):
	# -------------------------
		wxPanel.__init__(self, parent, wxID_ANY, wxDefaultPosition,
								wxDefaultSize, wxSIMPLE_BORDER)
		self.parent = parent	
		self.setServer()

		EVT_KEY_DOWN(self, self.OnKeyDown)
		EVT_KEY_UP(self, self.OnKeyUp)
		EVT_LEFT_DOWN(self, self.OnLeftDown)
		EVT_LEFT_UP(self, self.OnLeftUp)
		EVT_LEFT_DCLICK(self, self.OnLeftDClick)
		EVT_RIGHT_DOWN(self, self.OnRightDown)
		EVT_RIGHT_UP(self, self.OnRightUp)
		EVT_RIGHT_DCLICK(self, self.OnRightDClick)
		EVT_MIDDLE_DOWN(self, self.OnMiddleDown)
		EVT_MIDDLE_UP(self, self.OnMiddleUp)
		EVT_MIDDLE_DCLICK(self, self.OnMiddleDClick)
		EVT_MOTION(self, self.OnMotion)

	# -------------------------
	def setServer(self, event=None):
	# -------------------------
		self.uri = self.parent.addressBox.GetValue()
		self.server = Server(self.uri)
		
	# -------------------------
	def zoomOut(self, event):
	# -------------------------
		try: self.server.fireKeyDown(45)
		except: pass 
	# -------------------------
	def zoomIn(self, event):
	# -------------------------
		try: self.server.fireKeyDown(61)
		except: pass 

	# -------------------------
	def OnKeyDown(self, event):
	# -------------------------
		try: self.server.fireKeyDown(event.GetKeyCode())
		except: pass
	# -------------------------
	def OnKeyUp(self, event):
	# -------------------------
		try: self.server.fireKeyUp(event.GetKeyCode())
		except: pass

	# ---------------------------------
	def scaledEventCoords(self, event):
	# ---------------------------------
		"""Returns you (x, y), floats in [0, 1].
			Used so that your remote-control client window can
			be any size and its events will always be interpreted
			correctly by the server.
			@type event: wxMouseEvent
			@rtype: float, float
		"""
		x = float(event.GetX()) / float(self.GetSize()[0])
		y = float(event.GetY()) / float(self.GetSize()[1])
		return x, y

	# -------------------------
	def OnMotion(self, event):
	# -------------------------
		x = float(event.GetX()) / float(self.GetSize()[0])
		y = float(event.GetY()) / float(self.GetSize()[1])
		try: self.server.fireMotion(x, y)
		except: pass

	# -------------------------
	def OnLeftDown(self, event):
	# -------------------------
		x = float(event.GetX()) / float(self.GetSize()[0])
		y = float(event.GetY()) / float(self.GetSize()[1])
		if self.parent.flipButtons.GetValue():
			try: self.server.fireRightDown(x, y)
			except: pass
		else:
			try: self.server.fireLeftDown(x, y)
			except: pass
	# -------------------------
	def OnLeftUp(self, event):
	# -------------------------
		x = float(event.GetX()) / float(self.GetSize()[0])
		y = float(event.GetY()) / float(self.GetSize()[1])
		if self.parent.flipButtons.GetValue():
			try: self.server.fireRightUp(x, y)
			except: pass
		else:
			try: self.server.fireLeftUp(x, y)
			except: pass
	# -------------------------
	def OnLeftDClick(self, event):
	# -------------------------
		x = float(event.GetX()) / float(self.GetSize()[0])
		y = float(event.GetY()) / float(self.GetSize()[1])
		if self.parent.flipButtons.GetValue():
			try: self.server.fireRightDClick(x, y)
			except: pass
		else:
			try: self.server.fireLeftDClick(x, y)
			except: pass

	# -------------------------
	def OnRightDown(self, event):
	# -------------------------
		x = float(event.GetX()) / float(self.GetSize()[0])
		y = float(event.GetY()) / float(self.GetSize()[1])
		if self.parent.flipButtons.GetValue():
			try: self.server.fireLeftDown(x, y)
			except: pass
		else:
			try: self.server.fireRightDown(x, y)
			except: pass
	# -------------------------
	def OnRightUp(self, event):
	# -------------------------
		x = float(event.GetX()) / float(self.GetSize()[0])
		y = float(event.GetY()) / float(self.GetSize()[1])
		if self.parent.flipButtons.GetValue():
			try: self.server.fireLeftUp(x, y)
			except: pass
		else:
			try: self.server.fireRightUp(x, y)
			except: pass
	# -------------------------
	def OnRightDClick(self, event):
	# -------------------------
		x = float(event.GetX()) / float(self.GetSize()[0])
		y = float(event.GetY()) / float(self.GetSize()[1])
		if self.parent.flipButtons.GetValue():
			try: self.server.fireLeftDClick(x, y)
			except: pass
		else:
			try: self.server.fireRightDClick(x, y)
			except: pass

	# -------------------------
	def OnMiddleDown(self, event):
	# -------------------------
		x, y = self.scaledEventCoords(event)
		try: self.server.fireMiddleDown(x, y)
		except: pass
	# -------------------------
	def OnMiddleUp(self, event):
	# -------------------------
		x, y = self.scaledEventCoords(event)
		try: self.server.fireMiddleUp(x, y)
		except: pass
	# -------------------------
	def OnMiddleDClick(self, event):
	# -------------------------
		x, y = self.scaledEventCoords(event)
		try: self.server.fireMiddleDClick(x, y)
		except: pass




# ------------------------
if __name__ == '__main__':
# ------------------------
	uri = 'http://chromium:10321'
	server = ServerProxy(uri)
	app = wxPySimpleApp()
	win = remoteControlWindow('Speck Remote Control', (360, 240))
	win.Show(True)
	app.MainLoop()


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3