Reply
Thread Tools
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#1
I have a python application that I want to implement key-press scrolling on. I already have all the main frame code in place, just have no idea how to scroll something.

Here is the important part of the code:

Code:
   def on_key_press(self, widget, event, *args):
      if event.keyval == gtk.keysyms.F6:
      # The "Full screen" hardware key has been pressed
         if self.window_in_fullscreen:
            self.window.unfullscreen()
         else:
            self.window.fullscreen()

      if event.keyval == gtk.keysyms.F7:
         self.zoom_in_button_callback(self.textview)

      if event.keyval == gtk.keysyms.F8:
         self.zoom_out_button_callback(self.textview)
This function is called when I catch the key-press-event, and as you probably know, the if statements catch the correct key and executes the appropriate function.

I know I need to add if statements to catch the Up/Down key buttons, but how to you scroll a textview and/or scrolledwindow?

The textview is self.textview and scrolledwindow is self.sw (to complicate matters, the scrolledwindow can either be a gtk.ScrolledWindow or mokoui.FingerScroll object).

Any help is appreciated.
 
Posts: 1,950 | Thanked: 1,174 times | Joined on Jan 2008 @ Seattle, USA
#2
This is probably no help, but you know this?

http://www.internettablettalk.com/wi...e_Key_bindings

.
 

The Following User Says Thank You to GeraldKo For This Useful Post:
TrueJournals's Avatar
Posts: 480 | Thanked: 378 times | Joined on Apr 2008 @ Chicago-ish
#3
Not going to write any test code, so I haven't tried this at all... First I think you'll need to test for whether it's a ScrolledWindow or FingerScroll... For a ScrolledWindow, use gethadjustment(), then set the value of the returned gtk.Adjustment to some increment above or below its current value, then use sethadjustment() on the ScrolledWindow.

I hope that made sense. Not sure about the FingerScroll.

[edit]Here's some mostly-code:
Code:
if event.keyval == (UP keysym):
    if type(self.sw) == type(gtk.ScrolledWindow()):
        adj = self.sw.get_vadjustment()
        val = adj.get_value()
        adj.set_value(val+(adjustment))
        self.sw.set_vadjustment(adj) # Not sure if this is necessary
    elif type(self.sw) == type(mokoui.FingerScroll()):
        pass
        #Not sure about this
Obviously, this leaves about some values, and I haven't looked into mokoui.FingerScrol. You would also want to test that mokoui is imported before you just call type(mokoui.FingerScroll())

[edit2]Looking at mokoui... I believe the code would be the same as the scrolledwindow code, so no need to type test. Again, I haven't tried this at all (I've never even dealt with mokoui before).
__________________
Disclaimer: If a program I wrote doesn't work/breaks your tablet... It's not my fault
mcedit | Utility Calculators (WIP) | PyRDesktop
My Blog | Twitter

Last edited by TrueJournals; 2009-04-04 at 23:53.
 

The Following User Says Thank You to TrueJournals For This Useful Post:
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#4
Originally Posted by GeraldKo View Post
This is probably no help, but you know this?

http://www.internettablettalk.com/wi...e_Key_bindings

.
Yeah, that is kinda for Microb, this is different.
 
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#5
Originally Posted by TrueJournals View Post
Not going to write any test code, so I haven't tried this at all... First I think you'll need to test for whether it's a ScrolledWindow or FingerScroll... For a ScrolledWindow, use gethadjustment(), then set the value of the returned gtk.Adjustment to some increment above or below its current value, then use sethadjustment() on the ScrolledWindow.

I hope that made sense. Not sure about the FingerScroll.

[edit]Here's some mostly-code:
Code:
if event.keyval == (UP keysym):
    if type(self.sw) == type(gtk.ScrolledWindow()):
        adj = self.sw.get_vadjustment()
        val = adj.get_value()
        adj.set_value(val+(adjustment))
        self.sw.set_vadjustment(adj) # Not sure if this is necessary
    elif type(self.sw) == type(mokoui.FingerScroll()):
        pass
        #Not sure about this
Obviously, this leaves about some values, and I haven't looked into mokoui.FingerScrol. You would also want to test that mokoui is imported before you just call type(mokoui.FingerScroll())

[edit2]Looking at mokoui... I believe the code would be the same as the scrolledwindow code, so no need to type test. Again, I haven't tried this at all (I've never even dealt with mokoui before).
I just tested the code, using gtk.SROLL_PAGE_UP as the adjustment value, and it works (with a couple issues). The only problem is that it scrolls by small margins, so I tried:

Code:
adj.set_page_increment(gtk.SCROLL_PAGES)
But it says "AttributeError: 'gtk.Adjustment' object has no attribute 'set_page_increment'", which is strange. Because the pygtk reference seems to disagree...Also mokoui.FingerSroll seems to have a completely different api, because it doesn't have a gtk.Adjustment. I'll figure that out, but the first thing is stumping me.

Last edited by BrentDC; 2009-04-05 at 01:42.
 
TrueJournals's Avatar
Posts: 480 | Thanked: 378 times | Joined on Apr 2008 @ Chicago-ish
#6
Hmm... strange, but it seems to be a very surface-level problem. Try this:
Code:
adj.page_incrment = gtk.SCROLL_PAGES
__________________
Disclaimer: If a program I wrote doesn't work/breaks your tablet... It's not my fault
mcedit | Utility Calculators (WIP) | PyRDesktop
My Blog | Twitter
 
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#7
Today I really tried to get this working...but to no avail. My code is as follows:

Code:
      if event.keyval == gtk.keysyms.Up:
         adj = self.sw.get_vadjustment()
         adj.page_increment = gtk.SCROLL_PAGES
         val = adj.get_value()
         adj.set_value(val+(gtk.SCROLL_PAGE))
         self.sw.set_vadjustment(adj)
If anyone has any other ideas, I'll try 'em out, but if not, I'll just not implement hardware key scrolling (I don't think it's a huge deal).
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#8
Originally Posted by BrentDC View Post
Code:
      if event.keyval == gtk.keysyms.Up:
         adj = self.sw.get_vadjustment()
         adj.page_increment = gtk.SCROLL_PAGES
         val = adj.get_value()
         adj.set_value(val+(gtk.SCROLL_PAGE))
         self.sw.set_vadjustment(adj)
If you're paging up, shouldn't that be a minus sign? Also, aren't you missing an 'S'?
__________________
N9: Go white or go home
 
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#9
Also, you're not using the most important gtk.Adjustment attribute: 'page_size'.

And don't forget end conditions. Here's some code:

Code:
def pageup(self, sw):
    newval = sw.props.vadjustment.value - sw.props.vadjustment.page_size
    if newval < sw.props.vadjustment.lower: newval = sw.props.vadjustment.lower
    sw.props.vadjustment.value = newval
Just use the ScrolledWindow properties. pagedown in next post.
__________________
N9: Go white or go home

Last edited by daperl; 2009-04-06 at 01:57.
 

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
#10
Code:
def pagedown(self, sw):
    newval = sw.props.vadjustment.value + sw.props.vadjustment.page_size
    max = sw.props.vadjustment.upper - sw.props.vadjustment.page_size
    if newval > max: newval = max
    sw.props.vadjustment.value = newval
__________________
N9: Go white or go home
 

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

Tags
python


 
Forum Jump


All times are GMT. The time now is 12:44.