Sunday, 15 August 2010

python - Split byte array -



python - Split byte array -

i working on little personal project allows user drag list item qlistwidget in pyqt4 onto label opens message dialogue. see selected comes produces both title , link in both instances. how can access individual elements? aiming accomplish first element (title) in dialog header 2nd parameter of about() method , show sec part of bytearray (link) in main dialog box.

def dropevent(self, event): info = event.mimedata() bstream = data.retrievedata("application/x-feed", qtcore.qvariant.bytearray) selected = pickle.loads(bstream.tobytearray()) event.accept() qtgui.qmessagebox.about(self, str(selected), """ %s """ % str(selected) )

edit

class base(object): def __init__(self, name, link): self.name = name self.link = link def __repr__(self): homecoming "%s\n%s" % (self.name, self.link)

error: typeerror 'base' not back upwards indexing

background reading far: http://srinikom.github.io/pyside-docs/pyside/qtcore/qmimedata.html https://docs.python.org/3.1/library/functions.html

any help appreciated!

if pickle.loads returns tuple, may utilize syntax:

(title,link) = pickle.loads(bstream.tobytearray())

or

selected = pickle.loads(bstream.tobytearray()) title = selected[0] link = selected[1]

edit

i thought pickle.loads returned tuple returns base object 2 attributes need access attributes (remember there not private attributes in python):

selected = pickle.loads(bstream.tobytearray()) title = selected.name link = selected.link

python python-2.7 qt4 pyqt4

No comments:

Post a Comment