how to create windows 7 jump lists via python/pyqt? - python

i have a pyqt project which i'm interested in using to play around with the new windows 7 jump list feature. after a bunch of searching, i have not found any specific examples of anyone creating jumplists via python.
has anyone here found an easy way to hook into this? does mark hammond's pywin32 module have an appropriate wrapper?
thanks!

I don't think Qt supports jump lists, you can find a bit more info here
Qt 4.6 added support for windows 7 and it was released today but I don't think they added this specific feature and I don't think PyQt supports this release.

There is a Qt add-on that implements all the Windows 7 taskbar extensions. It is called Q7Goodies. Although, it is a C++ library, I suggest contacting the authors, maybe they provide a PyQt bindings too.

Ah well after 12 years Imma answer this XD.
There is an add-on introduced in Qt 5.2 named "QtWinExtras/Windows Extras". As explained by the docs:
Qt Windows Extras provide classes and functions that enable you to use miscellaneous Windows-specific functions. For example, you can convert Qt objects to Windows object handles and manipulate DWM glass frames.
In addition, you can use features introduced with Windows 7, such as Aero Peek, Jump Lists, a progress indicator on a taskbar button, or a thumbnail toolbar.
You can check the code bellow as an example:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel
from PyQt5.QtWinExtras import QWinJumpList, QWinJumpListItem
class Form(QMainWindow):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.resize(350, 150)
self.setWindowTitle("Windows Jump Lists")
label = QLabel("Right click the taskbar button")
label.resize(label.sizeHint())
label.setAlignment(Qt.AlignCenter)
self.setCentralWidget(label)
jump_list = QWinJumpList()
tasks = jump_list.tasks()
taskmgr = QWinJumpListItem(QWinJumpListItem.Link)
taskmgr.setTitle("Open Task Manager")
taskmgr.setFilePath("C:\\Windows\\system32\\taskmgr.exe")
tasks.addItem(taskmgr)
tasks.setVisible(True) # Necessary
self.show()
app = QApplication(sys.argv)
form = Form()
sys.exit(app.exec_())
You can check some examples here.
For more information you can check the official documentation

Related

Text tree in Python GUI

I'm looking for GUI feature that will be part of Python desktop application.
The feature is a text tree with drag and drop functionality between individual nodes.
Further I'd like to be able to attach a note with longer text to individual nodes in the tree. The note would be switchable to expanded or collapsed state.
It is exactly shown in this NestedSortable JQuery library except of the switchable note.
Could you show me what are the possibilities of contemporary Python GUIs according to this feature? I prefer lightweight GUI with modern look as in the JQuery example.
Which GUI would be the most suitable for this task? Tkinter, wxPython, pyQt, pyGTK or other? Or would you choose some GUI + Javascript libraries? Why would you prefer particular GUI to achieve requested functionality and lightweight modern design?
pyQT has a good solution for this with its QTreeWidget or a MVC setup. QTreeWidget is simplest:
Here's a small example using PyQt4
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.treewidget = QTreeWidget(self)
self.treewidget.setHeaderLabels(['a'])
self.treewidget.setDragEnabled(True)
self.treewidget.setAcceptDrops(True)
self.treewidget.setDropIndicatorShown(True)
self.treewidget.resize(300,300)
self.titems = []
for i in xrange(100):
if not i%10:
pitem = QTreeWidgetItem(self.treewidget,["Parent %d"%i])
self.titems.append(pitem)
else:
item = QTreeWidgetItem(pitem,["Child of %d"%i])
self.titems.append(item)
self.show()
app = QApplication(sys.argv)
w = MainWindow()
app.exec_()
Try using etetoolkit. Its much simpler.

pyqt Playing movie files in phonon player QT4.9

I'm definitely in need of your help guys.. As in really.
My laptop has been stolen and I didn't have a backup of my
pyqt phonon video player that I made a year ago. I forgot how and what to do to recreate it.
I only know some key things to do for it to work. So please help me out.
From what i can remember I need to
Set backend capabilities (set phonon backend to windows media player?)
Install the required codecs (which i dont have a copy of)
Code the program (and sadly I forgot how to play a video)
If there's someone out there who have a working sample python videoplayer,
can you please share it with me?
I'm trying it right now and my sample doesn't work at all
from PyQt4.phonon import Phonon
media_source = phonon.Phonon.MediaSource("C:\\Sample.avi")
self.ui.videoPlayer.load(media_source)
self.ui.videoPlayer.play()
Please help me. And thank you very much to you guys.
I'm using python 2.6 and qt version 4.9. Now I'm coding on a virtual box windows XP
EDIT:
got a following sample with this problem but..
having this error when loading a file.
"The Operation Cannot Be Performed Because the Pins Are Not Connected"
This maybe because I'm using a virtual box in Ubuntu?
Don't forget to show() the videoplayer. For the rest, in my experience Phonon often has trouble finding the codecs needed to play videos on Windows. Installing K-Lite codec pack might work in that situation.
Here's a self-contained example that does work for me (Windows Vista32, Python 2.6.5, PyQt 4.7.3).
import sys
from PyQt4 import QtCore, QtGui
from PyQt4.phonon import Phonon
app = QtGui.QApplication(sys.argv)
vp = Phonon.VideoPlayer()
media = Phonon.MediaSource('C:\\video.mp4')
vp.load(media)
vp.play()
vp.show()
sys.exit(app.exec_())
Edit:
Multiple people have recently commented that the above code no longer gives the desired behavior. I haven't worked with PyQt in ages, but I suspect that one of the updates might have changed Phonon functionality.
According to the commenters, vp.show() now needs to be called before Phonon.MediaSource(), i.e.:
...
vp = Phonon.VideoPlayer()
vp.show()
media = Phonon.MediaSource('C:\\video.mp4')
vp.load(media)
vp.play()
sys.exit(app.exec_())

Can I create a panel-like thing on Windows with Python?

Sorry for the vague title, couldn't come up with anything more informative %)
What I want is a 5px horizontal panel on the top of the screen that I can draw on (and, possible, handle clicks on too).
One of the following features would be awesome (although I understand it's probably not really possible to combine both of them):
the panel should be just like the Windows's own taskbar, i.e., maximized windows should not overlap it, but start below it instead
the panel should show in fullscreen apps too
Is it possible to do this in Python?
Thanks.
Yes, it's possible. The "how" part depends on the GUI library you choose for which there are many options, but most people will recommend the following two: wxPython or PySide which is Qt for Python.
PySide has good documentation and tutorials.
What you will want to do is create a QMainWindow instance and set the WindowFlags to your requirements. You probably want the following combination Qt::Window | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint.
Something like this:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
class Form(QMainWindow):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the form
form = Form()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())
Note, that there is a limit to the "staying on top" nature of such windows. There are Win32-specific ways to fight it and get even higher, but such requirement would be a design error.

Cross-platform Python GUI suitable for taskbar (Win) and menubar (mac) functionality?

I am fairly new to Python programming, and completely new to cross-platform GUI building (only previous GUI experience is through visual basic and Java).
I've written some python code to screen-scrape data from a website, and now I want to build a GUI that will reside in the Mac OS X menubar, and in Window's task bar (i.e., the system tray).
The most useful general page on cross-plaform Python GUIs for me was this one (despite its name indication Window GUIs). And some stackoverflow questions came in useful as well (especially this one, and the accepted answer of this one about splitting up the GUI and cli code).
I think I will go for either wxPython or QT because I want the GUI to look as native as possible.
However, as I've said the fairly simple GUI will mainly live in the taskbar/menubar.
Should this influence my decision?
Here's an example for PyQt. This works for me on MacOS X; I haven't tried it on other platforms. Note that the QSystemTrayIcon class will raise exceptions if it doesn't have an icon – I grabbed the RSS feed svg from Wiki commons for my icon.svg (but you can give QIcon a PNG directly and not mess around with QtSvg).
import PyQt4
from PyQt4 import QtCore, QtGui, QtSvg
app = QtGui.QApplication([])
i = QtGui.QSystemTrayIcon()
m = QtGui.QMenu()
def quitCB():
QtGui.QApplication.quit()
def aboutToShowCB():
print 'about to show'
m.addAction('Quit', quitCB)
QtCore.QObject.connect(m, QtCore.SIGNAL('aboutToShow()'), aboutToShowCB)
i.setContextMenu(m)
svg = QtSvg.QSvgRenderer('icon.svg')
if not svg.isValid():
raise RuntimeError('bad SVG')
pm = QtGui.QPixmap(16, 16)
painter = QtGui.QPainter(pm)
svg.render(painter)
icon = QtGui.QIcon(pm)
i.setIcon(icon)
i.show()
app.exec_()
del painter, pm, svg # avoid the paint device getting
del i, icon # deleted before the painter
del app
See this related SO answer on how to accomplish Windows system tray/OS X menu bar functionality in wxPython.

System theme icons and PyQt4

I'm writing a basic program in python using the PyQt4 module. I'd like to be able to use my system theme's icons for things like the preference dialog's icon, but i have no idea how to do this. So my question is, how do you get the location of an icon, but make sure it changes with the system's icon theme? If it matters, i'm developing this under ubuntu 9.04, so i am using the gnome desktop.
Unfortunately, It appears that Qt does not support getting icons for a specific theme. There are ways to do this for both KDE and Gnome.
The KDE way is quite elegant, which makes sense considering that Qt is KDE's toolkit. Instead of using the PyQt4.QtGui class QIcon, you instead use the PyKDE4.kdeui class KIcon. An example of this is:
from PyKDE4.kdeui import *
icon = KIcon("*The Icon Name*")
see the PyKDE documentation for this class, here.
One way to gain support for this for gnome is to use the python gtk package. It is not as nice as the kde way, but it works none the less. It can be used like this:
from PyQt4 import QtGui
from gtk import icon_theme_get_default
iconTheme = icon_theme_get_default()
iconInfo = iconTheme.lookup_icon("*The Icon Name*", *Int of the icon size*, 0)
icon = QtGui.QIcon(iconInfo.get_filename())
See the documentation for the Icon Theme class and Icon Info class.
EDIT: thanks for the correction CesarB
Use the PyKDE4 KIcon class:
http://api.kde.org/pykde-4.2-api/kdeui/KIcon.html
I spent a decent amount of researching this myself not long ago, and my conclusion was that, unfortunately, Qt doesn't provide this functionality in a cross-platform fashion. Ideally the QIcon class would have defaults for file open, save, '+', '-', preferences, etc, but considering it doesn't you'll have to grab the appropriate icon for your desktop environment.

Categories

Resources