Hi again,
I have written a module that clears the Interactive window of Active Python 2.2.2 and it works fine by its self but when I use it as an imported module then the clearing takes place after the rest of the main program has run. I'm using Mellinium at home but on NT at work it works fine.
The call to the module is the first statment after main(): in the calling program, the prog then goes on to extract info from web pages and display it to the Interactive window where upon the Interactive window is cleared.
The 'clear the Intractive window' prog does this by finding PythonWin window then using the keybd_event a few times, switches to the Interactive window, highlights all and deletes it as if you used the keys to do it
CTRL+I , CTRL+A and CTRL+X.
Is it something to do with threads? Im at a loss as I was for the file atributes ( that now works a treat - thanks)
THANKS in advance for any insight or where to start looking.
I'm really getting to like Python after a couple of weeks of frustration. Still needs more examples for everything.
Here are the programs first the HTML prog.
This could be any prog tho. I have taken out code that just makes the post long.
import urllib
import string
import clearInteractive
def getheadline(htmlRef):
start = fini = -1
theLine = ""
sock = urllib.urlopen(htmlRef)
htmlSource = sock.readlines()
sock.close()
for x in htmlSource:
~~~~ code to strip out unwanted stuff
print "one done"
def main():
clearInteractive.clearWin()
print "\n\nTech.\n"
htmlRef = "http://uk.news.yahoo.com/22" #tech
getheadline(htmlRef)
if __name__ == "__main__":
main()
and the clear win prog:
from win32gui import EnumWindows
from win32gui import SetActiveWindow
from win32gui import GetWindowText
from win32api import keybd_event
def EnumCallback( hwnd, extra ):
extra.append(hwnd)
def clearWin():
windows = []
wintexts = []
EnumWindows(EnumCallback, windows)
for each in windows:
wintexts.append(GetWindowText(each))
try:
SetActiveWindow(windows[wintexts.index("PythonWin")])
#move to the Interactive Window
keybd_event(18,1,1,0)
keybd_event(ord('I'),1,1,0)
keybd_event(ord('I'),1,-1,0)
keybd_event(18,1,-1,0)
~~~ code to Clear the Interactive window screen
except ValueError:
pass