Re: [Tutor] getting a wx.gauge to close!

2009-12-31 Thread Alan Gauld


"Pirritano, Matthew"  wrote 

I have got a wx.gauge running and I cannot get it to go away!  
Any quick and dirty ideas or do you need my ugly syntax. I'm a newbie!


I've no idea what you've done but guages don't normally go away. 
The window/dialog they are in sometimes goes away, but without knowing 
how you have constructed your GUI for the guage, what events it 
is monitoring etc it is impossible to give you any real advice.



--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] printing xps or gif

2009-12-31 Thread Rayon
Can I use python to print xps or gif.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using re to match text and extract info

2009-12-31 Thread Norman Khine
hello,

>>> import re
>>> line = "ALSACE 67000 Strasbourg 24 rue de la Division Leclerc 03 88 23 05 
>>> 66 strasbo...@artisansdumonde.org"
>>> m = re.search('[\w\-][\w\-\...@[\w\-][\w\-\.]+[a-za-z]{1,4}', line)
>>> emailAddress .search(r"(\d+)", line)
>>> phoneNumber = re.compile(r'(\d{2}) (\d{2}) (\d{2}) (\d{2}) (\d{2})')
>>> phoneNumber.search(line)

but this jumbles the phone number and also includes the 67000.

how can i split the 'line' into a list?

thanks
norman
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] try and except

2009-12-31 Thread Dave Angel

spir wrote:

Lie Ryan dixit:

  

class Error(Exception):
 def __init__(self, value):
 self.value = value
 def printer(self, value):
 print self.value



You can also use __str__ instead of printer. This will give a standard output 
form for your error automatically used by print and also, for exceptions, when 
python writes it to stderr: you don't need to catch the error to write it 
yourself.

 def __str_(self, value):
 print self.value

  
The __str__() method needs to return a string, not print it.  And it 
doesn't take a "value" argument.  I think you want (untested):


  def __str__(self):
return self.value

So that a test case may be (untested):

def oops():
 raise Error('some error')

def domoed(catch_error_and_go_on = False):
if catch_error_and_go_on:
try:
oops()
except Error, e:
print e # just for feedback
else:
print 'no error'
else:
oops()  # will print error
if __name__ == "__main__":
 print "=== case error uncatched"
 domoed()
 print "\n=== case error catched"
 domoed(true)


Denis


la vita e estrany

http://spir.wikidot.com/

  

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting a wx.gauge to close!

2009-12-31 Thread Pirritano, Matthew
Alan,

Thanks for the reply. I was hoping there might be a quick fix, and it is
really a wx.Frame, that contains the wx.gauge.

Here's the story. I'm using SPSS. I have written this program to create
a list of doctors from medical claims data to be used in another module
where I have set up check boxes that trigger an analysis to be run for
whatever doctor's box is checked. The program is running with the SPSS
Python-Integration Package, and is running externally, not in SPSS. I
just needed some indicator that the process was running because it can
take a long time (15, 20, or 30 minutes, depending on the size of the
claims file which can be more than 4gb).

Okay, here's the syntax. Please excuse any sloppiness in my form. I'm
just 
learning. 

I really appreciate the help! 


# Module:   lice.py
# Author:   Matthew Pirritano
# Date: 2009/12/15
# Version:  Draft 0.1
'''
Create a list of providers for drop down to select for further analyses
'''
###
# Log:
# 2009/12/15MP - File created
# 


# Ask the user to select the AMM  file they would like to use
import wx, os, spss, sys, thread


class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title,
  pos=(350, 150), size=(250, 150))

# Create the menubar
menuBar = wx.MenuBar()

# and a menu 
menu = wx.Menu()

# Now create the Panel to put the other controls on.
panel = wx.Panel(self)

# and a few controls
text = wx.StaticText(panel, -1, "I'm working on it!!!")
text.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
text.SetSize(text.GetBestSize())
btn = wx.Button(panel, -1, "Close", (10,30))

self.count = 0
 
self.g2 = wx.Gauge(panel, -1 , 50, (50, 60), (125, 25))

self.Bind(wx.EVT_END_PROCESS, self.on_end_process)
self.Bind(wx.EVT_TIMER, self.TimerHandler)
self.timer = wx.Timer(self)
self.timer.Start(100)

# bind the button events to handlers
self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)

# Use a sizer to layout the controls, stacked vertically and
with
# a 10 pixel border around each
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(text, 0, wx.ALL, 10)
panel.SetSizer(sizer)
panel.Layout()
  
self.chooserThread()

def chooserThread(self):
thread.start_new_thread(self.chooser,())


def OnTimeToClose(self, evt):
"""Event handler for the button click."""
print "See ya later!"
self.Close()

def TimerHandler(self, event):
self.count = self.count + 1

if self.count >= 50:
self.count = 0

self.g2.Pulse()

def on_end_process(self):
self.Frame.Destroy()
self.kill()
app.Destroy()
self.g2.Destroy
self.__init__(None,-1)

def onProvlistDone(self):

self.gauge.abort
self.Close
self.kill

def chooser(self): 

app = wx.PySimpleApp()

self.infile = ''
fileWildcard = "sav files (*.sav)|*.sav|" \
"All files (*.*)|*.*"
dlg = wx.FileDialog(None,
message="Choose the file to derive list
from...",
defaultDir="d:/data/",
defaultFile="",
wildcard=fileWildcard,
style=wx.OPEN| wx.MULTIPLE | wx.CHANGE_DIR
)

if dlg.ShowModal() == wx.ID_OK:
self.infile = dlg.GetPath()
else:
self.infile = None
 
dlg.Destroy()
self.on_end_process
app.Destroy()
thread.start_new_thread(self.provlist,())

  

def getfile(self):
return self.infile

   
def provlist(self):
spss.Submit(r"""
GET FILE= '%s'.
save outfile = '%s'
/compressed.
get file = '%s'.
SORT CASES BY license2.
AGGREGATE
  /OUTFILE='D:\Data\AMM\providers\list.sav'
  /PRESORTED
  /BREAK=license2
  /N_BREAK=N.
get file = 'D:\Data\AMM\providers\list.sav'.
delete variables N_BREAK.
""" % (self.infile, self.infile, self.infile))
   

i = [0]
dataCursor=spss.Cursor(i)
oneVar=dataCursor.fetchall()
dataCursor.close()
uniqueCount=len(set(oneVar))
licenses =[]
i = [0]
for i in range(uniqueCount):
 licenses.append(oneVar[i][:1][0])
print licenses
self.getfile
print self.infile
self.on_end_process()
 

if __name__ == "__main__":
app = wx.PyS

Re: [Tutor] extracting informations (images and text) from a PDF and creating a database from it

2009-12-31 Thread Kent Johnson
On Tue, Dec 29, 2009 at 2:33 AM, Shashwat Anand
 wrote:
> I need to make a database from some PDFs. I need to extract logos as well as
> the information (i.e. name,address) beneath the logo and fill it up in
> database.

Here is a commercial solution:
http://www.addtoit.com

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using re to match text and extract info

2009-12-31 Thread Emmanuel Ruellan
What's wrong with the phone number?

>>> phoneNumber.search(line).groups()
('03', '88', '23', '05', '66')

This looks fine to me.

Here is a regex that splits the line into several named groups. Test it with
other strings, though

>>> line = "ALSACE 67000 Strasbourg 24 rue de la Division Leclerc 03 88 23
05 66 strasbo...@artisansdumonde.org"

>>> details_re =
re.compile(r'(?P^\D+)(?P\d+)\s+(?P[\D\s]+)(?P.+?)(?P\d{2}
\d{2} \d{2} \d{2}
\d{2})\s+(?P[\w\-][\w\-\...@[\w\-][\w\-\.]+[a-za-z]{1,4})')

>>> m = details_re.search(line)

>>> print m.groups()
('ALSACE ', '67000', 'Strasbourg ', '24 rue de la Division Leclerc ', '03 88
23 05 66', 'strasbo...@artisansdumonde.org')

>>> print m.group('phone')
03 88 23 05 66

>>> print m.group('email')
strasbo...@artisansdumonde.org


Emmanuel


On Thu, Dec 31, 2009 at 2:49 PM, Norman Khine  wrote:

>
>
> hello,
>
> >>> import re
> >>> line = "ALSACE 67000 Strasbourg 24 rue de la Division Leclerc 03 88 23
> 05 66 strasbo...@artisansdumonde.org"
> >>> m = re.search('[\w\-][\w\-\...@[\w\-][\w\-\.]+[a-za-z]{1,4}', line)
> >>> emailAddress .search(r"(\d+)", line)
> >>> phoneNumber = re.compile(r'(\d{2}) (\d{2}) (\d{2}) (\d{2}) (\d{2})')
> >>> phoneNumber.search(line)
>
> but this jumbles the phone number and also includes the 67000.
>
> how can i split the 'line' into a list?
>
> thanks
> norman
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing xps or gif

2009-12-31 Thread Alan Gauld


"Rayon"  wrote 


Can I use python to print xps or gif.


Yes.

But how you do it depends on the context of what you are doing.
Care to expound?

Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using re to match text and extract info

2009-12-31 Thread Dave Angel

Norman Khine wrote:

hello,

  

import re
line = "ALSACE 67000 Strasbourg 24 rue de la Division Leclerc 03 88 23 05 66 
strasbo...@artisansdumonde.org"
m = re.search('[\w\-][\w\-\...@[\w\-][\w\-\.]+[a-za-z]{1,4}', line)
emailAddress .search(r"(\d+)", line)
phoneNumber = re.compile(r'(\d{2}) (\d{2}) (\d{2}) (\d{2}) (\d{2})')
phoneNumber.search(line)



but this jumbles the phone number and also includes the 67000.

how can i split the 'line' into a list?

thanks
norman

  

lst = line.split()will split the line strictly by whitespace.

Before you can write code to parse a line, you have to know for sure the 
syntax of that line.  This particular one has 15 fields, delimited by 
spaces.  So you can parse it with str.split(), and use slices to get the 
particular set of numbers representing the phone number.  (elements 9-14)


If the address portion might be a variable number of words, then you 
could still use split and slice, but use negative slice parameters to 
get the phone number relative to the end. (elements -6 to -2)


If the email address might have a space within it, then you have to get 
fancier.


If the phone number might have more or less than 5 "words", you have to 
get fancier.


Without a spec, all the regular expressions in the world are just noise.

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing xps or gif

2009-12-31 Thread ALAN GAULD



> Well I have a folder with some sub folders that have a combo of xps and gif
> files I want to be able to point the program to it and have it print the
> contents of each sub folder.

In that case I'd use os.walk to traverse 
the folders and find the files.

I'd then use os.system() (or the subprocess 
module for more control) and call whatever 
program you would use to print the files 
from the command line.

ghostscript may do it for the xps files, 
for example.

HTH,

Alan G.
http://www.alan-g.me.uk/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor