Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Util
diff options
context:
space:
mode:
authorJames <olpc@xo-02-32-5F.localdomain>2007-06-28 22:38:29 (GMT)
committer James <olpc@xo-02-32-5F.localdomain>2007-06-28 22:38:29 (GMT)
commitb4b4b194d59a453981049fd4bc1ae7ddc4df5411 (patch)
treef9a9882148231f5383b345a103d7b07e3bda325e /Util
parent3e7296105ae5f235141cf25e6d4b9ab182c408e4 (diff)
parenta6d2a7b12699bb844fb0af92a394d68ed895ceb4 (diff)
Merge branch 'master' of git+ssh://jaberg@dev.laptop.org/git/projects/tamtam
Diffstat (limited to 'Util')
-rw-r--r--Util/KeyboardWindow.py91
-rw-r--r--Util/Trackpad.py2
2 files changed, 70 insertions, 23 deletions
diff --git a/Util/KeyboardWindow.py b/Util/KeyboardWindow.py
index eccef03..b856fce 100644
--- a/Util/KeyboardWindow.py
+++ b/Util/KeyboardWindow.py
@@ -4,29 +4,37 @@ pygtk.require( '2.0' )
import gtk
import random
from ThemeWidgets import keyButton
+import Config
+KEY_MAP_PIANO = Config.KEY_MAP_PIANO
class KeyboardWindow(gtk.Window):
- def __init__(self, size = None, pos = 0):
- gtk.Window.__init__(self , gtk.WINDOW_POPUP)
- #self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
+ def __init__(self, size = None, pos = 0, popup = False):
+ if popup is False:
+ gtk.Window.__init__(self , gtk.WINDOW_TOPLEVEL)
+ else:
+ gtk.Window.__init__(self , gtk.WINDOW_POPUP)
color = gtk.gdk.color_parse("#000000")
self.modify_bg(gtk.STATE_NORMAL, color)
self.set_decorated(False)
- self.pos = pos
- self.set_pos(self.pos)
-
+
+ self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.ENTER_NOTIFY_MASK | gtk.gdk.KEY_PRESS_MASK)
self.connect("key-press-event",self.handle_keypress)
self.connect("key-release-event",self.handle_keyrelease)
- self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.ENTER_NOTIFY_MASK)
+ self.connect("button-press-event",self.handle_mousePress)
+ self.connect("button-release-event",self.handle_mouseRelease)
self.connect("enter-notify-event",self.handle_enter)
self.size = size
+ self.pos = pos
+ self.popup = popup
+ self.set_pos(self.pos)
+
if self.size == None:
self.pixel_space = 15
self.height = 45
else:
self.pixel_space = size
- self.height = 3* size
+ self.height = 3 * size
self.draw()
@@ -42,19 +50,20 @@ class KeyboardWindow(gtk.Window):
self.btn_dic = {}
+ mainvbox = gtk.VBox()
mainhbox = gtk.HBox()
+ #Main keyboard section
vbox = gtk.VBox()
for row in [1,2,3,4,5]:
hbox = gtk.HBox()
for key in self.rows[row]:
self.btn_dic[key[0]] = keyButton(self.pixel_space * key[1], self.height, [0,0,0], [0.5,0.5,0.5])
- self.btn_dic[key[0]].connect("enter",self.handle_mouseEnter)
- self.btn_dic[key[0]].connect("leave",self.handle_mouseLeave)
hbox.pack_start(self.btn_dic[key[0]], padding = self.pixel_space//2)
vbox.pack_start(hbox, padding = self.pixel_space//2)
mainhbox.pack_start(vbox)
+ #Right part of the keyboard
right_vbox = gtk.VBox()
right_tophbox = gtk.HBox()
right_lowhbox = gtk.HBox()
@@ -65,10 +74,6 @@ class KeyboardWindow(gtk.Window):
self.btn_dic[self.right_section[3][0]] = keyButton(self.pixel_space * self.right_section[3][1], self.height, [0,0,0], [0.5,0.5,0.5])
self.btn_dic[self.right_section[4][0]] = keyButton(self.pixel_space * self.right_section[4][1], self.height, [0,0,0], [0.5,0.5,0.5])
self.btn_dic[self.right_section[5][0]] = keyButton(self.pixel_space * self.right_section[5][1], self.height, [0,0,0], [0.5,0.5,0.5])
-
- for key in self.right_section:
- self.btn_dic[key[0]].connect("enter",self.handle_mouseEnter)
- self.btn_dic[key[0]].connect("leave",self.handle_mouseLeave)
right_vbox.pack_start(self.btn_dic[self.right_section[0][0]], padding = self.pixel_space//2)
right_vbox.pack_start(self.btn_dic[self.right_section[1][0]], padding = self.pixel_space//2)
@@ -78,10 +83,25 @@ class KeyboardWindow(gtk.Window):
right_lowhbox.pack_start(self.btn_dic[self.right_section[5][0]], padding = self.pixel_space//2)
right_vbox.pack_start(right_tophbox, padding = self.pixel_space//2)
right_vbox.pack_start(right_lowhbox, padding = self.pixel_space//2)
+
+ #Mouse buttons
+ mouse_hbox = gtk.HBox()
+ self.btn_dic["left_mouse"] = keyButton(self.pixel_space * 6, self.pixel_space * 2, [0,0,0], [0.5,0.5,0.5])
+ self.btn_dic["right_mouse"] = keyButton(self.pixel_space * 6, self.pixel_space * 2, [0,0,0], [0.5,0.5,0.5])
+ mouse_hbox.pack_start(self.btn_dic["left_mouse"], False, False, padding = self.pixel_space//2)
+ mouse_hbox.pack_start(self.btn_dic["right_mouse"], False, False, padding = self.pixel_space//2)
+
+
+ #Enter and Leave connections
+ for key in self.btn_dic:
+ self.btn_dic[key].connect("enter",self.handle_mouseEnter)
+ self.btn_dic[key].connect("leave",self.handle_mouseLeave)
mainhbox.pack_start(right_vbox)
+ mainvbox.pack_start(mainhbox)
+ mainvbox.pack_start(mouse_hbox, padding = self.pixel_space//2)
- self.add(mainhbox)
+ self.add(mainvbox)
def set_pos(self,_pos = 0):
width = self.get_screen().get_width()
@@ -91,22 +111,47 @@ class KeyboardWindow(gtk.Window):
self.pos = _pos
- pos = [0,0,0,0]
+ pos = [0,0]
pos[0] = (0, 0)
- pos[1] = (width - win_width, 0)
- pos[2] = (0, height - win_height)
- pos[3] = (width - win_width, height - win_height)
-
+ pos[1] = (width - win_width, height - win_height)
self.move(pos[self.pos][0],pos[self.pos][1])
+
+ def color_piano(self):
+ for key in KEY_MAP_PIANO:
+ self.btn_dic[key].set_fillcolor(1,1,1)
+
def handle_keypress(self,widget,event):
if event.hardware_keycode == 9:
self.hide_all()
+ elif event.hardware_keycode == 216:
+ self.btn_dic["left mouse"].set_fillcolor(random.random(),random.random(),random.random())
+ elif event.hardware_keycode == 133:
+ self.btn_dic["right_mouse"].set_fillcolor(random.random(),random.random(),random.random())
else:
self.btn_dic[event.hardware_keycode].set_fillcolor(random.random(),random.random(),random.random())
def handle_keyrelease(self,widget,event):
- self.btn_dic[event.hardware_keycode].set_fillcolor(0,0,0)
+ if KEY_MAP_PIANO.has_key(event.hardware_keycode):
+ self.btn_dic[event.hardware_keycode].set_fillcolor(1,1,1)
+ else:
+ self.btn_dic[event.hardware_keycode].set_fillcolor(0,0,0)
+ if event.hardware_keycode == 216 or event.hardware_keycode == 133:
+ self.btn_dic["left mouse"].set_fillcolor(0,0,0)
+ self.btn_dic["right mouse"].set_fillcolor(0,0,0)
+
+
+ def handle_mousePress(self,widget,event):
+ if event.button == 1:
+ self.btn_dic["left_mouse"].set_fillcolor(random.random(),random.random(),random.random())
+ elif event.button == 3:
+ self.btn_dic["right_mouse"].set_fillcolor(random.random(),random.random(),random.random())
+
+ def handle_mouseRelease(self,widget,event):
+ if event.button == 1:
+ self.btn_dic["left_mouse"].set_fillcolor(0,0,0)
+ elif event.button == 3:
+ self.btn_dic["right_mouse"].set_fillcolor(0,0,0)
def handle_mouseEnter(self,widget,event = None):
widget.set_strokecolor(1,1,1)
@@ -115,8 +160,10 @@ class KeyboardWindow(gtk.Window):
widget.set_strokecolor(0.5,0.5,0.5)
def handle_enter(self,widget,event):
+ if self.popup is False:
+ return
if self.pos == 0:
- self.set_pos(3)
+ self.set_pos(1)
else:
self.set_pos(0)
diff --git a/Util/Trackpad.py b/Util/Trackpad.py
index ea2990d..f46a62c 100644
--- a/Util/Trackpad.py
+++ b/Util/Trackpad.py
@@ -75,7 +75,7 @@ class Trackpad:
def handle_keyPress(self,widget,event):
if KEY_MAP_PIANO.has_key(event.hardware_keycode) and self.buttonPressed == False:
gtk.gdk.Display.warp_pointer(self.display, self.screen, self.screen.get_width() / 2, self.screen.get_height() / 2)
- gtk.gdk.pointer_grab(self.win.window, event_mask = gtk.gdk.POINTER_MOTION_MASK, cursor = self.invisible_cursor)
+ gtk.gdk.pointer_grab(self.win.window, event_mask = gtk.gdk.POINTER_MOTION_MASK)#, cursor = self.invisible_cursor)
self.buttonPressed = True
self.first_x = self.screen.get_width() / 2
self.first_y = self.screen.get_height() / 2