Re: QDoubleValidator

2010-01-14 Thread Helvin
Zabin,

The QDoubleValidator class works, but it allows 'intermediate' values
to show in the widget. This problem has been addressed here:
http://qt.nokia.com/developer/faqs/faq.2006-05-15.0450651751, I just
tried to implement this in PyQt again, and it worked! =P

I've posted the working code here:
http://learnwithhelvin.blogspot.com/2010/01/qdoublevalidator.html

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


Remove empty strings from list

2009-09-14 Thread Helvin
Hi,

Sorry I did not want to bother the group, but I really do not
understand this seeming trivial problem.
I am reading from a textfile, where each line has 2 values, with
spaces before and between the values.
I would like to read in these values, but of course, I don't want the
whitespaces between them.
I have looked at documentation, and how strings and lists work, but I
cannot understand the behaviour of the following:
line = f.readline()
line = line.lstrip() # take away whitespace at the 
beginning of the
readline.
list = line.split(' ') # split the str line into a list

# the list has empty strings in it, so now,
remove these empty strings
for item in list:
if item is ' ':
print 'discard these: ',item
index = list.index(item)
del list[index] # remove this 
item from the list
else:
print 'keep this: ',item
The problem is, when my list is :  ['44', '', '', '', '', '',
'0.0\n']
The output is:
len of list:  7
keep this:  44
discard these:
discard these:
discard these:
So finally the list is:   ['44', '', '', '0.0\n']
The code above removes all the empty strings in the middle, all except
two. My code seems to miss two of the empty strings.

Would you know why this is occuring?

Regards,
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Remove empty strings from list

2009-09-14 Thread Helvin Lui
Thanks Chris! Thanks for the quick reply. Indeed this is the case! I have
now written out a new list, instead of modifying the list I am iterating
over.
Logged at my blog:
http://learnwithhelvin.blogspot.com/2009/09/python-loop-and-modify-list.html

Regards,
Helvin  =)

On Tue, Sep 15, 2009 at 1:55 PM, Chris Rebert c...@rebertia.com wrote:

 On Mon, Sep 14, 2009 at 6:49 PM, Helvin helvin...@gmail.com wrote:
  Hi,
 
  Sorry I did not want to bother the group, but I really do not
  understand this seeming trivial problem.
  I am reading from a textfile, where each line has 2 values, with
  spaces before and between the values.
  I would like to read in these values, but of course, I don't want the
  whitespaces between them.
  I have looked at documentation, and how strings and lists work, but I
  cannot understand the behaviour of the following:
 line = f.readline()
 line = line.lstrip() # take away whitespace at the
 beginning of the
  readline.
 list = line.split(' ') # split the str line into a
 list
 
 # the list has empty strings in it, so now,
  remove these empty strings
 for item in list:
 if item is ' ':
 print 'discard these: ',item
 index = list.index(item)
 del list[index] # remove
 this item from the list
 else:
 print 'keep this: ',item
  The problem is, when my list is :  ['44', '', '', '', '', '',
  '0.0\n']
  The output is:
 len of list:  7
 keep this:  44
 discard these:
 discard these:
 discard these:
  So finally the list is:   ['44', '', '', '0.0\n']
  The code above removes all the empty strings in the middle, all except
  two. My code seems to miss two of the empty strings.
 
  Would you know why this is occuring?

 Block quoting from http://effbot.org/zone/python-list.htm
 
 Note that the for-in statement maintains an internal index, which is
 incremented for each loop iteration. This means that if you modify the
 list you’re looping over, the indexes will get out of sync, and you
 may end up skipping over items, or process the same item multiple
 times.
 

 Thus why your code is skipping over some elements and not removing them.
 Moral: Don't modify a list while iterating over it. Use the loop to
 create a separate, new list from the old one instead.

 Cheers,
 Chris
 --
 http://blog.rebertia.com




-- 
Helvin

Though the world may promise me more, I'm just made to be filled with the
Lord.
-- 
http://mail.python.org/mailman/listinfo/python-list


QTableWidgetItem-list

2009-09-13 Thread Helvin
Hi,

Could not find anything on this online, except the documentation,
which does not explain how to work with a QTableWidgetItem-list. How
do I get out what QWidgetTable.finditems found?

I have a string that I want to find in my table. I want to locate the
row it's in, then delete the row.
My code:

foundList = 
table_points.findItems(str(picked_node),
QtCore.Qt.MatchExactly)
inRow = 
self.ui.table_points.column(foundList)  # trying to
locate the row, but this does not work

where,
table_points: my table
picked_node:  an integer value I want to locate in table_points


Help MUCH appreciated!
Helvin
Newbie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: QTableWidgetItem-list

2009-09-13 Thread Helvin
On Sep 14, 7:18 am, Helvin helvin...@gmail.com wrote:
 Hi,

 Could not find anything on this online, except the documentation,
 which does not explain how to work with a QTableWidgetItem-list. How
 do I get out what QWidgetTable.finditems found?

 I have a string that I want to find in my table. I want to locate the
 row it's in, then delete the row.
 My code:

                                         foundList = 
 table_points.findItems(str(picked_node),
 QtCore.Qt.MatchExactly)
                                         inRow = 
 self.ui.table_points.column(foundList)  # trying to
 locate the row, but this does not work

 where,
     table_points: my table
     picked_node:  an integer value I want to locate in table_points

 Help MUCH appreciated!
 Helvin
 Newbie

Sorry, forgot to mention I am using PyQT.

Regards,
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list


global variable not working inside function. Increment

2009-09-04 Thread Helvin
Hi,

This increment thing is driving me nearly to the nuts-stage.  

I have a function that allows me to pick points. I want to count the
number of times I have picked points.

global no_picked
no_picked = 0

def picked(object, event):
  no_picked += 1
  print no_picked

Error msg says: UnboundLocalError: local variable 'no_picked'
referenced before assignment
For some reason, no_picked does not increment, but the printing
statement works.

Do you know why?

