Re: Using PyQT with QT Designer

2013-08-22 Thread tausciam
On Thursday, August 22, 2013 3:26:17 AM UTC-5, Phil Thompson wrote:

 It looks like you aren't using a layout to arrange your widgets.
 
 Explicitly specifying geometries is a bad idea.
 
 
 
 Phil

Thanks.QT Designer uses set geometry and I'm totally lost as how to implement 
it. I've tried using a layout on the central widget. I've tried specifically 
referencing the Ui_MainWindow in the window.py ui file...

This is what I tried:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from window import Ui_MainWindow
 
THUMBNAIL_SIZE = 128
SPACING= 10
IMAGES_PER_ROW = 4

class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()

#self.setWindowTitle(Image Gallery)

centralWidget=QWidget(self)
l=QVBoxLayout(centralWidget)

self.tableWidget=TableWidget(self)
l.addWidget(self.tableWidget)

self.listWidget=ListWidget(self)
l.addWidget(self.listWidget)

Ui_MainWindow.pushButton = QPushButton(self)
l.addWidget(Ui_MainWindow.pushButton)

self.pushButton_2 = QPushButton(self)
l.addWidget(self.pushButton_2)

self.pushButton_3 = QPushButton(self)
l.addWidget(self.pushButton_3)
 
self.setCentralWidget(centralWidget)
 

picturesPath=QDesktopServices.storageLocation(QDesktopServices.PicturesLocation)
pictureDir=QDir(picturesPath)
pictures=pictureDir.entryList(['*.jpg','*.png','*.gif'])
 
rowCount=len(pictures)//IMAGES_PER_ROW
if len(pictures)%IMAGES_PER_ROW: rowCount+=1
self.tableWidget.setRowCount(rowCount)
 
row=-1
for i,picture in enumerate(pictures):
col=i%IMAGES_PER_ROW
if not col: row+=1
self.tableWidget.addPicture(row, col, 
pictureDir.absoluteFilePath(picture))

class ListWidget(QListWidget):
def __init__(self, parent=MainWindow, **kwargs):
QListWidget.__init__(self, parent, **kwargs)

self.setGeometry(QRect(70, 400, 661, 181))

class TableWidget(QTableWidget):
def __init__(self, parent=MainWindow, **kwargs):
QTableWidget.__init__(self, parent, **kwargs)
 
self.setIconSize(QSize(128,128))
self.setColumnCount(IMAGES_PER_ROW)
self.setGridStyle(Qt.NoPen)

# Set the default column width and hide the header
self.verticalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)
self.verticalHeader().hide()
 
# Set the default row height and hide the header
self.horizontalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)
self.horizontalHeader().hide()
 
# Set the table width to show all images without horizontal scrolling

self.setMinimumWidth((THUMBNAIL_SIZE+SPACING)*IMAGES_PER_ROW+(SPACING*2))
 
def addPicture(self, row, col, picturePath):
item=QTableWidgetItem()
 
# Scale the image by either height or width and then 'crop' it to the
# desired size, this prevents distortion of the image.
p=QPixmap(picturePath)
if p.height()p.width(): p=p.scaledToWidth(THUMBNAIL_SIZE)
else: p=p.scaledToHeight(THUMBNAIL_SIZE)
p=p.copy(0,0,THUMBNAIL_SIZE,THUMBNAIL_SIZE)
item.setIcon(QIcon(p))
 
self.setItem(row,col,item)

 
if __name__==__main__:
from sys import argv, exit
 
a=QApplication(argv)
m=MainWindow()
m.show()
m.raise_()
exit(a.exec_())

and I'm getting this (not even starting at 800x600): 
http://i.imgur.com/Xg4Qnzl.png

instead of this as it was designed in QT Designer: 
http://i.imgur.com/ULRolq8.png

Here is the ui file window.py that I got by running pyuic4 on window.ui:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'window.ui'
#
# Created by: PyQt4 UI code generator 4.9.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8(MainWindow))
MainWindow.resize(800, 600)
MainWindow.setAnimated(False)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8(centralwidget))
self.tableWidget = QtGui.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(70, 20, 661, 381))

Re: Using PyQT with QT Designer

2013-08-23 Thread tausciam
Thank you. I just deleted all of them, reran pyuic4 on window.ui and 
regenerated window.py just to make sure. Unfortunately, I get the same problem.

I've got the GUI perfectly designed just like I want it in window.py... just 
can't figure out how to use it in my program.

On Friday, August 23, 2013 3:16:59 PM UTC-5, Dave Angel wrote:
 Michael Staggs wrote:
 
 
 
 
 
 
 
  That's the problem though. It is exactly how I want it in designer. It's
 
  perfect as it is in designer when I preview it. Here is a screenshot of the
 
  preview: http://i.imgur.com/ULRolq8.png
 
 
 
  The problem isn't that I can't design it in QT Designer. It is designed
 
  just like I want it. The problem is, when I try to follow zetcode and other
 
  tutorials about how to import and use my form as designed by qt designer
 
  and run through pyuic4 it doesn't seem to even notice my ui file...and
 
  certainly isnt acting on it.
 
 
 
 
 
 I don't know PyQT, so I've kept quiet so far...
 
 
 
 You don't say what the name of the generated file is, but perhaps since
 
 the source file was window.ui, the generated one is window.py
 
 
 
 My guess is that when you do the
 
 
 
 from window import Ui_MainWindow
 
 
 
 it is finding some OTHER window.py file.
 
 
 
 Have you tried simply adding an illegal line to the generated file, to
 
 force the compiler to fail the import?  Once you're sure that it is
 
 importing this particular file, you can remove such a line.
 
 
 
 Could be that you have some other window.py file  (or window.pyc, or
 
 whatever) and that it's finding that one.  Or it's finding some older
 
 version of this one.
 
 
 
 
 
 
 
 -- 
 
 DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using PyQT with QT Designer

2013-08-23 Thread tausciam
Thank you... I found my problem 

class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)

That seems to take care of it... if I comment out everything else, I get my 
pristine form 

I don't know if it's the super call or the setupuibut one of those was my 
godsend.

So, that is solved... I just have to figure out how to put things in the gui 
where I want thembut I think you're right at any rate. If I try to resize, 
it doesn't function like I thought it would. I will have to use layouts.. but 
at least now I am able to use the UI file that I created.

On Friday, August 23, 2013 7:35:53 PM UTC-5, Lee Harr wrote:
  That's the problem though. It is exactly how I want it in designer. It's
  perfect as it is in designer when I preview it. Here is a screenshot of the
  preview: http://i.imgur.com/ULRolq8.png
 
 That's not a preview. That's just the regular design view.
 (you can tell by the little dots in the background)
 
 You need to go to Form - Preview... to see the actual preview.
 
 That said...
 
 1.) You may want to ask your question on the PyQt mailing list. Though
 you are talking with the undisputed PyQt expert in Phil, there are more
 people on the other list who are familiar with PyQt and who may be willing
 to look more closely at your specific code.
 
 2.) It may be that the examples you are looking at are not sufficient to
 help you with the situation you are in. For instance, I've written several
 programs using Designer and PyQt and I would recommend against
 using the pyuic method.
 
 When I first started with PyQt I also used pyuic and eventually I found
 the PyQt4.uic method works better for me.
 
 3.) Layouts. You have to use them with Qt or you're going to have a
 bad time.
 
 Looking at your design, I would do something like ...
 
 - select the two buttons on the left and click Lay Out Vertically
 - select the two large white boxes and click Lay Out Vertically
 - put a vertical spacer underneath the red X button
 - select the red button and the spacer and click Lay Out Vertically
 - at this point you may need to resize and rearrange your three vertical
    layouts so that they don't overlap and are in approximately the positions
    that you want, then
 - select the main window and click Lay Out Horizontally
 
 Something along those lines would get you about to where you want
 to be. The form may not look _exactly_ the way you have it there, but
 it will be a more flexible design and nothing will be overlapping.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using PyQT with QT Designer

2013-08-24 Thread tausciam
Thanks. I probably will do exactly like you suggested later on. But, those two 
lines have solved the problem I had and I can work on the actual program now. I 
can come back to the GUI later.

Here is what it looks like now: http://i.imgur.com/sLiSU6M.png

On Friday, August 23, 2013 7:35:53 PM UTC-5, Lee Harr wrote:
  That's the problem though. It is exactly how I want it in designer. It's
  perfect as it is in designer when I preview it. Here is a screenshot of the
  preview: http://i.imgur.com/ULRolq8.png
 
 That's not a preview. That's just the regular design view.
 (you can tell by the little dots in the background)
 
 You need to go to Form - Preview... to see the actual preview.
 
 That said...
 
 1.) You may want to ask your question on the PyQt mailing list. Though
 you are talking with the undisputed PyQt expert in Phil, there are more
 people on the other list who are familiar with PyQt and who may be willing
 to look more closely at your specific code.
 
 2.) It may be that the examples you are looking at are not sufficient to
 help you with the situation you are in. For instance, I've written several
 programs using Designer and PyQt and I would recommend against
 using the pyuic method.
 
 When I first started with PyQt I also used pyuic and eventually I found
 the PyQt4.uic method works better for me.
 
 3.) Layouts. You have to use them with Qt or you're going to have a
 bad time.
 
 Looking at your design, I would do something like ...
 
 - select the two buttons on the left and click Lay Out Vertically
 - select the two large white boxes and click Lay Out Vertically
 - put a vertical spacer underneath the red X button
 - select the red button and the spacer and click Lay Out Vertically
 - at this point you may need to resize and rearrange your three vertical
    layouts so that they don't overlap and are in approximately the positions
    that you want, then
 - select the main window and click Lay Out Horizontally
 
 Something along those lines would get you about to where you want
 to be. The form may not look _exactly_ the way you have it there, but
 it will be a more flexible design and nothing will be overlapping.

-- 
http://mail.python.org/mailman/listinfo/python-list


Phonon error: libv4l2: error getting pixformat: Invalid argument

2013-08-26 Thread tausciam
Here is my code. I'm just trying to play an mp3 that I've clicked in a PyQT 
listwidget:

@pyqtSlot()
def item_clicked(self):
row = self.listWidget.currentRow()
song = musiclist[row]
QCoreApplication.setApplicationName(Phonon)
output = Phonon.AudioOutput(Phonon.MusicCategory)
m_media = Phonon.MediaObject()
Phonon.createPath(m_media, output)
m_media.setCurrentSource(Phonon.MediaSource(song))
m_media.play() 

I'm running OpenSUSE Linux 12.3

Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Phonon error: libv4l2: error getting pixformat: Invalid argument

2013-08-27 Thread tausciam
Looking in /var/log/messages, every time I get that error I get:

[41553.128652] xc2028 9-0061: i2c input error: rc = -19 (should be 2)
[41553.152537] xc2028 9-0061: i2c input error: rc = -19 (should be 2)
[41553.355913] xc2028 9-0061: i2c input error: rc = -19 (should be 2)
[41553.379712] xc2028 9-0061: i2c input error: rc = -19 (should be 2)

and that's my video capture card! That has nothing to do with playing an mp3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Phonon error: libv4l2: error getting pixformat: Invalid argument

2013-08-27 Thread tausciam
It's not giving me an exception. Here is the code I used:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.phonon import Phonon
import os
import sys, traceback

def lumberjack():
song = '/home/tannhaus/Music/A Perfect Circle/eMOTIVE/02 Imagine.mp3'
QCoreApplication.setApplicationName(Phonon)
output = Phonon.AudioOutput(Phonon.MusicCategory)
m_media = Phonon.MediaObject()
Phonon.createPath(m_media, output)
m_media.setCurrentSource(Phonon.MediaSource(song))
m_media.play() 

class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)

try:
lumberjack()
except IndexError:
exc_type, exc_value, exc_traceback = sys.exc_info()
print *** print_tb:
traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
print *** print_exception:
traceback.print_exception(exc_type, exc_value, exc_traceback,
  limit=2, file=sys.stdout)
print *** print_exc:
traceback.print_exc()
print *** format_exc, first and last line:
formatted_lines = traceback.format_exc().splitlines()
print formatted_lines[0]
print formatted_lines[-1]
print *** format_exception:
print repr(traceback.format_exception(exc_type, exc_value,
  exc_traceback))
print *** extract_tb:
print repr(traceback.extract_tb(exc_traceback))
print *** format_tb:
print repr(traceback.format_tb(exc_traceback))
print *** tb_lineno:, exc_traceback.tb_lineno

if __name__==__main__:
from sys import argv, exit
 
a=QApplication(argv)
m=MainWindow()
m.show()
m.raise_()
exit(a.exec_())


When I run it, the complete and only error I get is:

libv4l2: error getting pixformat: Invalid argument

When I check /var/log/messages, I see these messages:

2013-08-27T18:12:04.163062-05:00 tannhaus-PC kernel: [ 1786.397499] xc2028 
9-0061: i2c input error: rc = -19 (should be 2)
2013-08-27T18:12:04.187054-05:00 tannhaus-PC kernel: [ 1786.421479] xc2028 
9-0061: i2c input error: rc = -19 (should be 2)
2013-08-27T18:12:04.391057-05:00 tannhaus-PC kernel: [ 1786.625614] xc2028 
9-0061: i2c input error: rc = -19 (should be 2)
2013-08-27T18:12:04.415052-05:00 tannhaus-PC kernel: [ 1786.649613] xc2028 
9-0061: i2c input error: rc = -19 (should be 2)


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Phonon error: libv4l2: error getting pixformat: Invalid argument

2013-08-27 Thread tausciam
I unplugged the tv capture card and got no errors at all. It didn't cause it to 
crash when I had it plugged in. However, it appears that it's not actually 
playing the mp3. I don't hear it at all. I checked my sound mixer and no 
channels are muted.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Phonon error: libv4l2: error getting pixformat: Invalid argument

2013-08-27 Thread tausciam
But, the PYQT example works:

https://github.com/Werkov/PyQt4/blob/master/examples/phonon/musicplayer.py#L1

It's just my code isn't working for some reason. I don't hear anything coming 
from it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Phonon error: libv4l2: error getting pixformat: Invalid argument

2013-08-27 Thread tausciam
When I pare down the code to the following, I can't hear the mp3 play either:

#!/usr/bin/env python

import sip
sip.setapi('QString', 2)

import sys

from PyQt4 import QtCore, QtGui
from PyQt4.phonon import Phonon



class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(QtGui.QMainWindow, self).__init__()   
self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
self.mediaObject = Phonon.MediaObject(self)
self.metaInformationResolver = Phonon.MediaObject(self)
Phonon.createPath(self.mediaObject, self.audioOutput)
self.sources = /home/tannhaus/Music/A Perfect Circle/eMOTIVE/02 
Imagine.mp3

self.metaInformationResolver.setCurrentSource(Phonon.MediaSource(self.sources))
self.mediaObject.play()

if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
app.setApplicationName(Music Player)
app.setQuitOnLastWindowClosed(True)

window = MainWindow()
window.show()

sys.exit(app.exec_())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Phonon error: libv4l2: error getting pixformat: Invalid argument

2013-08-27 Thread tausciam
I've played around with it and got code that plays mp3s now. I'm not sure what 
I was doing wrong or why it plays now...but it does, so I'm going to use it:

#!/usr/bin/env python

import sip
sip.setapi('QString', 2)

import sys

from PyQt4 import QtCore, QtGui
from PyQt4.phonon import Phonon



class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(QtGui.QMainWindow, self).__init__()   
self.sources = /home/tannhaus/Music/A Perfect Circle/eMOTIVE/02 
Imagine.mp3
self.mediaObject = Phonon.createPlayer(Phonon.MusicCategory)
self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
Phonon.createPath(self.mediaObject, self.audioOutput)
self.mediaObject.setCurrentSource(Phonon.MediaSource(self.sources))
self.mediaObject.play()

if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
app.setApplicationName(Music Player)
app.setQuitOnLastWindowClosed(True)

window = MainWindow()
window.show()

sys.exit(app.exec_())
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using PyQT with QT Designer

2013-08-30 Thread tausciam
Lee Harr, thank you. I took your suggestion after I finished coding the audio 
section. You can see the improved project here: http://i.imgur.com/permuRQ.jpg

On Friday, August 23, 2013 7:35:53 PM UTC-5, Lee Harr wrote:
  That's the problem though. It is exactly how I want it in designer. It's
  perfect as it is in designer when I preview it. Here is a screenshot of the
  preview: http://i.imgur.com/ULRolq8.png
 
 That's not a preview. That's just the regular design view.
 (you can tell by the little dots in the background)
 
 You need to go to Form - Preview... to see the actual preview.
 
 That said...
 
 1.) You may want to ask your question on the PyQt mailing list. Though
 you are talking with the undisputed PyQt expert in Phil, there are more
 people on the other list who are familiar with PyQt and who may be willing
 to look more closely at your specific code.
 
 2.) It may be that the examples you are looking at are not sufficient to
 help you with the situation you are in. For instance, I've written several
 programs using Designer and PyQt and I would recommend against
 using the pyuic method.
 
 When I first started with PyQt I also used pyuic and eventually I found
 the PyQt4.uic method works better for me.
 
 3.) Layouts. You have to use them with Qt or you're going to have a
 bad time.
 
 Looking at your design, I would do something like ...
 
 - select the two buttons on the left and click Lay Out Vertically
 - select the two large white boxes and click Lay Out Vertically
 - put a vertical spacer underneath the red X button
 - select the red button and the spacer and click Lay Out Vertically
 - at this point you may need to resize and rearrange your three vertical
    layouts so that they don't overlap and are in approximately the positions
    that you want, then
 - select the main window and click Lay Out Horizontally
 
 Something along those lines would get you about to where you want
 to be. The form may not look _exactly_ the way you have it there, but
 it will be a more flexible design and nothing will be overlapping.

-- 
http://mail.python.org/mailman/listinfo/python-list


connecting clicked signal to different slots depending on function executing

2013-09-01 Thread tausciam
I have one tablewidget I want to use for two different uses, audio and video. 
If cover art is displayed and the user clicks the cover art, it emits a cell 
clicked and gets the list of the songs. If video thumbnails are displayed, it 
emits a cell clicked and plays the video fullscreen.

So, I have the same signal going to two different slots. Is there any way to 
break that connection before I define it again? In other words, in the audio 
section I could have something like:

[break video signal/slot connection]
self.tableWidget.cellClicked.connect(self.audiocell_clicked)

and then for the video section:

[break audio signal/slot connection]
self.tableWidget.cellClicked.connect(self.videocell_clicked)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: connecting clicked signal to different slots depending on function executing

2013-09-01 Thread tausciam
Nevermind. I found that it would let me create the connection again then 
when I disconnected, it would disconnect all of the instances...

so I ended up with: 

self.tableWidget.cellClicked.connect(self.videocell_clicked)   
self.tableWidget.cellClicked.disconnect(self.videocell_clicked)   
self.tableWidget.cellClicked.connect(self.audiocell_clicked)

If there's a better way to do this, I'd be interested in hearing about it. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: connecting clicked signal to different slots depending on function executing

2013-09-01 Thread tausciam
I should add that I know about:

self.tableWidget.cellClicked.disconnect(self.videocell_clicked)  

but, when I do that, if the connection is not there, then the program crashes. 
So, how could I check to see if the connection is there then break it?
-- 
http://mail.python.org/mailman/listinfo/python-list