Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Sequence of Execution

SkepsisSkepsis Posts: 9Member
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 "

Tech.
"
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

Comments

  • infidelinfidel Posts: 2,900Member
    : 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.
    :
    [code]
    : 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 "

    Tech.
    "
    : 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
    [/code]

    From now on, please use the [leftbr]code[rightbr] and [leftbr]/code[rightbr] stylecodes. Especially in Python, it is critical that indentation be maintained. Thank you.

    As far as your problem goes, I'm not sure what to make of it. I doubt it has anything to do with threading. Perhaps the firing of window drawing events is somehow delayed.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • SkepsisSkepsis Posts: 9Member

    : From now on, please use the [leftbr]code[rightbr] and [leftbr]/code[rightbr] stylecodes. Especially in Python, it is critical that indentation be maintained. Thank you.
    :
    : As far as your problem goes, I'm not sure what to make of it. I doubt it has anything to do with threading. Perhaps the firing of window drawing events is somehow delayed.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    :

    ok
    sorry bout the code thing. I was not aware of it

Sign In or Register to comment.