Text Capture Library COM Server Quick Tutorial - Python Sample

Download the source code for this article: PySample.zip                      More samples...

SUMMARY

This code snippet shows how to use Text Capture Library as a COM server in Python and get list items from desktop window.

SOURCE Text Source


 1 # TextCaptureLib COM library python demo
 2 #
 3 
 4 # Text Capture Library COM python demo
 5 # http://www.skesoft.com
 6 #
 7 
 8 import win32com.client  # http://sourceforge.net/projects/pywin32/
 9 import win32com.client.dynamic
10 
11 from Tkinter import *
12 from time import *
13 
14 class App:
15 
16     def __init__(self, master):
17 
18         frame = Frame(master)
19         frame.pack()
20         self.root = master
21 
22         self.labelMessage = Label(frame, text="Three seconds after you clicked this button, the mouse pointed window will be captured.")
23         self.labelMessage.pack()
24 
25         self.btnCapture = Button(frame, text="Capture It", fg="red", command=self.capture)
26         self.btnCapture.pack()
27 
28         self.textBox = Text(frame)
29         self.textBox.pack()
30 
31         self.btnClear = Button(frame, text="Clear Result", command=self.clear)
32         self.btnClear.pack()
33 
34         self.tcServer = win32com.client.dynamic.Dispatch('TextCaptureLib.TextCapture.1')
35         self.tcWindow = win32com.client.dynamic.Dispatch('TextCaptureLib.Window.1')
36 
37         # Please set your license info
38 
39         #if tcServer.License('Your Name Here', 'Your License Here'):
40         #    #The registered version of Text Capture Library
41         #else:
42         #    #The trial version of Text Capture Library
43 
44 
45     def capture(self):
46         self.clear()
47 
48         self.root.withdraw()
49 
50         sleep(3)
51         self.tcWindow.WindowFromCurrentPos()
52 
53         self.textBox.insert(END, self.tcServer.GetText(self.tcWindow))
54 
55         self.root.update()
56         self.root.deiconify()
57 
58 
59     def clear(self):
60         self.textBox.delete(1.0, END)
61 
62 root = Tk()
63 root.title("Text Capture Library COM python demo")
64 
65 app = App(root)
66 
67 root.mainloop()
 
More samples...