stuck in files!!

C

Chirag B

i want to kno how to link two applications using python for eg:notepad
txt file and some docx file. like i wat to kno how to take path of
those to files and run them simultaneously.like if i type something in
notepad it has to come in wordpad whenever i run that code.
 
T

Thomas Jollans

i want to kno how to link two applications using python for eg:notepad
txt file and some docx file. like i wat to kno how to take path of
those to files and run them simultaneously.like if i type something in
notepad it has to come in wordpad whenever i run that code.

Not possible.

(okay, within certain restrictions it might not be completely impossible)

What are you trying to achieve?
 
A

andrea crotti

2012/7/6 Chirag B said:
i want to kno how to link two applications using python for eg:notepad
txt file and some docx file. like i wat to kno how to take path of
those to files and run them simultaneously.like if i type something in
notepad it has to come in wordpad whenever i run that code.

I don't think that "I want to know" ever lead to some useful answers,
it would be not polite even if
people were actually paid to answer ;)

Anyway it's quite an application-os specific question, probably not
very easy either..
 
A

Alex

Chirag said:
i want to kno how to link two applications using python for eg:notepad
txt file and some docx file. like i wat to kno how to take path of
those to files and run them simultaneously.like if i type something in
notepad it has to come in wordpad whenever i run that code.

Text and docx files are not "applications"; you don't "run" them. You
can "open" them with applications like Notepad or Microsoft Word, and
you can open two files simultaneously in two different applications (or
in two windows within the same application).

Other than that, I don't understand what you mean by "link" them or
what it means for something typed in Notepad to "come in wordpad."
 
C

Chris Angelico

Text and docx files are not "applications"; you don't "run" them. You
can "open" them with applications like Notepad or Microsoft Word, and
you can open two files simultaneously in two different applications (or
in two windows within the same application).

Other than that, I don't understand what you mean by "link" them or
what it means for something typed in Notepad to "come in wordpad."

The nearest I can think of has nothing to do with Python, but all to
do with the applications concerned: DDE. Back in the early 90s it was
a much-touted technology on OS/2 - you could fire up Mesa
(spreadsheet), hotlink a particular group of cells to a table in
DeScribe, edit one and see the other change instantly. It was pretty
cool for its day.

How you'd go about implementing it today I don't know, but there's a
few options available. Really depends on what the OP actually wants to
achieve: Duplicate typing, shared text, simultaneous editing?

ChrisA
 
A

alex23

i want to kno how to link two applications using python for eg:notepad
txt file and some docx file. like i wat to kno how to take path of
those to files and run them simultaneously.like if i type something in
notepad it has to come in wordpad whenever i run that code.

Here's an approach that opens Notepad & Word, then monitors Notepad
for any changes, updating the open Word document when they occur. This
hasn't been tested in any great depth, and I wouldn't run it anywhere
with existing instances of Notepad or Word open without testing what
happens first, but it should get you started.

For the most part this uses standard library files, although I did go
with WinGuiAuto as a quick and dirty wrapper around the win32gui
complexity. If you don't want to introduce it as a dependency, you can
extract the functionality you need: http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html

import os
import time
from win32com.client import Dispatch
from winguiauto import (
findTopWindow,
findControl,
getEditText,
WinGuiAutoError
)

# conditional for main loop
def window_is_open(hwnd):
try:
findTopWindow(selectionFunction=lambda ohwnd: hwnd ==
ohwnd)
return True
except WinGuiAutoError:
return False

# start Notepad
os.system('start notepad')
time.sleep(0.1) # give it time to open or we don't get the handleW
npad = findTopWindow(wantedText='Untitled - Notepad')
ndoc = findControl(npad, wantedClass='Edit') # edit control for
Notepad

# start Word
word = Dispatch("Word.Application")
word.Visible = True
wdoc = word.Documents.Add() # edit control (new document) for Word

# update Word when Notepad changes
MEMORY = None
while window_is_open(npad):
ntxt = getEditText(ndoc)
if ntxt != MEMORY:
wdoc.Content.Text = os.linesep.join(ntxt)
MEMORY = ntxt
time.sleep(1)

wdoc.Close() # opens a save dialogue
wdoc.Quit()

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top