Re: [Tutor] Get keyboard input while other program is in focus?

2006-10-16 Thread billburns
[Jack]
> > What commands can I use to have the program know a certain key has
> > been pressed while another program is in focus?

[Luke]
> I think Pygame and TKInter have a capture-all-keys function, but this
> might also prevent the keypresses from actually going to the target
> application.

If you need this to work on Windows - take a look at pyHook:

http://www.cs.unc.edu/Research/assist/developer.shtml

As Luke has stated... it's possible to stop the key presses from reaching their
target application. If you do use pyHook, make sure your functions always return
True (this allows the key press to hit it's destination).

HTH,

Bill

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I find where my program is installed?

2006-09-07 Thread billburns


> way. so I need to tell my program to set the working directory back to the
> installation directory... but where is this?
>

Here's what I do in my py2exe app:

installDir = os.path.dirname(os.path.abspath(sys.argv[0]))

and take a look at this link:

http://www.py2exe.org/index.cgi/WhereAmI

HTH,

Bill
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find multiple lines in a file

2005-11-09 Thread billburns
[Kent wrote]
> > OK, none of my suggestions gets you closer to this...the simplest way is
> > if you can read the whole file into memory. Then you can just replace
> > the strings in place and write it out again. For example:
> >
> > oldPolicies = '''<<
> >  /Policies <<
> >/PageSize 3
> >  >>
> >
> >>> setpagedevice'''
> >
> >
> > newPolicies = 'something completely different'
> >
> > f = open(filename)
> > data = f.read()
> > f.close()
> > data.replace(oldPolicies, newPolicies)
> > f = open(filename, 'w')
> > f.write(data)
> > f.close()

Hi Kent,

I just tested the following code and it works like a champ :-)

filename = r'C:\TEST.ps'

old = '''<<
  /Policies <<
/PageSize 3
  >>
>> setpagedevice'''

new = '''<<
 /EndPage
  {  exch pop
 0 eq
{  gsave
  initmatrix
  save
850 1250 moveto 45 rotate 0 setgray
/Helvetica 25 selectfont (CAUTION - DO NOT SCALE!) true charpath .2
setlinewidth stroke
  restore
  true
  }
 { false }
 ifelse
  } bind
>> setpagedevice'''

f = open(filename)
data = f.read()
f.close()
newData = data.replace(old, new)
f = open(filename, 'w')
f.write(newData)
f.close()

Thanks again for your help!!

Bill
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor