How to add a file to a notebook via command line

Can somebody point me to information to build a programm that behaves
like most text editors.

python nameOfProgram.py sampleFile.txt
=> Program start with sampleFile opend OR
     if programm is already running opens the sample File in a new
Tab.

I don't know what to google for, I get mostly entries for optparse,
but not to this specific topic.

Best,
Marco

Hi,

Can somebody point me to information to build a programm that behaves
like most text editors.

python nameOfProgram.py sampleFile.txt
=> Program start with sampleFile opend OR
if programm is already running opens the sample File in a new
Tab.

The wxPython Demo includes "Editra" that might give you some pointers.
The Demo is available here:
Redirecting... (scroll down)

On my Pyhton 2.5 installation the following works:

"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\tools\Editra>python
Editra NEWS"

That pops up an Editra window with the NEWS file opened for editing.

More information about Editra is at http://editra.org

I don't know what to google for, I get mostly entries for optparse,
but not to this specific topic.

Best,
Marco

HTH a little.

Cheers,
Scott.

···

On Sun, Oct 18, 2009 at 10:07 AM, marco@rockiger.com <rockiger@googlemail.com> wrote:

Hi Marco!

marco@rockiger.com schrieb:

Can somebody point me to information to build a programm that behaves
like most text editors.

python nameOfProgram.py sampleFile.txt
=> Program start with sampleFile opend OR
     if programm is already running opens the sample File in a new
Tab.

I don't know what to google for, I get mostly entries for optparse,
but not to this specific topic.

That's not exactly a wxPython specific question. You may have tried
on comp.lang.python.

I wrote an app that behaves like that under Windows.
The program checks via DDE whether another instance is running already.
If that's the case, the filename is sent to the other instance and the
program terminates.

You can have a look at PythonWin how to implement this.
It's in two files:

...\Lib\site-packages\pythonwin\pywin\framework\intpyapp.py
  Methods:
   MakeExistingDDEConnection
   InitDDE
   InitInstance
   OnDDECommand

...\Lib\site-packages\pythonwin\pywin\framework\intpydde.py

Regards,

Dietmar

Dietmar Schwertberger wrote:

marco@rockiger.com schrieb:

Can somebody point me to information to build a programm that behaves
like most text editors.

python nameOfProgram.py sampleFile.txt
=> Program start with sampleFile opend OR
     if programm is already running opens the sample File in a new
Tab.

The program checks via DDE whether another instance is running already.

or use wx.SingleInstanceChecker for a platfrom-nuetral option.

The trick then is how to find the running app, and how to send it a message.

It would be nice to have this built-in to wxPython, but alas, it's not, and there are many ways to do it. Try googling SingleInstanceChecker for discussion of some of the options.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

I found out that this is more complicated than I exspected. So I put
this feature a bit behind.
I too think Editra is a good example, src/ed_ipc.py is the central
file that manages the messaging. I will investigate this later.

Thanks to all.

···

On Oct 19, 6:03 am, Chris Barker <Chris.Bar...@noaa.gov> wrote:

Dietmar Schwertberger wrote:
> ma...@rockiger.com schrieb:
>> Can somebody point me to information to build a programm that behaves
>> like most text editors.

>> python nameOfProgram.py sampleFile.txt
>> => Program start with sampleFile opend OR
>> if programm is already running opens the sample File in a new
>> Tab.
> The program checks via DDE whether another instance is running already.

or use wx.SingleInstanceChecker for a platfrom-nuetral option.

The trick then is how to find the running app, and how to send it a message.

It would be nice to have this built-in to wxPython, but alas, it's not,
and there are many ways to do it. Try googling SingleInstanceChecker for
discussion of some of the options.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Bar...@noaa.gov

Chris Barker schrieb:

Dietmar Schwertberger wrote:

marco@rockiger.com schrieb:

Can somebody point me to information to build a programm that behaves
like most text editors.

python nameOfProgram.py sampleFile.txt
=> Program start with sampleFile opend OR
     if programm is already running opens the sample File in a new
Tab.

The program checks via DDE whether another instance is running already.

or use wx.SingleInstanceChecker for a platfrom-nuetral option.

The trick then is how to find the running app, and how to send it a message.

That's part of the DDE solution.

Regards,

Dietmar

Hi,

I found out that this is more complicated than I exspected. So I put
this feature a bit behind.

If your not expecting any other arguments simplest case is just to use sys.argv

i.e)

if __name__ == '__main__':
     import sys
     app = wx.App(False)
     file_name = sys.argv[1]
     frame = MyFrame()
     frame.doOpen(file_name)
     frame.Show()
     app.MainLoop()

Not so complicated right?

I too think Editra is a good example, src/ed_ipc.py is the central
file that manages the messaging. I will investigate this later.

That is only used for IPC (inner process communication) when a second instance starts up it can send any command line args or other commands over to the currently running instance before exiting.

Cody

···

On Oct 19, 2009, at 1:03 AM, marco@rockiger.com wrote:

I will try this.

Thank you very much.

rg
Marco

···

On Oct 19, 3:44 pm, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

On Oct 19, 2009, at 1:03 AM, ma...@rockiger.com wrote:

> I found out that this is more complicated than I exspected. So I put
> this feature a bit behind.

If your not expecting any other arguments simplest case is just to use
sys.argv

i.e)

if __name__ == '__main__':
import sys
app = wx.App(False)
file_name = sys.argv[1]
frame = MyFrame()
frame.doOpen(file_name)
frame.Show()
app.MainLoop()

Not so complicated right?

> I too think Editra is a good example, src/ed_ipc.py is the central
> file that manages the messaging. I will investigate this later.

That is only used for IPC (inner process communication) when a second
instance starts up it can send any command line args or other commands
over to the currently running instance before exiting.

Cody