Active Topics

 


Reply
Thread Tools
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#11
Originally Posted by daperl View Post
Does anyone know what the keysyms are for the d-pad?
GDK_Left - Left on d-pad

And etc :
GDK_Up
GDK_Right
GDK_Down
 

The Following User Says Thank You to qwerty12 For This Useful Post:
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#12
Originally Posted by daperl View Post
Does anyone know what the keysyms are for the d-pad?
http://maemomm.garage.maemo.org/docs...l/ch02s03.html

You can also use "... if event.keyval == 65307:" for the back key.

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.
It worked!


EDIT:

I tested this by just returning True and it worked.
This worked, but also disabled completely the arrow keys, like when choosing an item in a listore. I will use the first suggestion then

Thanks A LOT!!
L.
 

The Following User Says Thank You to luis For This Useful Post:
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#13
Originally Posted by daperl View Post
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.
Hi daperl!!

After such a long time, I decided to implement your method.
It worked flawlessly. Well, at least in my PC. But is absolutely crazy in my N800: it kinds of multiply the movements before it settles when you stop moving. Look at what happens:

1) Centralize the image
2) With the pen, press in the middle of the image (nothing happens, of course)
3) Begin to draw VERY small circles (5 or 6 pixels in diameter)
4) Then, the image makes very small circles, as it should
5) After 1 or 2 seconds, the image begins to make HUGE circles and becomes crazy.
6) When I stop moving the pen, the image continues making huge circles, but after 2 or 3 seconds, it goes right behind the pen, as it should.

What I am doing wrong?? Do you have any idea of what is happening? How can I prevent this behavior? Again, in my Fedora box everything goes smoothly.

This is my code:

Code:
    def pressimg(self, swi, event):
          ....
          self.oldxpos = event.x
          self.oldypos = event.y

    def scrollimg(self, swi, event):
        swih = swi.parent.props.hadjustment
        swiv = swi.parent.props.vadjustment
        if event.x != self.oldxpos:
            aux = swih.value + self.oldxpos - event.x
            if swih.lower <= aux and \
                  aux <= swih.upper - swih.page_size:
                swih.value = aux
        if event.y != self.oldypos:
            aux = swiv.value + self.oldypos - event.y
            if swiv.lower <= aux and \
                  aux <= swiv.upper - swiv.page_size:
                swiv.value = aux

        def __init__(self):
        ....
        self.mpics_scroll = gtk.ScrolledWindow(None, None)
        event_box = gtk.EventBox()
        self.mpics = gtk.Image()
        event_box.add(self.mpics)

        self.mpics_scroll.add_with_viewport(event_box)
        self.mpics_scroll.set_policy(gtk.POLICY_NEVER, \
              gtk.POLICY_NEVER)

        event_box.connect("button-press-event", self.pressimg)
        event_box.connect('motion-notify-event', self.scrollimg)
The main difference with your code is that there is no
Code:
          self.oldxpos = event.x
          self.oldypos = event.y
in the scrollimg method (but there is in the pressimg method), because this makes everything flickr BOTH in N800 and the desktop, added to the craziness described above. I also found that things like
Code:
   event_box.set_events(gtk.gdk.BUTTON_MOTION_MASK)
made no difference at all.

Please, any help would be appreciated.

Thanks again for your time!

Cheers,

L.

Last edited by luis; 2011-02-21 at 21:23.
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#14
I'll take a look, but I might not be able to get to it till Wednesday.
__________________
N9: Go white or go home
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#15
Originally Posted by daperl View Post
I'll take a look, but I might not be able to get to it till Wednesday.
Oh, of course no problem, it is not an easy thing. You're very kind!!
Thank you so much!

BTW, I tried to send the signals to the scrolledwindow (self.mpics_scroll) instead of the eventbox, and took the ".parent" in the methods. Same thing: works perfectly in the linux box, crazy on the N800.

Thanks a trillion again!

Cheers,
L.
 
Posts: 146 | Thanked: 15 times | Joined on Oct 2008
#16
Hi daperl,
I solved the problem. It was actually tricky needing three modifications, and I don't quite understand how this works. I post it here cause it could be useful to others.

Part of the solution was pointed out by this small drawing script:

http://www.pygtk.org/pygtk2tutorial/...ibblesimple.py

Here, it is used a few lines of a property called "HINT". In my scrolling function, it reads:

Code:
        if event.is_hint:
            xpos, ypos, state = \
                             event.window.get_pointer()
        else:
            xpos = event.x
            ypos = event.y
            state = event.state
        if state & gtk.gdk.BUTTON1_MASK:
             ...
So there is a 'is_hint' property that should be caught. This is the thing I don't understand. To link to this property, it was needed to create the event:

Code:
event_box.set_events(gtk.gdk.POINTER_MOTION_HINT_MASK)
And the third crucial modification was to unset the default positions if scrolling fails, with:

Code:
self.oldxpos = -1
self.oldypos = -1
So, the final complete code (of the 3 relevant parts) looks like this:

Code:
    def scrollimg(self, swi, event):
    "The method that actually scrolls"
        if event.is_hint:
            xpos, ypos, state = \
                      event.window.get_pointer()
        else:
            xpos = event.x
            ypos = event.y
            state = event.state
        if state & gtk.gdk.BUTTON1_MASK:
            swih = swi.props.hadjustment
            swiv = swi.props.vadjustment
            if xpos != self.oldxpos:
               aux = swih.value + self.oldxpos - xpos
               if swih.lower <= aux and aux <= \
                        swih.upper - swih.page_size:
                    swih.value = aux
            if ypos != self.oldypos:
               aux = swiv.value + self.oldypos - ypos
               if swiv.lower <= aux and aux <= \
                       swiv.upper - swiv.page_size:
                    swiv.value = aux
        else:
            self.oldxpos = -1
            self.oldypos = -1

    def pressimg(self, swi, event):
    "The method that sets the initial positions"
        self.oldxpos = event.x
        self.oldypos = event.y

def __init__(self):
          ...
        self.mpics_scroll = gtk.ScrolledWindow(None, None)
        event_box = gtk.EventBox()
        self.mpics = gtk.Image()
        event_box.add(self.mpics)
        event_box.set_above_child(True)
        self.mpics_scroll.add_with_viewport\
             (event_box)

        self.mpics_scroll.connect\
             ("button-press-event", self.pressimg)
        self.mpics_scroll.connect
             ("motion-notify-event", self.scrollimg)
        event_box.set_events\
             (gtk.gdk.POINTER_MOTION_HINT_MASK)

         ....
Hope this helps to others, and thanks for the help,
L.

Last edited by luis; 2011-02-24 at 03:01. Reason: Formatting
 

The Following User Says Thank You to luis For This Useful Post:
Reply


 
Forum Jump


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