Python MySQL: clean multiple foreign keys table

2009-11-28 Thread Threader Slash
Hi Everybody,

I am working with Python MySQL, and need to clean a table in my database
that has 13328 rows.

I can not make a simple drop table, because this table is child and also
father of other child foreign-keys linked on it. If I try drop table, the
system forbidden me. The table is defined with ON UPDATE CASCADE, ON DELETE
CASCADE and InnoDB; The primary_key index to that table is defined as

productID INT(6) NOT NULL AUTO_INCREMENT ...
PRIMARY KEY (productID,productNO)

Therefore, I just have to clean; this will automatically restore the table
primary key index to 1 for the next input. Right?

This procedure worked fine for another table that was a father table, but
not also a father and child table. But, for this table, which is child and
father of other tables, I got stuck on it.

Here is the code - productID is my primary index key to this table:


def clean_tableProduct(self):
getMaxID_MySQLQuery = """SELECT MAX(productID)
FROM product;"""

cleanTabeMySQLQuery="""DELETE FROM product WHERE productID
<=%s;"""

self.cursorMySQL.execute(getMaxID_MySQLQuery)

for row in self.cursorMySQL:
self.cursorMySQL.execute(cleanTabeMySQLQuery,(row[0],))

If I go to the MySQL console to check the processing results, it gets me:

mysql> SELECT MIN(productID)
FROM product;
4615748

mysql> SELECT MAX(productID)
FROM product;
4629075

If I run the same command on console to clean the table, it works:

mysql> DELETE FROM product WHERE productID <='4629075';
Query OK, 13328 rows affected (0.64 sec)


and shows me what I would normally expect.

However, if I go to Python function after having cleaned the table on
console, and run the program again, and clean the table to restart the
processing, it restarts the table index not with MIN:1, but instead 4629076.

Any suggestion?

All comments and suggestions are highly appreciated and welcome.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for python similar to visual basic

2009-09-25 Thread Threader Slash
On Sat, Sep 26, 2009 at 12:58 AM, Dave Angel  wrote:

> Threader Slash wrote:
>
>> -- Forwarded message --
>>> From: J Sisson 
>>> To: Nobody 
>>> Date: Thu, 24 Sep 2009 19:18:03 -0500
>>> Subject: Re: IDE for python similar to visual basic
>>>
>>>
>>> On Sun, Sep 13, 2009 at 6:25 AM, Nobody  wrote:
>>>
>>>
>>>
>>>> On Fri, 11 Sep 2009 05:27:59 -0700, r wrote:
>>>>
>>>>
>>>>
>>>
>>>
>>>>  > Sounds like "somebody" failed to get input
>>>>
>>>>
>>>>> from their users at design time. Or "somebody" has the inability to
>>>>> relate to their end users.
>>>>>
>>>>>
>>>> You're assuming that there is some "right" answer which is appropriate
>>>> for
>>>> all users. There isn't.
>>>>
>>>>
>>>>
>>> I worked for a company that had a team composed of graphic artists, QA
>>> types, etc...that did nothing but draw up GUI's, show them to customers,
>>> revise them, write up runnable "dummies" of the approved GUI's, performed
>>> usability studies with our customers using the dummy GUI's, and finally
>>> handed the GUI's over to dev so they could put in the guts to make it "do
>>> stuff".
>>>
>>> "Bugs" or "Cases" involving the GUI needing revision because a button
>>> needed to be moved for usability were *extremely* rare, and the GUI
>>> didn't
>>> require an additional toolset that allowed end users to tweak them.
>>>
>>>
>>>
>>>
>>  My favorite IDE : Eclipse
>>
>> http://pydev.org/download.html
>>
>>
>> http://www.ibm.com/developerworks/opensource/library/os-eclipse-visualstudio
>>
>> http://www.eclipse.org
>>
>> Of course you have also the Mono:
>> http://monodevelop.com
>>
>> Cheers.|:0),
>>
>>
>>
> But where's the GUI designer for Eclipse/Python?  That's what the OP was
> asking about.
>
> GUI builders I've heard of, but not evaluated include:
>
>  Boa
>  wxGlade
>  wxFormBuilder
>  Wing IDE
>
> DaveA
>
>
Hi Dave,

Sorry, I just read and answer your post quickly... so, here again about the
IDE development for Python

http://pydev.org/download.html
http://pydev.org/screenshots.html

Also, please read and follow instructions:
http://pydev.org/manual_101_root.html
http://pydev.org/manual_101_project_conf2.html

About IDE you can install the Qt 2.5 or 2.6 SDK, it comes with the Qt
Designer. You just generates the design you want, then you save it as
myGUI.ui.

The only point is, if you are working on Windows with Python Qt, when you
have to run on console the command pyuic4 that will generate your
ui_myGUI.py source file to link it to your system, it doesn't work.

After reading and googling around, I find out that aparently there is a bug
on it for the free edtion of Qt for Windows. Hope that it can be fixed soon.
This means, that the GUI has to done code by yourself using Qt programming.

The Qt Design should just work fine for Linux, because I didn't hear about
any similar problem.

For Qt C++ on Windows it is apparently working -- but I didn't try yet:
http://labs.trolltech.com/blogs/2007/07/11/develop-qt-applications-in-eclipse

I hope this help. cheers.
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQL Matrix manipulation in Python

2009-09-29 Thread Threader Slash
Hello Everybody,

My doubt is about matrix data manipulation in python - I hope someone can
point me some direction.

I googled around, but there is not much good examples about playing with
matrix in python on internet.

My following function works pretty well, and gives me the outup from my
MySQL db:

* Code:
def employee(self, verifyName):
runQuery= """ = %s"""
self.cursor.execute(runQuery,(verifyName,))
for row in self.cursor.fetchall():
print row
print "Number of lines returned: %d" % self.cursor.rowcount
print "tell column numbers: %d" % len(row)

* output

('John', 'Plumber')
('Bill', 'Driver')
('Mark', 'Lawyer')
Number of lines returned: 3
tell column numbers: 2

Now, how can I transfer this output to provide a matrix with a content like
this:

my_array = [['John','Plumber'],
['Bill','Driver'],
['Mark','Lawyer']]

All comments and suggestions are highly appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


win32com.client import problem

2009-10-14 Thread Threader Slash
Hi Everybody,

I have 2 imports:

import pythoncom
from win32com.client import Dispatch

if I run it on my Python 2.6 Console, it works nicely. However, when I go to
Eclipse IDE, open a project, open a main.py file, and try run, it gives the
error:

import pythoncom
ImportError: No module named pythoncom

All other imports are working ok on Eclipse IDE -- e.g. import MySQLdb.

Any suggestion about what is missing?

All comments and suggestion are welcome.

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


win32com.client import problem : solved

2009-10-14 Thread Threader Slash
-- Forwarded message --
From: Dave Angel 
To: Threader Slash 
Date: Wed, 14 Oct 2009 07:04:21 -0400
Subject: Re: win32com.client import problem
Threader Slash wrote:

> Hi Everybody,
>
> I have 2 imports:
>
> import pythoncom
> from win32com.client import Dispatch
>
> if I run it on my Python 2.6 Console, it works nicely. However, when I go
> to
> Eclipse IDE, open a project, open a main.py file, and try run, it gives the
> error:
>
> import pythoncom
> ImportError: No module named pythoncom
>
> All other imports are working ok on Eclipse IDE -- e.g. import MySQLdb.
>
> Any suggestion about what is missing?
>
> All comments and suggestion are welcome.
>
> ThreaderSlash
>
>
>
Two things to check, python version (sys.version), and sys.path.   Add
prints for the two of them at the beginning of your script, and try the
script in both environments.  If there are any differences, figure out how
to reconfigure Eclipse to match what you've got at the console.


DaveA


--  --  --  --

-- hope this can help and save time for others too

Here is what did and works:
* copy the file mfc71.dll on windows\system32
* copy the same also on directories
* copy the same to your directories Python26\DLLs and
Python26\lib\site-packages\win32
* go to preferences : pydev : interpreter python : remove all the
interpreter you have there. apply, ok.
then add python 2.6 again, apply, ok.

It will do the trick...|:0), ThreaderSlash

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


win32com lotus notes: not opened

2009-10-20 Thread Threader Slash
Hi Everybody,

Hope someone can point me some direction...

I got python linking to lotus notes, under Eclipse IDE. The code is:

import pythoncom
import pywintypes
from win32com.client import Dispatch
session=Dispatch("Lotus.NotesSession")
session

print pythoncom.CreateGuid()

try:
session.Initialize("password")
db = session.getDatabase("local", "C:\Program
Files\lotus\notes\data\mydata.nsf")

agent=db.getAgent("($All)")
doc = db.CreateDocument()
view = db.GetView("($All)")
doc = view.getFirstDocument()

testvar = doc.getItemValue("($All)")

except pywintypes.com_error: raise

but the compiler gives me the error:

".nsf has not been opened yet"

Any suggestion? Thanks. ThreaderSlash
-- 
http://mail.python.org/mailman/listinfo/python-list


mysql select some sort of caching

2009-10-20 Thread Threader Slash
-- Forwarded message --
From: David Sfiligoi 
To: [email protected]
Date: Tue, 20 Oct 2009 21:41:10 -0500
Subject: mysql select some sort of caching
Hi
I am normally an SQLlite person because it just works... but I decided to
keep inproving my skills set and do my new project using a MySQL database
backend because of the architecture decision I made(horizontal scalable
system via message queues). The project is architected around a rabbitmq
system with bunch of consumers(potentially large) and publishers... I
digress, the rabbit has a no part to play in my myunderstanding with
mysql.

I have a consumer that get data from a queue(a url). This queue is
checked in a loop. Once a url has been published in the queue, the
consumer sees it and call a function to do something with it.  Using a
column in the table I verify if 'today's task' has been done already
(compare the current date to the last task date that I store in the table
last time I executed the task)

So normally I would open a connection and instentiate a cursor for my
queries once at a global level(like find out if the current date is >
than the last task date). Then go in an infinite loop that wait for data
to arrive in the queue and carry the cursor and connection over.  However
this is the issue I seem to run into.  I test the code by zapping, using
mysql query tools, the table's last task date column with an older date
so that current date is larger than the current date.  Issue is that
whatever prior date I put in the table's last task date colum somehow
they are not seen by the SELECT query
sqlcur.execute("SELECT `url`d` from `url_snapshot` WHERE `url` = %s and
`lastsnapshotdate` < %s",(url,currentdate))
that query returns old data.

Just like if the query is cachedyet the data actually changed in the
database.

However when I recreate a new connection and cursor everytime I get a new
message in the queue(url), therefore within the message found loop there
are no issues seeing the last update done via the mysql query tool

I don't think this has to do with mysql caching features since its
suppose to detect when the fields changed.

Any ideas?

Thanks for your Time,
David

-- Forwarded message --

A simple suggestion.. in your next post - go direct to your problem.

Just to be sure, did you got a "commit"!?
-- 
http://mail.python.org/mailman/listinfo/python-list


python pyodbc - connect error

2009-10-22 Thread Threader Slash
Hello Everybody... here we go - my question:

1. I am using Eclipse IDE with Python 2.5 and pyodbc25 - winXP; need to read
content from a
Lotus Notes database, so run some basic query like - SELECT personname FROM
tablename.
2. 'import pyodbc' is ok - python see it!
3. But it doesn't connect, when I try to run
conn = pyodbc.connect("DRIVER={Lotus NotesSQL Driver};SERVER=local;UID=John
Meyer;PWD=yellowbird;DATABASE=mydb.nsf")

It gives me the error:
pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data
source name not found and no default driver specified (0)
(SQLDriverConnectW)')

Please, any hint or suggestion? Thanks in advance. ThreaderSlash
-- 
http://mail.python.org/mailman/listinfo/python-list


python pyodbc - connect error

2009-10-22 Thread Threader Slash
Hi again.. I have done the same test using pyodbc, but to MySQL ODBC driver.
It works fine for MySQL. The problem still remains to Lotus Notes. Any other
hints please?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem in installing wxwidgets for python.

2009-11-04 Thread Threader Slash
This additional links should come in hand:

http://www.gossamer-threads.com/lists/python/python/785413?page=last
http://www.daniweb.com/forums/thread235862.html#
http://forum.amule.org/index.php?topic=11728.0
http://www.linuxquestions.org/questions/linux-software-2/problem-in-installing-wxwidgets...-76/

I hope it can help. Good luck and have fun!

ThreaderSladh


-- Forwarded message --
From: Ishwor Gurung 
To: [email protected]
Date: Wed, 4 Nov 2009 23:11:39 +1100
Subject: Re: problem in installing wxwidgets for python..
Hi,

2009/11/4 Jebagnana Das :
> Hello friends,
>   I've tried to install wxwidgets in my mandriva 2009
spring
> for GUI interaction with python. In the installation instruction it said
> that i need gtk+ library. So i downloaded GTK+. When i configured GTK+ i
got
> the message

You probably want wxpython binding instead - http://www.wxpython.org/
Use binaries provided by Mandriva's package manager where possible
unless you _really_ want to do a source installation.

> checking for BASE_DEPENDENCIES... configure: error: Package requirements
> (glib-2.0 >= 2.21.3atk >= 1.13.0pango >= 1.20cairo >= 1.6)
were
> not met:
>
>
> Requested 'glib-2.0 >= 2.21.3' but version of GLib is 2.20.1
>
> Consider adjusting the PKG_CONFIG_PATH environment variable if you
> installed software in a non-standard prefix.

$ export PKG_CONFIG_PATH=/usr/lib/
pkgconfig:/usr/local/lib/pkgconfig
(considering that your local installs went to those directories. Try
replacing those directories accordingly for glib, atk, pango and
cairo). The files you're after is a ".pc" (pkg-config need them) file.
A quick find will tell you where it is if it is installed.

Run configure script again.

> Alternatively, you may set the environment variables
> BASE_DEPENDENCIES_CFLAGS
>
> and BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config.
> See the pkg-config man page for more details.
>
> Then i downloaded glib2.21.3,atk 1.13.0,pango 1.20 and cairo 1.6. I
> installed all the packages using the following commands.

[...]
> tar xvzf filename.tar.gz
> cd folder
> ./configure
>
> make
> make install

Yep. Check where it installed them one by one. In short, you need
access to a ".pc" file that they provide. If not, write one yourself.

> I've not specified anf options like --prefix and i installed in the folder
> itself.

man pkg-config for further info.

> when i tried to install gtk+ after installing all this it showed the same
> error. What should i do to install wxwidgets? Plz. reply as soon as
> possible.. Coz. i've to finish my proj. quickly.. Thanks and regards...

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


Re: Clean PyQt selection comboBox

2009-11-05 Thread Threader Slash
> -- Original message --
> From: MRAB 
> To: [email protected]
> Date: Thu, 05 Nov 2009 15:37:49 +
> Subject: Re: Clean PyQt selection comboBox
> Threader Slash wrote:
>
>> Hello Everybody, 8)
>>
>> I am using Qt and need to build a selection comboBox -- e.g.:
>> http://www.java2s.com/Tutorial/VBImages/ComboBoxSelectionEventAddValue.PNG.
>>
>> The problem is - after one choice was made, and the code run, for the next
>> time the user select a different choice, both, the present and all past
>> choices run. See what I mean: ;(
>>
>> Code:
>>
>> selected color - blue
>> we are on runBlue
>>
>> selected color - red
>> we are on runBlue
>> we are on runRed
>>
>>
>> Here is the code:
>>
>> .
>> QtCore.QObject.connect(self.selectComboBox,
>>  QtCore.SIGNAL("currentIndexChanged(QString)"),
>>  self.combo_activateInput)   .
>>
>> def combo_activateInput(self):
>>color=unicode(self.selectComboBox.currentText())
>>if(color == "blue"):
>>print "selected color - blue"
>>QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runBlue)
>>
>>if(color == "red"):
>>print "selected color - red"
>>QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runRed)  if(color
>> == "yellow"):
>>
>>print "selected color - yellow"
>>QtCore.QObject.connect(self.okButton,
>> QtCore.SIGNAL("clicked()"), self.combo_runYellow)
>>del color .
>>
>> def combo_runBlue(self):
>>print "we are on runBlue"
>>
>> def combo_runRed(self):
>>print "we are on runRed"
>>
>> def combo_runYellow(self):
>>print "we are on runYellow"
>>
>> I run "del color" to clean the content returned by
>> selectComboBox.currentText, but it didn't clean the content indeed.
>>
>>  "del color" doesn't "clean the content", it just says "forget this
> name", in this case "forget the local variable called 'color'".
>
>  So, any suggestion? All comments and suggestions are highly appreciated.
>> :D :D :D
>>
>>  The ".connect" method connects something each time it's called. If you
> call it multiple times then multiple things will be connected.
>
> Try using ".disconnect" to disconnect what you no longer want connected.
>
> -- --
>

Thanks Man! You saved the day. It solved the problem...

def combo_runBlue(self):
print "we are on runBlue"
QtCore.QObject.disconnect(self.okButton, QtCore.SIGNAL("clicked()"),
self.combo_runBlue)

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


QtPython QtreeWidget - sortingEnabled Problem

2009-11-16 Thread Threader Slash
Hello Everybody,

I trying to do a Qtreewidget to attend a customer design suggestion. I am
coding it on QtPython. I did a first try using Qt Designer, then generated
the code. But when I try to run it, an error comes out:

self.centralwidget.setSortingEnabled(__sortingEnabled)
AttributeError: setSortingEnabled

I googled around, but didn't find any solution for this problem, except some
suggestion just to simply delete the lines in the code that results in the
compiling error. But it didn't really help, because if you do so, it
triggers more error, just like that:

self.treeWidget.topLevelItem(0).child(1).setText(0,
QtGui.QApplication.translate("MainWindow", "Item Name", None,
QtGui.QApplication.UnicodeUTF8))
AttributeError: 'NoneType' object has no attribute 'setText'

Here is my current code to generate a nice simple QtreeWidget/View:

#//===//#
def color_setupUi(self, MainWindow,phrase):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.eqpt_centralwdg(MainWindow)
self.eqpt_retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
#//===//#
def eqpt_centralwdg(self,MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")

self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget)
self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141))
self.colorTreeWidget.setObjectName("colorTreeWidget")

item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
item = QtGui.QTreeWidgetItem(self.colorTreeWidget)

self.centralwidget.setSortingEnabled(__sortingEnabled)
MainWindow.setCentralWidget(self.centralwidget)
#//===//#
def eqpt_retranslateUi(self, MainWindow):

MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
"MainWindow", None, QtGui.QApplication.UnicodeUTF8)

self.colorTreeWidget.headerItem().setText(0,
QtGui.QApplication.translate("MainWindow", "color", None,
QtGui.QApplication.UnicodeUTF8)
__sortingEnabled = self.colorTreeWidget.isSortingEnabled()
self.colorTreeWidget.setSortingEnabled(False)
self.colorTreeWidget.topLevelItem(0).setText(0,
QtGui.QApplication.translate("MainWindow", "Yellow", None,
QtGui.QApplication.UnicodeUTF8)
self.colorTreeWidget.topLevelItem(1).setText(0,
QtGui.QApplication.translate("MainWindow", "Blue", None,
QtGui.QApplication.UnicodeUTF8)
self.colorTreeWidget.setSortingEnabled(__sortingEnabled)
#//===//#

All other object I needed to implement on Qt using Designer and a little bit
of code has worked fine so far, e.g. inputLine, comboBox, TabWidget. I just
got stuck with this TreeWidget error.

Any hints or suggestion are highly appreciated and welcome.
-- 
http://mail.python.org/mailman/listinfo/python-list


Solved: QtPython QtreeWidget - sortingEnabled Problem

2009-11-16 Thread Threader Slash
> --  --
> From: Threader Slash 
> To: [email protected]
> Date: Tue, 17 Nov 2009 10:34:34 +1100
> Subject: QtPython QtreeWidget - sortingEnabled Problem
> Hello Everybody,
>
> I trying to do a Qtreewidget to attend a customer design suggestion. I am
> coding it on QtPython. I did a first try using Qt Designer, then generated
> the code. But when I try to run it, an error comes out:
>
> self.centralwidget.setSortingEnabled(__sortingEnabled)
> AttributeError: setSortingEnabled
>
> I googled around, but didn't find any solution for this problem, except
> some suggestion just to simply delete the lines in the code that results in
> the compiling error. But it didn't really help, because if you do so, it
> triggers more error, just like that:
>
> self.treeWidget.topLevelItem(0).child(1).setText(0,
> QtGui.QApplication.translate("MainWindow", "Item Name", None,
> QtGui.QApplication.UnicodeUTF8))
> AttributeError: 'NoneType' object has no attribute 'setText'
>
> Here is my current code to generate a nice simple QtreeWidget/View:
>
> #//===//#
> def color_setupUi(self, MainWindow,phrase):
> MainWindow.setObjectName("MainWindow")
> MainWindow.resize(800, 600)
> self.eqpt_centralwdg(MainWindow)
> self.eqpt_retranslateUi(MainWindow)
> QtCore.QMetaObject.connectSlotsByName(MainWindow)
> #//===//#
> def eqpt_centralwdg(self,MainWindow):
> self.centralwidget = QtGui.QWidget(MainWindow)
> self.centralwidget.setObjectName("centralwidget")
>
> self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget)
> self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141))
> self.colorTreeWidget.setObjectName("colorTreeWidget")
>
> item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
> item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
>
> self.centralwidget.setSortingEnabled(__sortingEnabled)
> MainWindow.setCentralWidget(self.centralwidget)
> #//===//#
> def eqpt_retranslateUi(self, MainWindow):
>
> MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
> "MainWindow", None, QtGui.QApplication.UnicodeUTF8)
>
> self.colorTreeWidget.headerItem().setText(0,
> QtGui.QApplication.translate("MainWindow", "color", None,
> QtGui.QApplication.UnicodeUTF8)
> __sortingEnabled = self.colorTreeWidget.isSortingEnabled()
> self.colorTreeWidget.setSortingEnabled(False)
> self.colorTreeWidget.topLevelItem(0).setText(0,
> QtGui.QApplication.translate("MainWindow", "Yellow", None,
> QtGui.QApplication.UnicodeUTF8)
> self.colorTreeWidget.topLevelItem(1).setText(0,
> QtGui.QApplication.translate("MainWindow", "Blue", None,
> QtGui.QApplication.UnicodeUTF8)
> self.colorTreeWidget.setSortingEnabled(__sortingEnabled)
> #//===//#
>
> All other object I needed to implement on Qt using Designer and a little
> bit of code has worked fine so far, e.g. inputLine, comboBox, TabWidget. I
> just got stuck with this TreeWidget error.
>
> Any hints or suggestion are highly appreciated and welcome.
>
> --  --
>


Here is the solution:
1. delete/comment only the following line:
#self.centralwidget.setSortingEnabled(__sortingEnabled)

Then code:
[code]
def eqpt_centralwdg(self,MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")

self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget)
self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141))
self.colorTreeWidget.setObjectName("colorTreeWidget")

item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
item = QtGui.QTreeWidgetItem(self.colorTreeWidget)

self.connect(self.colorTreeWidget,
QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'),
self.eqpt_activateInput)

MainWindow.setCentralWidget(self.centralwidget)

def eqpt_activateInput(self,item,col):
print "Qtree ok! pressed"
print item.text(col)
[/code]

Hope this may help others too.
ThreaderSlash
-- 
http://mail.python.org/mailman/listinfo/python-list


Qt Python : QTreeWidget Child Problem

2009-11-16 Thread Threader Slash
Hello Everybody,

I have a QTreewidget that works fine if I have just one level on my
treelist. If I decide to add child sublevels, it gives me an error. Here is
the code, that works nice only without the "childs" lines on it (see after
"child 1" and "child 2").

def eqpt_centralwdg(self,MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")

self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget)
self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141))
self.colorTreeWidget.setObjectName("colorTreeWidget")

# father root 1
item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
#child 1 - from father 1
item = QtGui.QTreeWidgetItem(item)
#child 2 - from father 1
item = QtGui.QTreeWidgetItem(item)
# father root 2
item = QtGui.QTreeWidgetItem(self.colorTreeWidget)

self.connect(self.colorTreeWidget,
QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'),
self.eqpt_activateInput)

MainWindow.setCentralWidget(self.centralwidget)

def eqpt_retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
"MainWindow", None, QtGui.QApplication.UnicodeUTF8)
self.colorTreeWidget.headerItem().setText(0,
QtGui.QApplication.translate("MainWindow", "color", None,
QtGui.QApplication.UnicodeUTF8)
__sortingEnabled = self.colorTreeWidget.isSortingEnabled()
self.colorTreeWidget.setSortingEnabled(False)
# father root 1
self.colorTreeWidget.topLevelItem(0).setText(0,
QtGui.QApplication.translate("MainWindow", "Yellow", None,
QtGui.QApplication.UnicodeUTF8)
#child 1 - from father 1
self.colorTreeWidget.topLevelItem(0).child(0).setText(0,
QtGui.QApplication.translate("MainWindow", "Yellow Sun", None,
QtGui.QApplication.UnicodeUTF8))
#child 2 - from father 1
self.colorTreeWidget.topLevelItem(0).child(1).setText(0,
QtGui.QApplication.translate("MainWindow", "Yellow Gold", None,
QtGui.QApplication.UnicodeUTF8))

# father root 2
self.colorTreeWidget.topLevelItem(1).setText(0,
QtGui.QApplication.translate("MainWindow", "Blue", None,
QtGui.QApplication.UnicodeUTF8)

self.colorTreeWidget.setSortingEnabled(__sortingEnabled)


Here is the output, when it works

def eqpt_activateInput(self,item,col):
print "Qtree ok! pressed"
print item.text(col)

if I exclude the lines related to the "child 1" and "child 2" from the code,
it runs. Otherwise, it gives me the error:

AttributeError: 'NoneType' object has no attribute 'setText'


I used the Qt Designer to generate the code, and added some lines to trigger
events.

Any hints or suggestions are highly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Qt Python : QTreeWidget Child Problem

2009-11-17 Thread Threader Slash
> Hello Everybody,
>
> I have a QTreewidget that works fine if I have just one level on my
> treelist. If I decide to add child sublevels, it gives me an error. Here is
> the code, that works nice only without the "childs" lines on it (see after
>
> "child 1" and "child 2").
>
> def eqpt_centralwdg(self,MainWindow):
> self.centralwidget = QtGui.QWidget(MainWindow)
> self.centralwidget.setObjectName("centralwidget")
>
> self.colorTreeWidget = QtGui.QTreeWidget(self.centralwidget)
> self.colorTreeWidget.setGeometry(QtCore.QRect(60, 60, 191, 141))
> self.colorTreeWidget.setObjectName("colorTreeWidget")
>
> # father root 1
> item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
> #child 1 - from father 1
> item = QtGui.QTreeWidgetItem(item)
> #child 2 - from father 1
> item = QtGui.QTreeWidgetItem(item)
>
> # father root 2
> item = QtGui.QTreeWidgetItem(self.colorTreeWidget)
>
> self.connect(self.colorTreeWidget,
> QtCore.SIGNAL('itemClicked(QTreeWidgetItem*, int)'),
> self.eqpt_activateInput)
>
> MainWindow.setCentralWidget(self.centralwidget)
>
> def eqpt_retranslateUi(self, MainWindow):
> MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
> "MainWindow", None, QtGui.QApplication.UnicodeUTF8)
>
> self.colorTreeWidget.headerItem().setText(0,
> QtGui.QApplication.translate("MainWindow", "color", None,
> QtGui.QApplication.UnicodeUTF8)
> __sortingEnabled = self.colorTreeWidget.isSortingEnabled()
>
> self.colorTreeWidget.setSortingEnabled(False)
> # father root 1
> self.colorTreeWidget.topLevelItem(0).setText(0,
> QtGui.QApplication.translate("MainWindow", "Yellow", None,
>
> QtGui.QApplication.UnicodeUTF8)
> #child 1 - from father 1
> self.colorTreeWidget.topLevelItem(0).child(0).setText(0,
> QtGui.QApplication.translate("MainWindow", "Yellow Sun", None,
>
> QtGui.QApplication.UnicodeUTF8))
> #child 2 - from father 1
> self.colorTreeWidget.topLevelItem(0).child(1).setText(0,
> QtGui.QApplication.translate("MainWindow", "Yellow Gold", None,
>
> QtGui.QApplication.UnicodeUTF8))
>
> # father root 2
> self.colorTreeWidget.topLevelItem(1).setText(0,
> QtGui.QApplication.translate("MainWindow", "Blue", None,
> QtGui.QApplication.UnicodeUTF8)
>
> self.colorTreeWidget.setSortingEnabled(__sortingEnabled)
>
>
> Here is the output, when it works
>
> def eqpt_activateInput(self,item,col):
> print "Qtree ok! pressed"
> print item.text(col)
>
> if I exclude the lines related to the "child 1" and "child 2" from the code,
> it runs. Otherwise, it gives me the error:
>
> AttributeError: 'NoneType' object has no attribute 'setText'
>
>
> I used the Qt Designer to generate the code, and added some lines to trigger
> events.
>
> Any hints or suggestions are highly appreciated.
>
>
Solved!
Here is the solution:

parent1 = QtGui.QTreeWidgetItem(self.colorTreeWidget)
child1_1 = QtGui.QTreeWidgetItem()
child1_2 = QtGui.QTreeWidgetItem()
parent1.addChild(child1_1)
parent1.addChild(child1_2)

Now it works properly.

Hope this may help others too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Qt Python radiobutton: activate event

2009-11-17 Thread Threader Slash
Hi Everybody,

I am developing a project for one customer, where the design has a radio
button with exclusive options.

Here is a piece of the code that runs and show two nice radio buttons:

self.performGroupBox = QtGui.QGroupBox(self.centralwidget)
self.performGroupBox.setGeometry(QtCore.QRect(50, 20, 181, 121))
self.performGroupBox.setObjectName("performGroupBox")

self.consultRadioButton = QtGui.QRadioButton(self.performGroupBox)
self.consultRadioButton.setGeometry(QtCore.QRect(40, 30, 84, 18))
self.consultRadioButton.setObjectName("consultRadioButton")

self.insertRadioButton = QtGui.QRadioButton(self.performGroupBox)
self.insertRadioButton.setGeometry(QtCore.QRect(40, 60, 84, 18))
self.insertRadioButton.setObjectName("insertRadioButton")

it just looks like:

perform:
() Consult
() Insert


The point here is, how to know what choice was marked: "consultRadioButton"
or "insertRadioButton"?

Here is a sample on trying to get this information:

if self.consultRadioButton.isChecked():
self.call_Consult()
if self.insertRadioButton.isChecked():
self.call_Insert()

But it didn't do anything when the radiobutton is chosen.

Otherwise, using connect should be another option:

QtCore.QObject.connect(self.consultRadioButton,
QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Consult)
QtCore.QObject.connect(self.insertRadioButton,
QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Insert)

But it didn't work either.

What is missing here... Any suggestion?

All comments are highly welcome and appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Solved: Inserting Unicode text with MySQLdb in Python 2.4-2.5?

2009-11-18 Thread Threader Slash
-- Forwarded message --
From: Keith Hughitt 
To: [email protected]
Date: Wed, 18 Nov 2009 06:09:11 -0800 (PST)
Subject: Inserting Unicode text with MySQLdb in Python 2.4-2.5?
Hi all,

I ran into a problem recently when trying to add support for earlier
versions of Python (2.4 and 2.5) to some database related code which
uses MySQLdb, and was wondering if anyone has any suggestions.

With later versions of Python (2.6), inserting Unicode is very simple,
e.g.:

   # -*- coding: utf-8 -*-
   ...
   cursor.execute('''INSERT INTO `table` VALUES (0,
'Ångström'),...''')

When the same code is run on earlier versions, however, the results is
either garbled text (e.g. "Ã or "?" instead of "Å" in Python 2.5), or
an exception being thrown (Python 2.4):

   UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in
position 60: ordinal not in range(128)

So far I've tried a number of different things, including:

   1. Using Unicode strings (e.g. u"\u212B")

   2. Manually specifying the encoding using sys.setdefaultencoding
('utf-8')

   3. Manually enabling Unicode support in MySQLdb
(use_unicode=False, charset = "utf8")

...but no combination of any of the above resulted in proper database
content.

To be certain that the issue was related to Python/MySQLdb and not
MySQL itself, I manually inserted the text and it worked just fine.
Furthermore, when working in a Python console, both print "Å" and
print u"\u212B" display the correct output.

Any ideas? The versions of the MySQLdb adapter tested were 1.2.1
(Python 2.4), and 1.2.2-10 (Python 2.5).

Thanks!
Keith


Hello Keithm,

Here is your answer...

I run on Python2.5, this syntax works fine for me -- a piece of my code:

getMaxID_Query = """SELECT MAX(customerID)
FROM customer;"""

self.cursorMySQL.execute(getMaxID_Query)

Try to use: """ instead of ''' . It will solve your problem.

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


Qt Python radiobutton: activate event

2009-11-18 Thread Threader Slash
Hi Guys,

I am trying to get the choice made by the user on Python Qt with
radiobutton.

QtCore.QObject.connect(self.radioButton1,
QtCore.SIGNAL("toggled()"),self.radio_activateInput)
QtCore.QObject.connect(self.radioButton2,
QtCore.SIGNAL("toggled()"),self.radio_activateInput)

and that

QtCore.QObject.connect(self.performGroupBox,
QtCore.SIGNAL("toggled()"),self.radio_activateInput)

But it didn't make anything when I click on the option.

Yes, I have enabled it:

self.radioButton1.setCheckable(True)
self.radioButton1.setChecked(True)
self.radioButton2.setCheckable(True)

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


Re: Python-list Digest, Vol 74, Issue 245

2009-11-19 Thread Threader Slash
On Thu, Nov 19, 2009 at 7:05 PM,  wrote:

>
> --  --
> From: Threader Slash 
> To: [email protected]
> Date: Thu, 19 Nov 2009 14:51:27 +1100
> Subject: Qt Python radiobutton: activate event
> Hi Guys,
>
> I am trying to get the choice made by the user on Python Qt with
> radiobutton.
>
> QtCore.QObject.connect(self.radioButton1,
> QtCore.SIGNAL("toggled()"),self.radio_activateInput)
> QtCore.QObject.connect(self.radioButton2,
> QtCore.SIGNAL("toggled()"),self.radio_activateInput)
>
> and that
>
> QtCore.QObject.connect(self.performGroupBox,
> QtCore.SIGNAL("toggled()"),self.radio_activateInput)
>
> But it didn't make anything when I click on the option.
>
> Yes, I have enabled it:
>
> self.radioButton1.setCheckable(True)
> self.radioButton1.setChecked(True)
> self.radioButton2.setCheckable(True)
>
> Any suggestion?
>
>
> -- Forwarded message --
>

Here is solution... now working:

QtCore.QObject.connect(self.radioButton1,QtCore.SIGNAL("toggled(bool)"),self.radio_activateInput)

when have the parameter bool included into toggled to signal, it worked.

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


problem with pyqt.. help please...

2009-11-22 Thread Threader Slash
-- Forwarded message --
From: Jebagnana Das 
To: [email protected]
Date: Sat, 21 Nov 2009 19:17:56 +0530
Subject: problem with pyqt.. help please...
Hi friends,
 I've recently changed to ubuntu 9.04.. I've not had any problem
with the installation of pyqt as it is available from the ubuntu
repositories with umpteen number of packages.. Anyhow i've to download
tarball file for python 3.1 and installed it.. I found that PyQt4 supports
python 3.1(Am i right?)..

I wanted to check the pyqt installation with a sample program..

import sys
from PyQt4 import QtGui
app=QtGui.QApplication(sys.argv)
widget=QtGui.QWidget()
widget.resize(250,150)
widget.setWindowTitle('Simple')
widget.show()
sys.exit(app.exec_())

when i issued the command
$python simple.py
it worked perfectly since it's executed with 2.6 installation..
But when i tried to execute it with
$python3 simple.py
it showed the error like
ImportError: No module named PyQt4
So i searched the sys.path for 2.6 and included
/usr/lib/python2.6/dist-packages
in python3 sys.path...
Now when i tried to run this with python3  the error is like..
ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined
symbol: PyString_FromString
I got the same error when i tried to execute another program... So can u
please tell me how to solve this problem?? Am i heading in the right
direction???...

Thanks & Regards...

Jebagnanadas,
Python Learner..

...
it just looks like your problem is on setting your installation paths. Have
a look here:
http://www.linux.org/docs/ldp/howto/Nvidia-OpenGL-Configuration/instqt.html
http://www.linuxforums.org/forum/debian-linux-help/108948-setting-path-qt.html

Check and follow the steps. It should fix your problem.
- ThreaderSlash.
-- 
http://mail.python.org/mailman/listinfo/python-list


QtPython: removeChild/addChild QGroupBox

2009-11-23 Thread Threader Slash
Hi Everybody,

I am developing a system for a customer which is displayed in a set of
GroupBox.
Depending on mouse events, the container (groupBox) must be removed from the
centralwidget, or then added with new updated data for the table.
Here is a piece of the code that runs nicely and shows the a groupBox.

Now it starts to show some effects on removeWidget, but it is still didn't
clear the box completely.. just the right border of the box is erased.

   self.vLayout_wdg = QtGui.QWidget(self.centralwidget)
   self.vLayout_wdg.setGeometry(QtCore.QRect(40, 160, 171, 121))
   self.vLayout_wdg.setObjectName("vLayout_wdg")

   self.vLayoutBoxObj = QtGui.QVBoxLayout(self.vLayout_wdg)
   self.vLayoutBoxObj.setObjectName("vLayoutBoxObj")

   self.newGroupBox = QtGui.QGroupBox(self.vLayout_wdg)
   self.newGroupBox.setObjectName("newGroupBox")

   self.radioButton1 = QtGui.QRadioButton(self.newGroupBox)
   self.radioButton1.setGeometry(QtCore.QRect(30, 30, 101, 21))
   self.radioButton1.setObjectName("helloRadioButton")

   self.radioButton2 = QtGui.QRadioButton(self.newGroupBox)
   self.radioButton2.setGeometry(QtCore.QRect(30, 60, 111, 18 )
   self.radioButton2.setObjectName("niceRadioButton")

   self.vLayoutBoxObj.addWidget(self.newGroupBox)

   if removeContainer_Button_Pressed:
 self.vLayoutBoxObj.removeWidget(self.newGroupBox)
 self.newGroupBox.adjustSize()
 self.vLayoutBoxObj.deleteLater()
 self.vLayoutBoxObj.update()

All hints and comments are highly welcome and appreciated.
ThreaderSlash
-- 
http://mail.python.org/mailman/listinfo/python-list


python-win32 : cross database automation

2009-09-18 Thread Threader Slash
Hello Everybody...

I working on a client-server database solution. The system is normalized and
is using MySQL. To automate some of processes I using Python. Part of the
old database will be still running on Lotus Notes.

After working on it, it seems that the best choice to directly manipulate
Lotus is to use Python with win32COM -
http://www.boddie.org.uk/python/COM.html . I installed ActivePython 2.6
compiler, which comes with integrated win32com.

However, when I try to run.. it gives me the error:

--x--x--

ActivePython 2.6.2.2 (ActiveState Software Inc.) based on
Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)]
on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
>>> sess=win32com.client.Dispatch("Lotus.NotesSession")
Traceback (most recent call last):
File "", line 1, in 
File "C:\dev\python\Py26\lib\site-packages\win32com\client\__init__.py",
line 95, in Dispatch
dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\dev\python\Py26\lib\site-packages\win32com\client\dynamic.py", line
98, in _GetGoodDispatchAndUserN
ame
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\dev\python\Py26\lib\site-packages\win32com\client\dynamic.py", line
78, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

--x--x--

Any suggestions? Some help is mostly appreciated.

I will keep working to get it fixed, after I post the working solution here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 72, Issue 210

2009-09-21 Thread Threader Slash
Hi Roman,

I am using MySQL with Python -- in Windows XP for a contract.

I hope my comments can be useful:

When dealing with installation on Python, I noticed that tiny details can
make a difference -- e.g. first I installed the latest version of Python
3.x, but it did not attend what I am looking for: the need to put MySQLdb
and Python to communicate together.

Then what I need to do was to downgrade the Python version to Python 2.5
which works nicely with the MySQLdb2.5 package. I also installed the
ActivePython-2.6 to get it working with win32com. The ActivePython looks to
me a more complete version of Python compiler.

Then, in the sequence I configured it to compile using Eclipse IDE.

Threader.

-- Forwarded message --
From: Roman Gorbunov 
To: [email protected]
Date: Sat, 19 Sep 2009 08:18:31 -0700 (PDT)
Subject: How to install pysqlite?
Hi all,

I am trying to install pysqlite (Python interface to the SQLite). I
downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I
did the following:

gunzip pysqlite-2.5.5.tar.gz
tar xvf pysqlite-2.5.5.tar
cd pysqlite-2.5.5
python setup.py install

At the last step I have a problem. I get the following error message:
error: command 'gcc' failed with exit status 1

I found that other peoples also had this problem. For example here:
http://forums.opensuse.org/applications/400363-gcc-fails-during-pysqlite-install.html

As far as I understood in the person had a problem because sqlite2 was
not installed. But in my case, I have sqlite3 (I can run it from
command line).

May be I should change some paths in "setup.cfg"? At the moment I have
there:
#define=
#include_dirs=/usr/local/include
#library_dirs=/usr/local/lib
libraries=sqlite3
define=SQLITE_OMIT_LOAD_EXTENSION

And if I type "which sqlite3" I get:
/usr/bin/sqlite3

Can anybody pleas help me with that problem.

Thank you in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Compile kinterbasdb with mingw32 and python 2.6 - DLL load failed

2009-09-21 Thread Threader Slash
I have spent two week working with MinGW. The conclusion I came after a lot
of headaches and making the project getting late is: MinGW doesn't work
properly on MS Windows -- there are many conflicting variables and functions
with similar names on MinGW libs and MS Libs, e.g. windows.h, etc, etc. My
suggestion... avoid it. If you really need a C compiler to work on MS, try
anything else.



--  --
From: Laszlo Nagy 
To: "python-list (General)" 
Date: Mon, 21 Sep 2009 08:53:06 +0430
Subject: Compile kinterbasdb with mingw32 and python 2.6 - DLL load failed
This is what I did so far:

#1. Install Python 2.6, Firebird 1.5 server (with libs and headers), egenix
mx base and mingw C compiler
#2. put "c:\MinGW\bin"  on the PATH (or wherever it is)
#3. extract kinterbasdb source to a temp folder
#4. hack setup.cfg. Change the build section:

[build]
compiler=mingw32

#5. hack setup.py

Replace this:
  customCompilerName = 'msvc'
With this:
  customCompilerName = 'mingw32-gcc'

#6. run "python setup.py install"

The building and installation went find. But I cannot "import kinterbasdb"
because I get a "DLL load failed" error. I figured out that has something to
do with msvcr90 and "_ftime". Can you please give me some advice how to
solve this problem?

Thanks,

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


Python: automate input to MySQL query

2009-09-21 Thread Threader Slash
Hi Everybody...

I have a query that works as follows:

 Code:

db.query("""SELECT traveler.travelerFirstName,vaccine.vaccineName from
(traveler INNER JOIN takenvaccine ON traveler.travelerID =
takenvaccine.travelerID)
INNER JOIN vaccine ON takenvaccine.vaccineID=vaccine.vaccineID
INNER JOIN requiredvaccine ON
vaccine.vaccineID=requiredvaccine.requiredvaccineID
INNER JOIN city ON requiredvaccine.cityID = city.cityID
WHERE traveler.travelerFirstName = 'John'""")

The output gives me all vaccines taken by a given employee. To allow the
user to choose different names when running the system, I am trying to use a
variable, named *person*:

 Code:

person = "John"

db.query("""SELECT traveler.travelerFirstName,vaccine.vaccineName from
(traveler INNER JOIN takenvaccine ON traveler.travelerID =
takenvaccine.travelerID)
INNER JOIN vaccine ON takenvaccine.vaccineID=vaccine.vaccineID
INNER JOIN requiredvaccine ON
vaccine.vaccineID=requiredvaccine.requiredvaccineID
INNER JOIN city ON requiredvaccine.cityID = city.cityID
WHERE traveler.travelerFirstName = 'person'""")

Then I run the query inside my python program. The first version without
variable works fine. But the second, using variable, doesn't give me any
output. What I am missing here about the python variable sintaxe to make the
MySQL work with variable ... Any suggestion?

All comments or suggestions are highly appreciated!

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


Solved - Python: automate input to MySQL query

2009-09-21 Thread Threader Slash
-- Forwarded message --
> From: Philip Semanchuk 
> To: "Python-list (General)" 
> Date: Mon, 21 Sep 2009 08:49:27 -0400
> Subject: Re: Python: automate input to MySQL query
>
> On Sep 21, 2009, at 5:18 AM, Threader Slash wrote:
>
>  Hi Everybody...
>>
>> I have a query that works as follows:
>>
>> Code:
>>
>> db.query("""SELECT traveler.travelerFirstName,vaccine.vaccineName from
>> (traveler INNER JOIN takenvaccine ON traveler.travelerID =
>> takenvaccine.travelerID)
>>   INNER JOIN vaccine ON takenvaccine.vaccineID=vaccine.vaccineID
>>   INNER JOIN requiredvaccine ON
>> vaccine.vaccineID=requiredvaccine.requiredvaccineID
>>   INNER JOIN city ON requiredvaccine.cityID = city.cityID
>> WHERE traveler.travelerFirstName = 'John'""")
>>
>> The output gives me all vaccines taken by a given employee. To allow the
>> user to choose different names when running the system, I am trying to use
>> a
>> variable, named *person*:
>>
>> Code:
>>
>> person = "John"
>>
>> db.query("""SELECT traveler.travelerFirstName,vaccine.vaccineName from
>> (traveler INNER JOIN takenvaccine ON traveler.travelerID =
>> takenvaccine.travelerID)
>>   INNER JOIN vaccine ON takenvaccine.vaccineID=vaccine.vaccineID
>>   INNER JOIN requiredvaccine ON
>> vaccine.vaccineID=requiredvaccine.requiredvaccineID
>>   INNER JOIN city ON requiredvaccine.cityID = city.cityID
>> WHERE traveler.travelerFirstName = 'person'""")
>>
>> Then I run the query inside my python program. The first version without
>> variable works fine. But the second, using variable, doesn't give me any
>> output. What I am missing here about the python variable sintaxe to make
>> the
>> MySQL work with variable ... Any suggestion?
>>
>
> In your second query you've got "person" hardcoded as a string. You're
> looking for a traveler with the actual first name of person.
>
> Change this line:
>
>> WHERE traveler.travelerFirstName = 'person'""")
>>
>
> to this:
>
>> WHERE traveler.travelerFirstName = %s""")
>>
>
> and pass person as a list of params to db.query(). Something like this
> should work:
>
> sql = """SELECT blah blah blah WHERE traveler.travelerFirstName = %s"""
> db.query(sql, [person])
>
> See the Python DB API documentation for specifics. This might look like the
> same thing as string interpolation, but it isn't.
>
> Good luck
> Philip
>

Hi Philip,

Thanks for comments and suggestions.

Now it works! Here is the solution:

 Code:


self.db = MySQLdb.connect(hostname,username,passwd,dbname)
self.cursor=self.db.cursor();

name="John"
runQuery="SELECT traveler.travelerFirstName,vaccine.vaccineName from
traveler INNER JOIN takenvaccine ON traveler.travelerID =
takenvaccine.travelerID INNER JOIN vaccine ON
takenvaccine.vaccineID=vaccine.vaccineID INNER JOIN requiredvaccine ON
vaccine.vaccineID=requiredvaccine.requiredvaccineID INNER JOIN site ON
requiredvaccine.siteID = site.siteID WHERE traveler.travelerFirstName
= %s"

self.cursor.execute(runQuery,(name,))

print "tell vaccines taken for a chosen traveler\n"

for row in self.cursor.fetchall():
 print row


Note: you need to declare the whole query in the same line to it take effect
in the variable "runQuery".
-- 
http://mail.python.org/mailman/listinfo/python-list


[SQL] Pick random rows from SELECT?

2009-09-21 Thread Threader Slash
Here is a simple and quick solution --

Generate a random number
"random.shuffle(x[, random])¶Shuffle the sequence x in place. The optional
argument random is a 0-argument function returning a random float in [0.0,
1.0); by default, this is the function random()."
http://docs.python.org/library/random.html

Multiple the random value returned by the maxnumber of your table primary
key index.
http://www.tizag.com/mysqlTutorial/mysqlmax.php

Then use the result in your query as

randID = MAX(id) * random()

SELECT objectname FROM products WHERE objectID = randID

Hope this help.
Cheers... Threader


-- Forwarded message --
From: Dennis Lee Bieber 
To: [email protected]
Date: Mon, 21 Sep 2009 21:40:02 -0700
Subject: Re: [SQL] Pick random rows from SELECT?
On Mon, 21 Sep 2009 10:59:38 +0200, Gilles Ganault 
declaimed the following in gmane.comp.python.general:

> Since this list is quite big and the site is the bottleneck, I'd like
> to run multiple instances of this script, and figured a solution would
> be to pick rows at random from the dataset, check in my local database
> if this item has already been taken care of, and if not, download
> details from the remote web site.
>
   You really think making MULTIPLE, overlapping requests to a web site
is going to be more efficient than just suffering the single transfer
time of one large query?

> If someone's done this before, should I perform the randomization in
> the SQL query (SQLite using the APSW wrapper
> http://code.google.com/p/apsw/), or in Python?
>
   Pardon, I thought you implied the bottleneck is the web-site
database -- I'd worry about any web-site that exposes a file-server
based database to direct user access.

> Here's some simplified code:
>
> sql = 'SELECT id,label FROM companies WHERE activity=1'
> rows=list(cursor.execute(sql))
> for row in rows:
>   id = row[0]
>   label = row[1]
>
>   print strftime("%H:%M")
>   url = "http://www.acme.com/details.php?id=%s"; % id
>   req = urllib2.Request(url, None, headers)
>   response = urllib2.urlopen(req).read()
>
>   name = re_name.search(response)
>   if name:
>   name = name.group(1)
>   sql = 'UPDATE companies SET name=? WHERE id=?'
>   cursor.execute(sql, (name,id) )

   Ah... You mean you are retrieving the names from a local database,
and then requesting web-site details based upon that name.

   No matter how you look at it, you appear to want to process the
entire local list of companies... Multiple randomized local queries will
just add to the final run-time as you start to get duplicates -- and
have to reject that one to query for another random name.

   I'd suggest either a pool of threads -- 5-10, each reading company
names from a shared QUEUE, which is populated by the main thread
(remember to commit() so that you don't block on database updates by the
threads). OR... determine how many companies there are, and start
threads feeding them  and  (length being #names /
#threads, round up -- start then being 0*length+1, 1*length+1, etc...)
and use those in thread specific selects using "... limit 
offset "... This way each thread retrieves its own limited set of
companies (make sure to use the same sorting criteria).
--
   Wulfraed Dennis Lee Bieber   KD6MOG
   [email protected]
HTTP://wlfraed.home.netcom.com/




-- Forwarded message --
From: greg 
To: [email protected]
Date: Tue, 22 Sep 2009 17:07:33 +1200
Subject: Re: Comparison of parsers in python?
Nobody wrote:

 What I want: a tokeniser generator which can take a lex-style grammar (not
> necessarily lex syntax, but a set of token specifications defined by
> REs, BNF, or whatever), generate a DFA, then run the DFA on sequences of
> bytes. It must allow the syntax to be defined at run-time.
>

You might find my Plex package useful:

http://www.cosc.canterbury.ac.nz/greg.ewing/python/Plex/

It was written some time ago, so it doesn't know about
the new bytes type yet, but it shouldn't be hard to
adapt it for that if you need to.

 What I don't want: anything written by someone who doesn't understand the
> field (i.e. anything which doesn't use a DFA).
>

Plex uses a DFA.

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


Solved - Python: automate input to MySQL query

2009-09-22 Thread Threader Slash
Hi Dennis,
You're right. Putting """ allows indentation. Great!

About putting the name of the table: x.travelerID, etc.. I think it keep the
query more documented, specially when you are dealing with 5 tables in a
same query, like this query.

Cheers.. Threader.

-- Forwarded message --
From: Dennis Lee Bieber 
To: [email protected]
Date: Tue, 22 Sep 2009 10:43:52 -0700
Subject: Re: Solved - Python: automate input to MySQL query
On Tue, 22 Sep 2009 15:58:18 +1000, Threader Slash
 declaimed the following in
gmane.comp.python.general:

>
> self.db = MySQLdb.connect(hostname,username,passwd,dbname)
> self.cursor=self.db.cursor();
>
> name="John"
> runQuery="SELECT traveler.travelerFirstName,vaccine.vaccineName from
> traveler INNER JOIN takenvaccine ON traveler.travelerID =
> takenvaccine.travelerID INNER JOIN vaccine ON
> takenvaccine.vaccineID=vaccine.vaccineID INNER JOIN requiredvaccine ON
> vaccine.vaccineID=requiredvaccine.requiredvaccineID INNER JOIN site ON
> requiredvaccine.siteID = site.siteID WHERE traveler.travelerFirstName
> = %s"
>
   
>
> Note: you need to declare the whole query in the same line to it take
effect
> in the variable "runQuery".

   No, you don't... IF you wrap it in triple-quotes...

runQuery="""select t.travelerFirstName, v.vaccineName
   from traveler as t
   inner join takenvaccine as tv
   on t.travelerID = tv.travelerID
   inner join vaccine as v
   on tv.vaccineID = v.vaccineID
   inner join requiredvaccine as rv
   on v.vaccineID = rv.requiredvaccineID
   inner join site as s
   on rv.siteID = s.siteID
   where t.travelerFirstName = %s"""

Should be perfectly acceptable to Python and the database query
processor.

   I'm not too impressed with the database naming scheme -- if the
TABLE is named "x", why prefix all the fields in the table with the same
"x"
   requiredvaccine.requiredvaccineID
is rather redundant -- same with all the others. The only place where it
might be justified is when it is a foreign key linkage.

   vaccine.ID  ID of the vaccine record

   requiredvaccine.ID  ID of the rv record itself, not of
the
vaccine
   requiredvaccine.vaccineID   foreign key, ID /in/ vaccine
that
this record refers to.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-Qt problem with pyuic4

2009-09-23 Thread Threader Slash
Hello Everybody

I have used Qt Designer to generate a basic GUI. The file saved from Qt
Designer I named it myGUI.ui .

Now, I have to generate from myGUI.ui the ui_myGUI.py. To get this done, we
must run pyuic4, directly or via mkpuqt.py or Make PyQt. I tried to get it
done, so went into the Py25 console:

 Code:

pyuic4 -o C:\dev\prgr\src\ui_myGUI.py C:\dev\prgr\src\myGUI.ui
The system cannot find the path specified.

Then to be sure, I moved the file myGUI.ui to the folder where is found the
pyuic4, and run again...

 Code:

pyuic4 -o ui_myGUI.py myGUI.ui
The system cannot find the path specified.

I didn't figure out how to get it running.

I googled around and didn't find much useful material or any practical
example/setup on internet  about
how to put the pyuic4 to generate the ui_myGUI.py.

Of course the better would be to run pyuic4 directly from the Eclipse
IDE,
which I have integrated and compiling Python 2.5 and 2.6. However, no way is
working.

What I am doing wrong, or what is missing here?

All comments or suggestions are mostly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-Qt problem with pyuic4

2009-09-23 Thread Threader Slash
Hello Xavier.. thanks! [?]

Just tried..

pyuic4 -o C:\dev\prgr\src\ui_myGUI.py -x C:\dev\prgr\src\myGUI.ui
The system cannot find the path specified.

pyuic4 -o ui_myGUI.py -x myGUI.ui
The system cannot find the path specified.

Very strange. [?]

Yep.. the ..!\Py25\Lib\site-packages\PyQt4 is included into the System
Properties : Environment Variables : Path.

Still gives the same error. [?]



On Thu, Sep 24, 2009 at 10:45 AM, Xavier Lapointe
wrote:

> Have you tried something like so?
>
> pyuic4 -o C:\dev\prgr\src\ui_myGUI.py -x C:\dev\prgr\src\myGUI.ui
>
>
>
> (Sorry if double post occured - just changed my Mailing list account ..)
>
<<983.png>><<331.png>><<35C.png>>-- 
http://mail.python.org/mailman/listinfo/python-list


Python-Qt problem with pyuic4

2009-09-23 Thread Threader Slash
Hi Xavier

Yes. You are right, I am in WinXP - developing a client-server database for
a customer. I am pretty sure that this type of problem won't be happening on
Linux.

Anyway, I did both way about the path. It didn't work and keep giving that
same error message.

Maybe it seems to be a bug .. see:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=523059 .

Cheers [?]



On Thu, Sep 24, 2009 at 10:45 AM, Xavier Lapointe
wrote:
>
>> Have you tried something like so?
>>
>> pyuic4 -o C:\dev\prgr\src\ui_myGUI.py -x C:\dev\prgr\src\myGUI.ui
>>
>>
>>
>> (Sorry if double post occured - just changed my Mailing list account ..)
>>
>
>
<<35C.png>>-- 
http://mail.python.org/mailman/listinfo/python-list


IDE for python similar to visual basic

2009-09-25 Thread Threader Slash
> -- Forwarded message --
> From: J Sisson 
> To: Nobody 
> Date: Thu, 24 Sep 2009 19:18:03 -0500
> Subject: Re: IDE for python similar to visual basic
>
>
> On Sun, Sep 13, 2009 at 6:25 AM, Nobody  wrote:
>
>> On Fri, 11 Sep 2009 05:27:59 -0700, r wrote:
>>
>
>
>>  > Sounds like "somebody" failed to get input
>> > from their users at design time. Or "somebody" has the inability to
>> > relate to their end users.
>>
>> You're assuming that there is some "right" answer which is appropriate for
>> all users. There isn't.
>>
>
> I worked for a company that had a team composed of graphic artists, QA
> types, etc...that did nothing but draw up GUI's, show them to customers,
> revise them, write up runnable "dummies" of the approved GUI's, performed
> usability studies with our customers using the dummy GUI's, and finally
> handed the GUI's over to dev so they could put in the guts to make it "do
> stuff".
>
> "Bugs" or "Cases" involving the GUI needing revision because a button
> needed to be moved for usability were *extremely* rare, and the GUI didn't
> require an additional toolset that allowed end users to tweak them.
>
>
 My favorite IDE : Eclipse

http://pydev.org/download.html

http://www.ibm.com/developerworks/opensource/library/os-eclipse-visualstudio

http://www.eclipse.org

Of course you have also the Mono:
http://monodevelop.com

Cheers.|:0),
-- 
http://mail.python.org/mailman/listinfo/python-list