Drag and Drop with PyQt4

2006-08-25 Thread Harshad
Hi,

I'm writing a program using Python 2.4 and PyQt4. The aim is to
implement drag and drop from filesystem and display a list of files
dragged on to the listWidget. This function will later become part of a
software for workflow management.

When I run the program, DragEnterEvent works as expected, but the
DropEvent does not seem to be working. I'm not an experienced Python
hacker, and am unable to trace out any problems with the source code.
Any and all help will be appreciated!

Cheers!
Harshad.

P.S.: The source code for the two files is given below:

--- zaraa.py
---

from PyQt4 import QtCore, QtGui
from zaraamain import Ui_Dialog
import sys
from PyQt4 import *

class Zaraa(QtGui.QDialog, Ui_Dialog):
def __init__(self):
QtGui.QDialog.__init__(self)

# Set up the user interface from Designer.
self.setupUi(self)

# Enable Drag and Drop
self.listWidget.setAcceptDrops(True)

# Set up the handlers for the listWidget
self.listWidget.__class__.dragEnterEvent =
self.lwDragEnterEvent
self.listWidget.__class__.dropEvent = self.lwDropEvent

# Drag Enter Event handler
def lwDragEnterEvent(self, event):
print "DragEnter"
event.acceptProposedAction()

#  BEGIN 
# The following event is not fired, or at least is not
# handled by this function - as is expected...

# Drag Drop Event Handler
def lwDropEvent(self, event):
print "DragDrop"

event.acceptProposedAction()

# we want to append only URLs to the list...
if event.mimeData().hasUrls() == True:
urllist = event.mimeData().urls()
for url in urllist:
self.listWidget.addItem(url.toLocalFile())
#  END 

# Set up the application and execute it.
app = QtGui.QApplication(sys.argv)

window = Zaraa()
window.show()

sys.exit(app.exec_())

--- /zaraa.py
---

--- zaraamain.py
---
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'zaraamain.ui'
#
# Created: Sat Aug 26 00:00:10 2006
#  by: PyQt4 UI code generator 4.0.1
#
# WARNING! All changes made in this file will be lost!

import sys
from PyQt4 import QtCore, QtGui

class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")

Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,249,300).size()).expandedTo(Dialog.minimumSizeHint()))

self.vboxlayout = QtGui.QVBoxLayout(Dialog)
self.vboxlayout.setMargin(9)
self.vboxlayout.setSpacing(6)
self.vboxlayout.setObjectName("vboxlayout")

self.listWidget = QtGui.QListWidget(Dialog)
self.listWidget.setObjectName("listWidget")
self.vboxlayout.addWidget(self.listWidget)

self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog",
"Zaraa", None, QtGui.QApplication.UnicodeUTF8))

--- /zaraamain.py
---

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


Re: Drag and Drop with PyQt4

2006-08-26 Thread Harshad

David Boddie wrote:
>
> I tested this code with Python 2.4.2, Qt 4.1.4 and PyQt 4.1, and I
> think you should be able to do the same in your code.
>

First of all, thanks a lot for the very precise and quick help! Ot
works now.

>  1. If you are prepared to try Qt's model/view classes, you can exert
> more control over the way drag and drop is handled. They're not
> quite as straightforward as the item-based classes that you're
> already using, but you benefit from greater reusability of your
> components and better control over the appearance and behaviour
> of the view widgets.

I will certainly give it more thought and probably reimplement this
program with model/view classes. Thanks for the heads-up.

>  2. You seem to prefer adding methods to specific instances rather than
> subclassing and reimplementing methods in the base class. I hope
> you don't mind me asking, but is that because it takes less code,
> because you find it conceptually easier, or is there another reason
> that I'm missing?
>

I am pretty new to Python and more so with PyQt4 and am still to learn
a lot of things. I realized the issue with adding methods to specific
instances a bit after I emailed to the group. I am going to subclass
the widget classes in the program.

Again, thanks a lot.

Cheers!

Harshad.

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


encoding latin1 to utf-8

2007-09-10 Thread Harshad Modi
hello ,
 I make one function for encoding latin1 to utf-8. but i think it is
not work proper.
plz guide me.

it is not get proper result . such that i got "Belgi�" using this
method, (Belgium)  :

import codecs
import sys
# Encoding / decoding functions
def encode(filename):
 file = codecs.open(filename, encoding="latin-1")
 data = file.read()
 file = codecs.open(filename,"wb", encoding="utf-8")
 file.write(data)

file_name=sys.argv[1]
encode(file_name)

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


Re: encoding latin1 to utf-8

2007-09-10 Thread Harshad Modi
thx for Reply ,
but I need some basic knowledge . how to encoding ? which algorithm
use for that . bz my data has some special char , i have not
confidence   this function got proper result. i want to make my own
function  / script for encoding.

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


Re: encoding latin1 to utf-8

2007-09-12 Thread Harshad Modi
thx for response ,
i think, my file has wrong encoding format.
thanks for guide and advise

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