Commit 9b89e503 authored by Bruno Coudoin's avatar Bruno Coudoin

louis baille activity: implemented a clean drag and motion for the game.

Still misses the way to reorder items during the move.
parent 93a73a7b
...@@ -110,33 +110,36 @@ class Gcompris_louis_braille: ...@@ -110,33 +110,36 @@ class Gcompris_louis_braille:
gcompris.bar_location(gcompris.BOARD_WIDTH - 120, -1, 0.8) gcompris.bar_location(gcompris.BOARD_WIDTH - 120, -1, 0.8)
for index in range(11): for index in range(11):
#Create Rounded Rectangles for each story group_item = goocanvas.Group(parent = self.rootitem)
self.dragRect = goocanvas.Rect(parent=self.rootitem,
x = 100, # Create Rounded Rectangles for each story
y = (index + 0.5) * 43, goocanvas.Rect(parent = group_item,
width = 550, x = 100,
height = 40, y = (index + 0.5) * 43,
radius_x = 17, width = 550,
radius_y = 17, height = 40,
stroke_color = "orange", radius_x = 17,
fill_color = "white", radius_y = 17,
line_width = 2.0) stroke_color = "orange",
fill_color = "white",
#Displaying the STORY line_width = 2.0)
self.dragText = goocanvas.Text(parent = self.rootitem,
x = 370.0, # Displaying the STORY
y = (index + 1) * 43, goocanvas.Text(parent = group_item,
text = str(self.dataset.get(str(NUMBER_SEQUENCE[index][0]),"_story")), x = 370.0,
fill_color = "black", y = (index + 1) * 43,
anchor = gtk.ANCHOR_CENTER, text = str(self.dataset.get(str(NUMBER_SEQUENCE[index][0]),"_story")),
alignment = pango.ALIGN_CENTER, fill_color = "black",
font = 'SANS 9', anchor = gtk.ANCHOR_CENTER,
width = 500, alignment = pango.ALIGN_CENTER,
) font = 'SANS 9',
gcompris.utils.item_focus_init(self.dragText, self.dragRect) width = 500,
self.dragText.connect("button_press_event", self.component_drag) )
self.dragText.connect("motion_notify_event", self.component_drag) # It is hard to manage focus when we move the item
self.dragText.connect("button_release_event", self.component_drag) #gcompris.utils.item_focus_init(self.dragText, self.dragRect)
group_item.connect("button_press_event", self.component_drag)
group_item.connect("motion_notify_event", self.component_drag)
group_item.connect("button_release_event", self.component_drag)
ok = goocanvas.Svg(parent = self.rootitem, ok = goocanvas.Svg(parent = self.rootitem,
...@@ -248,22 +251,22 @@ class Gcompris_louis_braille: ...@@ -248,22 +251,22 @@ class Gcompris_louis_braille:
) )
def component_drag(self, widget, target, event): def component_drag(self, widget, target, event):
if event.type == gtk.gdk.MOTION_NOTIFY: groupitem = target.get_parent()
if event.state & gtk.gdk.BUTTON1_MASK: groupitem.raise_(None)
# Save the click to image offset
if self.offset_x == 0: if event.type == gtk.gdk.BUTTON_PRESS:
bounds = widget.get_bounds() bounds = groupitem.get_bounds()
self.offset_x = (event.x - bounds.x1) self.offset_y = event.y
self.offset_y = (event.y - bounds.y1)
elif ( event.type == gtk.gdk.MOTION_NOTIFY
widget.set_properties(x = 360, and event.state & gtk.gdk.BUTTON1_MASK ):
y = event.y - self.offset_y) groupitem.translate(0, event.y - self.offset_y)
if event.type == gtk.gdk.BUTTON_RELEASE: elif event.type == gtk.gdk.BUTTON_RELEASE:
if event.button == 1: pass
bounds = widget.get_bounds() # Must find the closer stop to drop this item
return True return True
def enter_callback(self, event, widget, index): def enter_callback(self, event, widget, index):
print self.widget_array[index].get_text() print self.widget_array[index].get_text()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment