[PyQt] Sourcing libs across network?

2011-08-24 Thread Christopher Evans
Anyone sourcing the pyqt libs from across a network (windows)?

We have some weird errors, mainly when loading a UIC via the UIC module.

# Error: type 'exceptions.SyntaxError': invalid syntax (string, line 31)
# Traceback (most recent call last):
# File maya console, line 1, in module
# File 
\\fs1\TECHART\Tools\CryMayaTools\CryAnimation\retarget\retarget_tool.py,
line 62, in module
# form_class, base_class = uic.loadUiType(uiFile)
# File \\fs1\TECHART\Tools\libs\PyQt4\uic\__init__.py, line 200, in loadUiType
# winfo = compiler.UICompiler().compileUi(uifile, code_string, from_imports)
# File \\fs1\TECHART\Tools\libs\PyQt4\uic\Compiler\compiler.py, line
55, in __init__
# CompilerCreatorPolicy())
# File \\fs1\TECHART\Tools\libs\PyQt4\uic\uiparser.py, line 127, in __init__
# self.factory = QObjectCreator(creatorPolicy)
# File \\fs1\TECHART\Tools\libs\PyQt4\uic\objcreator.py, line 91, in __init__
# if load_plugin(open(filename), plugin_globals, plugin_locals):
# File \\fs1\TECHART\Tools\libs\PyQt4\uic\port_v2\load_plugin.py,
line 47, in load_plugin
# raise WidgetPluginError(%s: %s % (e.__class__, str(e)))
# WidgetPluginError: type 'exceptions.SyntaxError': invalid syntax
(string, line 31) #

--
CE
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] pyqt behavior change

2011-08-24 Thread Ingrid Dahl-Olsen

Hi,

Sorry for commenting on a post this old, but I've only just run into 
this change as I'm using PyQt in maya at work, and so have been stuck 
with using 4.7.2 until very recently when it was bumped up to 4.8.4.


Just out of curiosity, is it really wrong to expect an instance of a 
widget like QComboBox to evaluate to True? I can understand the 
implementation of the __len__ method as a neater, more pythonic way to 
test for number of items in the widget (although personally, I think 
just using count() is a bit clearer). But does that really mean it makes 
sense to evaluate to False if there are no items in the combo box? It's 
still a widget with attributes etc, which potentially takes up screen 
space. I would have thought the __nonzero__ method should also have been 
implemented, so 'if combo' would still evaluate to True, but len( combo 
) would return 0?


I expect this behaviour will stay as it is, as it's been that way for a 
year now, but just thought I'd ask...


Cheers,
Ingrid
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] subtle bug in PyQt in combination with Python garbage collector

2011-08-24 Thread Adrian Buehlmann
On 2011-08-13 18:05, Kovid Goyal wrote:
 This bug has been present for a very long time. As a workaround in my 
 projects, 
 I disable the automatic garbage collector and run garbage collection manually
 in the GUI thread via QTimer. Here's the code to do that:
 
 class GarbageCollector(QObject):

I just wanted to say thank you for sharing this info.

I've applied your workaround on TortoiseHg [1]

   https://bitbucket.org/tortoisehg/thg/changeset/d5a9ae16b56b

which will be included in the next stable release 2.1.3 (due on Sep 1st).

[1] http://tortoisehg.bitbucket.org/
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Adding a table to GUI in QT Designer

2011-08-24 Thread Nader Abedrabbo

Thanks Tony. 

I was able to add a context menu to the table with the functionality I need
and now can CutPaste from excel to my code with no problems.  

One issue I still have is that I have 4 tabs in my program and each tab has
its own table.  In order to cut and paste to the correct table (with its
associated name) I am having to re-write the code for each table
individually, which I know is redundant and bad programming, but I don't
know a way around it. 

To solve this problem, is there a way for the program to: 
1. Track the location of the mouse in the program and when it is located
ONLY over a table to activate the QMenu context menu; 
2. When it is located over a certain table to report the name of that table
back? 


That way I could simplify my code. 

Thanks, 
Nader Abedrabbo




yes it's possible to do that... read about QMenu classes to do the right
click and
maybe visit here to other examples

http://www.rkblog.rk.edu.pl/w/p/python/#3

2011/8/22 Nader Abedrabbo aenad...@yahoo.com


-- 
View this message in context: 
http://old.nabble.com/Adding-a-table-to-GUI-in-QT-Designer-tp32313584p32326763.html
Sent from the PyQt mailing list archive at Nabble.com.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] pyqt behavior change

2011-08-24 Thread Phil Thompson
On Wed, 24 Aug 2011 12:51:52 +0100, Ingrid Dahl-Olsen i...@dneg.com wrote:
 Hi,
 
 Sorry for commenting on a post this old, but I've only just run into 
 this change as I'm using PyQt in maya at work, and so have been stuck 
 with using 4.7.2 until very recently when it was bumped up to 4.8.4.
 
 Just out of curiosity, is it really wrong to expect an instance of a 
 widget like QComboBox to evaluate to True? I can understand the 
 implementation of the __len__ method as a neater, more pythonic way to 
 test for number of items in the widget (although personally, I think 
 just using count() is a bit clearer). But does that really mean it makes

 sense to evaluate to False if there are no items in the combo box? It's 
 still a widget with attributes etc, which potentially takes up screen 
 space. I would have thought the __nonzero__ method should also have been

 implemented, so 'if combo' would still evaluate to True, but len( combo 
 ) would return 0?
 
 I expect this behaviour will stay as it is, as it's been that way for a 
 year now, but just thought I'd ask...

If you want to test whether an object is None then you should always do so
explicitly, ie. use...

if combo is not None:

...and not...

if combo:

You might argue that this is just a question of programming style, but (to
me) not testing explicitly is a bug in your code. In other words the change
only affected buggy programs and so was acceptable.

Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] how aim same function to other tables

2011-08-24 Thread Tony Peña
hi I want to use same function to other tables like this

tablename = Searchtable  but could be table1 table2 table3 ... table n

addAction.triggered.connect(self.addFriend) - This works ok def addFriend(
self, event): tablename = 'SearchtableWidget' table_obj = getattr(self.ui,
tablename)  current_row = table_obj.currentRow() current_vid = table_obj.
item(current_row, 0) current_realname = table_obj.item(current_row, 2)
total_vid = len(vid) insert = True if total_vid = 0: for i in range(0,
total_vid): if int(str(current_vid.text())) == vid[i][0]: . rest code
run fine 
--- if i
pass this to prepare the connect when right-click button is active...
addAction.triggered.connect(self.addFriend(self, 'SearchtableWidget')) --
need fix this because is running function before connected :| def addFriend(
self, event, tablename): table_obj = getattr(self.ui, tablename) -this
receive Searchtable same like before BUT... current_row = table_obj.
currentRow() current_vid = table_obj.item(current_row, 0) current_realname =
table_obj.item(current_row, 2) total_vid = len(vid) insert = True if
total_vid = 0: for i in range(0, total_vid): if int(str(current_vid.text
())) == vid[i][0]: current_vid.text() - current.text() method NOT WORK...
because when came tablename as argument is NoneType
...stop here...

I guess to need some help with how can connect to a function with ARG as
options...

any idea?


-- 
Antonio Peña
Secure email with PGP 0x8B021001 available at http://pgp.mit.edu
 Fingerprint: 74E6 2974 B090 366D CE71  7BB2 6476 FA09 8B02 1001
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] QItemDelegate createEditor - help with focusOut on custom widget

2011-08-24 Thread James Holstead
Below is a working example. You'll see the PathWidget looses focus
when a combo box is selected. How can I delegate focus back to the
patchwidget when the user clicks outside of the entire TableView?



from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
import datetime


class testView(QTableView):

def __init__(self,parent,data):
QTableView.__init__(self,parent)
self.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.MinimumExpanding)

model = testModel(data)
self.setModel(model)
self.setItemDelegate(testDelegate(self))
self.setFixedWidth(600)
self.setColumnWidth(2,300)
self.show()

def focusOutEvent(self, evt):
print repr(self) + ' lost focus';

class testModel(QAbstractTableModel):

def __init__(self,data):
QAbstractTableModel.__init__(self)
self.data = data

def focusOutEvent(self, evt):
print repr(self) + ' lost focus';

def flags(self,index):
return Qt.ItemFlags(QAbstractTableModel.flags(self,index)
|Qt.ItemIsEditable)

def rowCount(self, index=QModelIndex()):
return 1

def columnCount(self,index=QModelIndex()):
return len(self.data)

def data(self,index,role=Qt.DisplayRole):
if role == Qt.DisplayRole:
return self.data[index.column()]

def setData(self, index, value, role=Qt.EditRole):
self.data[index.column()] = value.toString()
return True

class testDelegate(QItemDelegate):

def createEditor(self,parent,option,index):
if index.column() != 2:
editor = QLineEdit(parent)
return editor
else:
editor = PathEditor(parent)
return editor

def setModelData(self, editor, model, index):
if index.column() != 2:
model.setData(index,QVariant(editor.text()))
else:
model.setData(index,QVariant(editor.data()))

class PathEditor(QWidget):
def __init__(self, parent=None):
print type(parent)
super(PathEditor, self).__init__(parent)
self.setFocusPolicy(Qt.StrongFocus)
self.setAutoFillBackground(True)
self._lm = QGridLayout()
self._lm.setMargin(0)
self._initGui()

def focusOutEvent(self, evt):
print repr(self) + ' lost focus';

def _initGui(self):
for x in range(3):
combo_box = QComboBox()
combo_box.addItem('Option 1','One')
combo_box.addItem('Option 2','Two')
combo_box.addItem('Option 3','Three')
combo_box.setCurrentIndex(-1)
self._lm.addWidget(combo_box, 0,x)

self.setLayout(self._lm)

def data(self):
values = []
for child in self.children():
if isinstance(child, QComboBox):
if child.currentIndex() != -1:

values.append(str((child.itemData(child.currentIndex())).toString()))
res = ,.join(values)
return res

if __name__ == '__main__':

app = QApplication(sys.argv)
data = ['One','Two','Three']
v = testView(None,data = data)
app.exec_()
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] how aim same function to other tables

2011-08-24 Thread Josh Stratton
Can you pull the table name out of the event object?  Another option
is to make a unique function for each table, which calls the addFriend
function itself with the table name.  That way you won't have to
duplicate addFriend code.

example:

addFriend(event, table):


def table1AddFriend(event): # connect to this
 addFriend(event, table1)

etc.

These wrapper functions, I believe, can be anonymous so you can make
them dynamically.

On Wed, Aug 24, 2011 at 10:18 AM, Tony Peña emperor...@gmail.com wrote:

 hi I want to use same function to other tables like this
 tablename = Searchtable  but could be table1 table2 table3 ... table n
 addAction.triggered.connect(self.addFriend) - This works ok def
 addFriend(self, event): tablename = 'SearchtableWidget' table_obj =
 getattr(self.ui, tablename) current_row = table_obj.currentRow() current_vid
 = table_obj.item(current_row, 0) current_realname =
 table_obj.item(current_row, 2) total_vid = len(vid) insert = True if
 total_vid = 0: for i in range(0, total_vid): if
 int(str(current_vid.text())) == vid[i][0]: . rest code run fine 
 --- if i
 pass this to prepare the connect when right-click button is active...
 addAction.triggered.connect(self.addFriend(self, 'SearchtableWidget')) --
 need fix this because is running function before connected :| def
 addFriend(self, event, tablename): table_obj = getattr(self.ui, tablename)
 -this receive Searchtable same like before BUT... current_row =
 table_obj.currentRow() current_vid = table_obj.item(current_row, 0)
 current_realname = table_obj.item(current_row, 2) total_vid = len(vid)
 insert = True if total_vid = 0: for i in range(0, total_vid): if
 int(str(current_vid.text())) == vid[i][0]: current_vid.text() -
 current.text() method NOT WORK... because when came tablename as argument is
 NoneType
                                             ...stop here...
 I guess to need some help with how can connect to a function with ARG as
 options...
 any idea?

 --
 Antonio Peña
 Secure email with PGP 0x8B021001 available at http://pgp.mit.edu
 Fingerprint: 74E6 2974 B090 366D CE71  7BB2 6476 FA09 8B02 1001

 ___
 PyQt mailing list    PyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] send a QVariant in a QUdpSocket Datagram?

2011-08-24 Thread emmanuel_mayssat

Hello,

I have been able to send a QVariant in over the network using a QTcpSocket and 
QDataStream.
now I would like to send the same QVariant over a QUdpSocket.

The issue is that the type of a datagram is string or QByteArray (Not 
QDataStream)
So I send my datagram as a QByteArray

def issuePyObject(self, pyobject):
''' Note that an Item needs to of class object and not class QObject 
!!! '''


self.request = QByteArray()
stream = QDataStream(self.request, QIODevice.WriteOnly)
stream.setVersion(QDataStream.Qt_4_2)
stream.writeUInt16(0)
qVariant = QVariant(pyobject)
if self.debug:
print pyobject
print qVariant.toPyObject()# -- Works because it knows the 
qVariant type (class!!)
# Indeed it uses the correct __str__ rountine!!!
stream.writeQVariant(qVariant)
stream.device().seek(0)
nextBlockSize = self.request.size() - SIZEOF_UINT16
if self.debug: print nextBlockSize = %d  % nextBlockSize
stream.writeUInt16(nextBlockSize)


if self.protocol == 'udp' :
self.udpSocket = QUdpSocket()
datagram = self.request
self.udpSocket.bytesWritten.connect(self.on_udpSocket_bytesWritten)
self.udpSocket.writeDatagram(datagram, 
QHostAddress(QHostAddress.Broadcast),
self.portNumber)
elif self.protocol == 'tcp':
self.tcpSocket = QTcpSocket()
self.connect(self.tcpSocket, SIGNAL(connected()), 
self.on_tcpSocket_connected)
self.connect(self.tcpSocket, SIGNAL(disconnected()), 
self.on_tcpSocket_disconnected)
self.connect(self.tcpSocket, SIGNAL(readyRead()), 
self.on_tcpSocket_readyRead)
self.connect(self.tcpSocket, 
SIGNAL(error(QAbstractSocket::SocketError)),
self.on_tcpSocket_error)
self.connect(self.tcpSocket, SIGNAL(hostFound()), 
self.on_tcpSocket_hostFound)
if self.tcpSocket.isOpen():
self.tcpSocket.close()
self.tcpSocket.connectToHost(self.serverName, self.portNumber)
else:
pass

Now on the server side i have to convert the datagram into a QVariant and then 
the PyObject
This operation doesn't work at all !!!
As a matter of fact even reading nextBlockSize is incorrect!

@LInAndOut(DEBUG  THREADS)
def run(self):
if self.debug: print UDP Server on %d % self.portNumber
udpSocket = QUdpSocket()
udpSocket.bind(self.portNumber)
udpSocket.readyRead.connect(self.on_udpSocket_readyRead)
while(udpSocket.state()==QAbstractSocket.BoundState):
udpSocket.waitForReadyRead(-1)
while udpSocket.hasPendingDatagrams():
datagram, host, port = 
udpSocket.readDatagram(udpSocket.pendingDatagramSize())
if self.debug: print Received datagram: \%s\ % datagram
self.extractNotificationFromDatagram(datagram)


@LInAndOut(DEBUG  THREADS)
def extractNotificationFromDatagram(self,datagram):
notification = LNotificationItem()
stream = QDataStream(QByteArray(datagram),QIODevice.ReadOnly)
stream.setVersion(QDataStream.Qt_4_2)
nextBlockSize = stream.readUInt16()
qVariant = stream.readQVariant()
notification =  qVariant.toPyObject()

if self.debug :
print qVariant
#print qVariant.toPyObject() # doesn't work  Check SIP !!!
print notification: %s %  notification # -- WORKS !
print nextBlockSize: %d %  nextBlockSize # -- WORKS !

try:
LThread.lock.lockForWrite()
try:
self.parent().dataContainer.notifications.append(notification)
self.parent().dataContainer.timeLastWritten = time.time()
except AttributeError, e:
print notification
finally:
LThread.lock.unlock()

Please help!

-- 
Emmanuel
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] removeWidget

2011-08-24 Thread uahmed
Hi

I want to add widget in (f1) function and want to remove the widget from
(f2) function . I tried the same thing in same function it do work but when
i try to remove the widget from another it doesnt . Any help ?

Code :


import sys,os
from functools import partial
from PyQt4 import QtGui, QtCore
import Skype4Py
import time
import socket


class main():
def f1(self):
print f1
buttons['user'] = QtGui.QToolButton(widget)
layout.addWidget(buttons['user'])
widget.setLayout(layout)
def f2(self):
print f2
layout.removeWidget(buttons['user'])
widget.setLayout(layout)


app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
layout = QtGui.QVBoxLayout()
buttons = {}
sk = main()
sk.f1()
sk.f2()
widget.show()
sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt