Active Topics

 


Reply
Thread Tools
Posts: 842 | Thanked: 1,197 times | Joined on May 2010
#1
I am working on developing a comic/image viewer frontend for an application I'm designing.

Now, what I'd like to end up with is similar to the built-in image viewer(at least, the actual "show image" part), but with some differences.

I'm looking at:
1. Displaying an image with some text below it. Currently I'm using QTextBrowser, which seems to do the job.
2. Scaling of both text and image. I just need to be able to either set a % or get the current width and be able to set a pixel #.
2.5. Relatedly, I need to figure out how to get button presses of the zoom/volume keys.
3. Having portrait mode support(at least manually, through a setting).
4. Being able to slide your finger on the touchscreen to switch between images(Like how the built-in viewer does it).
5. long-press/right-click menu for whatever I end up using as my image/text viewer. How can I set this up?
6. Some sort of "multi-page" interface, like the image-viewer: You can click the "back" button in the upper right-hand corner to view another page(in that case, a list of images). In my case, it will be a QTreeWidget object.

Can you guys point me to some pages, tutorials and or code-snippets that might help me with these things?

Thanks,

-RobbieThe1st
 

The Following User Says Thank You to RobbieThe1st For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#2
woah, lots of questions - i'm by no means an authority on anything pyqt but here goes!

1) Text Browser (Opening an HTML File, so it could assist in opening an image if you want!)
Code:
self.textBrowser = QtGui.QTextBrowser(self.tab_4)
self.textBrowser.setGeometry(QtCore.QRect(0, 10, 781, 301))
self.textBrowser.setOpenExternalLinks(True)
fsock = os.popen('cat /home/opt/healthcheck/about.txt').read()
self.textBrowser.setHtml(fsock)
# self.textBrowser.setText (fsock)
# Make the font small!!!
font = QtGui.QFont()
font.setPointSize(20)
2. Scaling of both text and image. - May i ask scaling dependent on what? As scaling normally depends on something changing... - the above example shows the font size being set/changed.
But i assume you mean auto-rotate style repositioning. What you would need to do is to read the width and height and compare it to the current max width or height (800*420 without top bar)
Another way, is to have a slide in menu like the new firefox 4 example- that way whats on your screen can stay it's normal size?

2.5. Relatedly, I need to figure out how to get button presses of the zoom/volume keys.
I think 1up in the repos is pyqt and uses these keys - http://maemo.org/downloads/product/Maemo5/1up/ - if it is, might be worth downloading the code and taking a look
My assumption, but i dont know how to map the hw keys, sorry!

3. Having portrait mode support(at least manually, through a setting).
This relates to number two! - http://forums.internettablettalk.com...t=31940&page=3 - should help!

4. No idea, sorry! Well kinda, the healthcheck code reads in and detects screen location, if you can use that to detect movements of a specific type it should work
Code:
def mouseMoveEvent(self, event):
        self.mousePressPos = QtCore.QPoint(event.pos())
        if self.mousePressPos.isNull():
            event.ignore()
            return
        self.x = self.mousePressPos.x()
        self.y = self.mousePressPos.y()
        event.accept()
        self.update()
5. I think what you mean is a context menu? - as far as i am aware you set up a menu the same as you would for the title/top menu but just call it differently?
http://www.riverbankcomputing.co.uk/...tml/qmenu.html
Code:
import sys
from PyQt4.QtCore import Qt
from PyQt4.QtGui import *

class TableWidget(QTableWidget):

    def __init__(self, parent = None):

        QTableWidget.__init__(self, parent)

    def contextMenuEvent(self, event):

        menu = QMenu(self)
        quitAction = menu.addAction("Quit")
        action = menu.exec_(self.mapToGlobal(event.pos()))
        if action == quitAction:
            qApp.quit()

app = QApplication([])
tableWidget = TableWidget()
tableWidget.show()
sys.exit(app.exec_())
Look here for more info though - http://diotavelli.net/PyQtWiki/Handl...ontext%20menus )

6. Check the healthcheck pages for multipage stuff, the tools page tools stuff mainly load up in new windows.

Sorry typed it all a bit quick, as heading out! hope that helps!
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 

The Following 5 Users Say Thank You to noobmonkey For This Useful Post:
Posts: 842 | Thanked: 1,197 times | Joined on May 2010
#3
@noobmonkey:
Thanks.

1. Yea, I have QTextBrowser code working, but I'm not sure it will let me do what I want(especially #2).
2. Thing is, some comics and images look fine scaled down to the resolution of the screen. Some don't.
I intend to have an back-end option that will allow the user to select between scrolling(full-size) and scaled to the screen-size.
Making it match the width, that's easily done. Its getting access to a function that allows me to scale the image onscreen to whatever dimensions I choose that's the issue. More importantly, I need to be able to scale the image [i]using a good[/url] scaling algorithm, just like with the image viewer. Nearest-neighbor etc. just won't do.
Now, last I checked, I could add a pixel-width to the img in the HTML code I'm sending to QTextBrowser, but I'm not sure I could externally change it without reloading the whole code etc. This may be the best option, but I'm really wondering if there's a better widget.

With 3, thanks for that. However, do you know of any -manual- rotation function? I'd like to be able to lock it in portrait mode based on a setting or two.

4. Alright, but there's got to be some sort of library for doing this; it seems kludgy to simply poll the cursor whenever the mouse "button" is down, and then try to extrapolate motion from that.

5. Yes, that's what I mean - I'm just slightly worried about content inside the QTextView(etc) overriding my menu - I'm trying to make the menu appear anywhere, not just where there's no image.

6. Alright, I'll see what I can do...
 

The Following User Says Thank You to RobbieThe1st For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#4
Originally Posted by RobbieThe1st View Post
@noobmonkey:
Thanks.

1. Yea, I have QTextBrowser code working, but I'm not sure it will let me do what I want(especially #2).
2. Thing is, some comics and images look fine scaled down to the resolution of the screen. Some don't.
I intend to have an back-end option that will allow the user to select between scrolling(full-size) and scaled to the screen-size.
Making it match the width, that's easily done. Its getting access to a function that allows me to scale the image onscreen to whatever dimensions I choose that's the issue. More importantly, I need to be able to scale the image [i]using a good[/url] scaling algorithm, just like with the image viewer. Nearest-neighbor etc. just won't do.
Now, last I checked, I could add a pixel-width to the img in the HTML code I'm sending to QTextBrowser, but I'm not sure I could externally change it without reloading the whole code etc. This may be the best option, but I'm really wondering if there's a better widget.

With 3, thanks for that. However, do you know of any -manual- rotation function? I'd like to be able to lock it in portrait mode based on a setting or two.

4. Alright, but there's got to be some sort of library for doing this; it seems kludgy to simply poll the cursor whenever the mouse "button" is down, and then try to extrapolate motion from that.

5. Yes, that's what I mean - I'm just slightly worried about content inside the QTextView(etc) overriding my menu - I'm trying to make the menu appear anywhere, not just where there's no image.

6. Alright, I'll see what I can do...
3) you can set the rotation as you wish using very similar examples.
This one is in python so you can just translate the others (In c++ i think)
self.setAttribute(QtCore.Qt.WA_Maemo5AutoOrientati on, True)

setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);

An example in c .....
Code:
  QRect screenGeometry = QApplication::desktop()->screenGeometry();
         if (screenGeometry.width() > screenGeometry.height())
             label->setText("<p align=\"center\">In Landscape Mode</p>");
         else
             label->setText("<p align=\"center\">In Portrait Mode</p>");
4) Get on IRC - and have a chat with someone like W00t or frals - they should be able to help or point you in the right way (Not everyone comes in the forums!)

5) Took me a while to get a normal menu working! I know you can position it depending on where they press , but i have no experience, if you come up with a good example post it for all to see in the wiki!
But i'd definitley hunt through the repos for some example python apps that do it already!

As soon as i get a bit of time i'll try and do some proper examples - just got back from hols and back to work monday, so frantically washing, cleaning etc! :P
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Reply


 
Forum Jump


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