(I'm actually writing this for a vtkrenderwindowinteractor.)

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


Re: global variable not working inside function. Increment

2009-09-04 Thread Helvin Lui
Wow!!! Thanks a million!! It worked!   = DThanks for the fast reply too!

Helvin

On Sat, Sep 5, 2009 at 11:52 AM, Rami Chowdhury rami.chowdh...@gmail.comwrote:

global no_picked
no_picked = 0

def picked(object, event):
  no_picked += 1
  print no_picked


 In order to be able to affect variables in the global scope, you need to
 declare them global inside the function, and not at the global scope. So
 your code should read:

no_picked = 0

def picked(object, event):
global no_picked
no_picked += 1
print no_picked

 I believe that will work.


 On Fri, 04 Sep 2009 16:43:27 -0700, Helvin helvin...@gmail.com wrote:

  Hi,

 This increment thing is driving me nearly to the nuts-stage.  

 I have a function that allows me to pick points. I want to count the
 number of times I have picked points.

global no_picked
no_picked = 0

def picked(object, event):
  no_picked += 1
  print no_picked

 Error msg says: UnboundLocalError: local variable 'no_picked'
 referenced before assignment
 For some reason, no_picked does not increment, but the printing
 statement works.

 Do you know why?

 (I'm actually writing this for a vtkrenderwindowinteractor.)

 Helvin




 --
 Rami Chowdhury
 Never attribute to malice that which can be attributed to stupidity --
 Hanlon's Razor
 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)




-- 
Helvin

Though the world may promise me more, I'm just made to be filled with the
Lord.
-- 
http://mail.python.org/mailman/listinfo/python-list


Qstrings to Strings

2009-09-02 Thread Helvin
Just wanted to say, to convert qstrings (or integers for that matter)
to strings, use the str() function.

http://learnwithhelvin.blogspot.com/2009/09/qstrings-and-strings.html
-- 
http://mail.python.org/mailman/listinfo/python-list


string find mystery

2009-09-02 Thread Helvin
Hi,

I have come across this very strange behaviour. Check this code:

if file_str.find('Geometry'):
#if file_str.endswith('Data_Input_Geometry.txt'):
print 'I found geometry'
elif file_str.find('Material'):
print 'I found material'
The amazing thing is when file_str  = 'C:\Qt\SimLCM\Default
\Data_Input_Material.txt',
the first if statement if fulfilled, that seemingly says that in this
file_str, python actually finds the word 'Geometry'.
I know this, because the line: 'I found geometry' is printed. However,
if instead of using file_str.find(), I use file_str.endswith(), it
does not exhibit this strange behaviour.

Obviously, I want the elif line to be true, instead of the first if
statement.

Does anyone know why this is happening?
Help much appreciated!

Very puzzled,
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string find mystery

2009-09-02 Thread Helvin Lui
Thanks!  I just realised that too, but I used the condition:.find()  0 But
I think your's is better.
Simple programming knowledge...   
I made a blog post:
http://learnwithhelvin.blogspot.com/2009/09/1-is-true-if-loops.html

http://learnwithhelvin.blogspot.com/2009/09/1-is-true-if-loops.html

On Thu, Sep 3, 2009 at 5:19 PM, Stephen Hansen apt.shan...@gmail.comwrote:

 The amazing thing is when file_str  = 'C:\Qt\SimLCM\Default
 \Data_Input_Material.txt',
 the first if statement if fulfilled, that seemingly says that in this
 file_str, python actually finds the word 'Geometry'.
 I know this, because the line: 'I found geometry' is printed. However,
 if instead of using file_str.find(), I use file_str.endswith(), it
 does not exhibit this strange behaviour.


 The problem is str.find returns -1 on failure; and -1 is a true value. Only
 0, empty string, empty sequences, etc, are false values.

 So, you have to test, 'if find_str.find(pattern) != -1:'

 HTH,

 --S




-- 
Helvin

Though the world may promise me more, I'm just made to be filled with the
Lord.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt GUI

2009-09-01 Thread Helvin
Having left my problem with this embedding vtk business for a month, I
came back to it yesterday, and with a bit more programming knowledge,
found that my problem was simply with the python path. All I needed to
do was to append, in my GUI file,  the path to the python bindings,
which came with the source. I have blogged in more detail here:

http://learnwithhelvin.blogspot.com/2009/09/embedding-vtk-into-pyqt-gui.

My VTK stuff are now displayed in my GUI!  =D
Welcome to ask, if my blog is not detailed enough. I just wasn't
bothered to put my entire file on there.

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


Search and write to .txt file

2009-08-11 Thread Helvin
Hi everyone,

I am writing some python script that should find a line which contains
'1' in the data.txt file, then be able to move a certain number of
lines down, before replacing a line. At the moment, I am able to find
the line '1', but when I use f.seek to move, and then rewrite, what I
write goes to the end of the .txt file, instead of being adjusted by
my f.seek.

Do you know what way I should take?

Data.txt is a file of 3 lines:
   line1
   line2
   line3

Code:

   with open('data.txt', 'r+') as f:
   firstread = f.readlines()   # Take a snapshot of initial file

   f.seek(0,0)# Go back to beginning and search
   for line in f:
   print line
   if line.find('1'):
   print 'line matched'
   f.seek(1,1)   # Move one space along
   f.write('house\n') # f.write overwrites the exact
number of bytes.
   break# leave loop once '1' is found

   f.seek(0,0)  # Go back to beginning, and read
data.txt again
   lastread = f.readlines()

   print 'firstread is', firstread
   print 'lastread is', lastread

This shouldn't be too difficult, but I don't know how.  
Help appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt GUI

2009-07-26 Thread Helvin
On Jul 24, 5:03 am, Robert Kern robert.k...@gmail.com wrote:
 On 2009-07-23 03:55, Helvin wrote:

  I believe I now have vtkpython.exe. However, my 'import vtk' statement
  in my python code is not working. The error says something like no
  module named vtk.
  Where do I find modules for vtk inpyqt? Do they exist?

 There are no VTK modules inPyQtitself. ThePyQtsupport is in the vtk package
 which can be built with VTK itself. You will need to install VTK and the vtk
 package correctly in order to achieve this. vtkpython.exe is not going to help
 you. Ignore it. After you have built VTK, you need to do an extra step to
 install the vtk package to where your Python interpreter will be able to find 
 it.

 Let's say that your build directory is c:\vtkbuild.

    cd \vtkbuild\Wrapping\Python
    python setup.py install
    cd \

 Now you should be able to import vtk from your normal Python interpreter. If 
 you
 are still having problems, you will need to copy-and-paste exactly what you 
 did
 and what error messages you got. Do not paraphrase error messages.

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
    -- Umberto Eco

Hi Robert,

I realised that vtkpython.exe works, if I drag and drop my .py file on
it. Ie, running my .py file using vtkpython.exe
But my python interpreter does not work with the python file. I have
tried what you suggested.
Below is what I typed in command line, as well as the error that it
produces.

C:\Qt\VTKbin7\Wrapping\Pythonpython setup.py install
Traceback (most recent call last):
  File setup.py, line 138, in module
raise ERROR: Must specify BUILD_TYPE=config-name on command
line.
TypeError: exceptions must be classes or instances, not str

Is it just a small error with input format or something?

Thanks so much!
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt GUI

2009-07-23 Thread Helvin
I believe I now have vtkpython.exe. However, my 'import vtk' statement
in my python code is not working. The error says something like no
module named vtk.
Where do I find modules for vtk in pyqt? Do they exist?

They must, right? Because there are people using vtk in pyqt? Or do I
have to use OpenGL?

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


Re: PyQt GUI

2009-07-09 Thread Helvin
On Jul 9, 11:29 am, Robert Kern robert.k...@gmail.com wrote:
 On 2009-07-08 18:10, Helvin wrote:

  Thanks for the fast replies! I will look into how to use VTK now.
  Where would I find VTK's explicit support for PyQt?

 Wrapping/Python/vtk/qt4/ in the VTK sources.

  Because I have installed VTK (using its installer) and pyVTK (using
  its setup.py file), but how do I actually use it in my code? According
  to:http://www.nabble.com/embedded-VTK-window-in-PyQt-application-td23521...,
  I have tried 'import vtk', but python can't find the vtk module.

 Then you have not installed VTK's Python bindings correctly. Note that pyVTK 
 is
 just a library for manipulating VTK files. The VTK Python bindings are part of
 VTK's distribution itself. Exactly how did you install VTK? Did you compile it
 yourself?

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
    -- Umberto Eco

You mean, when I download VTK, the VTK Python bindings come with it?
I downloaded VTK from:http://vtk.org/files/release/5.4/

I downloaded pyVTK from: http://pypi.python.org/pypi/PyVTK/0.4.67
And then installed it by the command 'python setup.py install'
according to: http://cens.ioc.ee/projects/pyvtk/
I understand that this command runs the file called 'setup.py' that
came with the pyVTK download.

Thanks so much for your help! I am very desperate now...

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


Re: PyQt GUI

2009-07-09 Thread Helvin
On Jul 9, 6:27 pm, Helvin helvin...@gmail.com wrote:
 On Jul 9, 11:29 am, Robert Kern robert.k...@gmail.com wrote:





  On 2009-07-08 18:10, Helvin wrote:

   Thanks for the fast replies! I will look into how to use VTK now.
   Where would I find VTK's explicit support for PyQt?

  Wrapping/Python/vtk/qt4/ in the VTK sources.

   Because I have installed VTK (using its installer) and pyVTK (using
   its setup.py file), but how do I actually use it in my code? According
   to:http://www.nabble.com/embedded-VTK-window-in-PyQt-application-td23521...,
   I have tried 'import vtk', but python can't find the vtk module.

  Then you have not installed VTK's Python bindings correctly. Note that 
  pyVTK is
  just a library for manipulating VTK files. The VTK Python bindings are part 
  of
  VTK's distribution itself. Exactly how did you install VTK? Did you compile 
  it
  yourself?

  --
  Robert Kern

  I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it 
  had
    an underlying truth.
     -- Umberto Eco

 You mean, when I download VTK, the VTK Python bindings come with it?
 I downloaded VTK from:http://vtk.org/files/release/5.4/

 I downloaded pyVTK from:http://pypi.python.org/pypi/PyVTK/0.4.67
 And then installed it by the command 'python setup.py install'
 according to:http://cens.ioc.ee/projects/pyvtk/
 I understand that this command runs the file called 'setup.py' that
 came with the pyVTK download.

 Thanks so much for your help! I am very desperate now...

 Helvin

I googled: vtk for beginners python.
From there, I found this: 
http://www.nabble.com/pls-help-how-to-install-VTK-and-run-td14977428.html
And from there, this: 
http://www-viz.tamu.edu/courses/viza658/08spring/tutorials/WinVTKInstall.html

This last one has very detailed info about how to get started with
VTK. I am now redoing the installing VTK thing. Hope it will work.

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


Re: PyQt GUI

2009-07-09 Thread Helvin
On Jul 10, 3:54 am, Robert Kern robert.k...@gmail.com wrote:
 On 2009-07-09 01:27, Helvin wrote:





  On Jul 9, 11:29 am, Robert Kernrobert.k...@gmail.com  wrote:
  On 2009-07-08 18:10, Helvin wrote:

  Thanks for the fast replies! I will look into how to use VTK now.
  Where would I find VTK's explicit support for PyQt?
  Wrapping/Python/vtk/qt4/ in the VTK sources.

  Because I have installed VTK (using its installer) and pyVTK (using
  its setup.py file), but how do I actually use it in my code? According
  to:http://www.nabble.com/embedded-VTK-window-in-PyQt-application-td23521...,
  I have tried 'import vtk', but python can't find the vtk module.
  Then you have not installed VTK's Python bindings correctly. Note that 
  pyVTK is
  just a library for manipulating VTK files. The VTK Python bindings are 
  part of
  VTK's distribution itself. Exactly how did you install VTK? Did you 
  compile it
  yourself?

  You mean, when I download VTK, the VTK Python bindings come with it?
  I downloaded VTK from:http://vtk.org/files/release/5.4/

 Exactly which file did you download? I don't think the vtk-5.4.x-win32.exe
 installers have the Python bindings. You will need to build VTK from sources.

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
    -- Umberto Eco

Yes, I think you are right. I did initially use the windows installer.
I didn't know that it did't have python bindings. I thought that if I
had pyVTK, then it would work. But it didn't. I am now building VTK
with sources according to this EXCELLENT tutorial that I have somehow
come across, at:
http://www-viz.tamu.edu/courses/viza658/08spring/tutorials/WinVTKInstall.html

It's for Windows XP, and I am on Vista, but I hope it will work. I
have worked my way through most of it now.

Thanks Robert!
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQt GUI

2009-07-08 Thread Helvin
Hi experts!

I'm developing a GUI for a software using PyQT, and need 3D
visualization. Should I use PyOpenGL or VTK?
I understand that the PyQt package comes with a opengl module. What
else would I need? I think I need to download opengl. but how? where?
I have VTK and pyVTK installed, but I don't know how to use it in my
code, as when I run it, an error says it can't find the vtk module.

Help would be so appreciated!
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt GUI

2009-07-08 Thread Helvin
On Jul 8, 9:23 pm, Phil Thompson p...@riverbankcomputing.com wrote:
 On Wed, 08 Jul 2009 11:11:51 +0200, Diez B. Roggisch
 de...@nospam.web.de
 wrote:





  Helvin wrote:

  Hi experts!

  I'm developing a GUI for a software using PyQT, and need 3D
  visualization. Should I use PyOpenGL or VTK?
  I understand that the PyQt package comes with a opengl module. What
  else would I need? I think I need to download opengl. but how? where?
  I have VTK and pyVTK installed, but I don't know how to use it in my
  code, as when I run it, an error says it can't find the vtk module.

  VTK won't mix with Qt. And I don't think you need to download opengl - it
  either comes with your system (or gfx-drivers), or not. I'm not sure if
 Qt
  actually wraps the OpenGL api itself, AFAIK it doesn't, so you need
  PyOpenGL I guess.

 VTK has explicit support for both Qt (ie. via C++) and PyQt.

 Phil

Thanks for the fast replies! I will look into how to use VTK now.
Where would I find VTK's explicit support for PyQt?

Because I have installed VTK (using its installer) and pyVTK (using
its setup.py file), but how do I actually use it in my code? According
to: 
http://www.nabble.com/embedded-VTK-window-in-PyQt-application-td23521455.html,
I have tried 'import vtk', but python can't find the vtk module.

Thanks a million!
Helvin
-- 
http://mail.python.org/mailman/listinfo/python-list