Active Topics

 


Reply
Thread Tools
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#1
Hi,
I am making an application for my N800 that has a small image viewer inside, and I want the user to be able to scroll the image with the finger.

Any link/indication about how to do that would be highly appreciated!

Thanks!
L.
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#2
Maybe start with a variation of something like this:

Code:
   ...

    def __init__(s, aScrolledWindow, ...):
        ...
        s.sw = aScrolledWindow
        s.oldx = -1
        s.oldy = -1
        ...
        s.connect('button-press-event', s.on_button_press)
        s.connect('motion-notify-event', s.on_motion)
        ...

    def on_button_press(s, view, event):
        ...
        s.oldx = event.x
        s.oldy = event.y
        ...

    def on_motion(s, view, event):
        ...
        sw = s.sw
        if event.x != s.oldx:
            aux = sw.props.hadjustment.value + s.oldx - event.x
            if sw.props.hadjustment.lower <= aux and \
            aux <= sw.props.hadjustment.upper - sw.props.hadjustment.page_size:
                sw.props.hadjustment.value = aux
        if event.y != s.oldy:
            aux = sw.props.vadjustment.value + s.oldy - event.y
            if sw.props.vadjustment.lower <= aux and \
            aux <= sw.props.vadjustment.upper - sw.props.vadjustment.page_size:
                sw.props.vadjustment.value = aux
        s.oldx = event.x
        s.oldy = event.y
        ...

     ...
I originally ported/stole this from Bundyo's Tear.
__________________
N9: Go white or go home
 

The Following 3 Users Say Thank You to daperl For This Useful Post:
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#3
That 'on_motion' routine of yours is what I was looking for! I will give it a try.

Thanks a lot!!
L.
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#4
For some reason, your on_motion function didn't work for me. It didn't even enter in the function...

But never mind, I decided to make another approach using a variation of your code (clicking in the image bring that pixel to the center of the widget).

But I have another question, if you don't mind: clicking in the arrows of the D-PAD cycles the focus through the widgets of the app. I want to use the D-PAD for better purposes, but it keeps moving the focus, even if I do some "...grab_focus". How I completely disable this focus cycle properties of the D-PAD?

Thanks a lot!!

L.
 
Posts: 882 | Thanked: 1,310 times | Joined on Mar 2007
#5
Originally Posted by luis View Post
For some reason, your on_motion function didn't work for me. It didn't even enter in the function....
Maybe too late, but you may need to add the image to EventBox and then add the EventBox to container.
 

The Following 4 Users Say Thank You to ukki For This Useful Post:
Posts: 105 | Thanked: 48 times | Joined on Aug 2008
#6
this is from panucci, a media player that uses the directional for playback control.

Code:
            # Disable focus for all widgets, so we can use the cursor
            # keys + enter to directly control our media player, which
            # is handled by "key-press-event"
            for w in (
                    self.rrewind_button, self.rewind_button,
                    self.play_pause_button, self.forward_button,
                    self.fforward_button, self.progress, 
                    self.bookmarks_button, self.volume_button, ):
                w.unset_flags(gtk.CAN_FOCUS)
The code block is in GTK_Main.make_main_window() inside file panucci.py

Each "w" is a gtk.Button() object.

There's probably a more extensible way of doing this - like looping through each property of self, testing to see if it is focusable, and then unsetting the CAN_FOCUS flag. That way, you don't have to worry about keeping the list of controls in sync with the actual controls on the window. You just have to remember to make every focusable control a member of self.
 

The Following 3 Users Say Thank You to MattZTexasu For This Useful Post:
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#7
Originally Posted by luis View Post
For some reason, your on_motion function didn't work for me. It didn't even enter in the function...

But never mind, I decided to make another approach using a variation of your code (clicking in the image bring that pixel to the center of the widget).

But I have another question, if you don't mind: clicking in the arrows of the D-PAD cycles the focus through the widgets of the app. I want to use the D-PAD for better purposes, but it keeps moving the focus, even if I do some "...grab_focus". How I completely disable this focus cycle properties of the D-PAD?

Thanks a lot!!

L.
Sorry, I forgot that widgets have different default event masks. A gtkDrawingArea, for example, doesn't have any I think.

So, after creating the widget you would have to do the following:

Code:
myWidget.add_events(gtk.gdk.POINTER_MOTION_MASK|gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK)
If the above suggestions for the d-pad focus issue don't work, let us know and we'll bang our heads some more.
__________________
N9: Go white or go home

Last edited by daperl; 2009-07-10 at 16:59.
 

The Following User Says Thank You to daperl For This Useful Post:
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#8
@luis

Originally Posted by ukki View Post
Maybe too late, but you may need to add the image to EventBox and then add the EventBox to container.
Yes, I think ukki is right. It's subtle, but there's a difference between signals and events. Events are a GDK thing and signals are a gobject thing. A gtk.Widget is a gobject but it doesn't necessarily have or use its own gtk.gdk.Window. Thus, no gtk.gdk.Window, no events for that particular widget. So, if you want to catch events for widgets that don't have a corresponding gtk.gdk.Window, you have to put them in a gtk.EventBox.

Here's an API link and here's a tutorial link. At the moment, I can't seem to find the verbiage that mentions which widgets do and don't have a gtk.gdk.Window, but most of them don't, so, in that case, events go directly to the top level gtk.Window.
__________________
N9: Go white or go home
 

The Following 2 Users Say Thank You to daperl For This Useful Post:
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#9
Originally Posted by MattZTexasu View Post
this is from panucci, a media player that uses the directional for playback control.
[...]
Unfortunately, I think that I cannot use your advice, because I do use focus on the widgets. I just don't want the D-PAD to change it.

Thanks!
L.
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#10
Does anyone know what the keysyms are for the d-pad? If so, catching and subsuming their events should be as simple as:

Code:
...
window = gtk.Window()
window.connect("key-press-event", on_key_press)
...
def on_key_press(widget, event, *args):
    returnValue = False
    ....
    if event.keyval == gtk.keysyms.<DPAD_LEFT> or\
    event.keyval == gtk.keysyms.<DPAD_RIGHT> or\
    event.keyval == gtk.keysyms.<DPAD_UP> or\
    event.keyval == gtk.keysyms.<DPAD_DOWN>:
        ...
        returnValue = True
    ...
    return returnValue
...
The "returnValue = True" is the import part because it will keep these events from propagating.

EDIT:

I tested this by just returning True and it worked.
__________________
N9: Go white or go home

Last edited by daperl; 2009-07-11 at 00:11.
 

The Following 2 Users Say Thank You to daperl For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 00:10.