Open generated files in plugin

Technical questions about Editra, post them here

Open generated files in plugin

Postby weholt » Mon Mar 28, 2011 10:40 pm

I`ve written a plugin for Editra that adds a menu with menuitems that when clicked generates files on disk.

1) I want to open those files in new tabs when the generation of those files are completed.

2) One of my menuitems will create a new folder as well as files. Is it possible to get that folder added automatically to the Project plugin, as a new project, if that plugin is installed?

I`m writing a plugin for django developers so that we can create django projects and django apps from inside Editra. Any relevant information about Editra and Django you might have would be appreciated. Thanks and keep up the good work! :D

Best regards,
Thomas Weholt
weholt
User
 
Posts: 6
Joined: Mon Mar 28, 2011 11:15 am

Re: Open generated files in plugin

Postby cody » Tue Mar 29, 2011 3:04 am

Hi,

Here is one way to open the file:

Code: Select all
app = wx.GetApp()
app.OpenFile(filename)


ref Editra App class api documentation

As for automatically adding the folder to the Projects plugin it doesn't have any interfaces for doing that directly. If the folder is already underneath another existing project it will automatically appear though. A new interface could probably be added as part of an update to the plugin though if you have some requirements defined.

I don't know much of anything about Django but let me know if you have any further questions about writing a plugin and integrating with Editra. I updated the API documentation recently so it may be of help as well, see http://editra.org/documentation

Cody
User avatar
cody
Site Admin
 
Posts: 1312
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: Open generated files in plugin

Postby weholt » Tue Mar 29, 2011 10:06 am

Thanks for the input on how to open files and regarding my requirements for the Project plugin, they`re simple:

1. I need to be able to add a project in code, in my plugin, using a specified directory.

2. It would be nice to be able to easily add a menu entry in the context menu in the project as well. I`d like to be able to set some properties for a project, for instance, when I`m working with django what port the development server will be running at etc. This will be django specific, but a api for adding a menu item to the context menu would make this an easy task and open for alot of other enhancements as well.

I hope to contribute to Editra, mostly by developing plugins, but perhaps also by testing, documenting etc. in the future.

Have a nice day! :-)

Regards,
Thomas
weholt
User
 
Posts: 6
Joined: Mon Mar 28, 2011 11:15 am

Re: Open generated files in plugin

Postby weholt » Tue Mar 29, 2011 11:02 am

One more thing; I need to iterate thru all the notebooks/tabs open in the main window and see the complete filepath for the file open in a given tab. How do I do that?

Thanks again!
weholt
User
 
Posts: 6
Joined: Mon Mar 28, 2011 11:15 am

Re: Open generated files in plugin

Postby cody » Tue Mar 29, 2011 12:10 pm

Hi,

The adding of folders can be done but the Projects plugin is really just a file manager and source control interface so it doesn't have anything like project settings like your thinking with #2.

For getting the file path you need to get a reference to the text buffer

i.e)
Code: Select all
buff = wx.GetApp().GetCurrentBuffer()
fname = buff.GetFileName()


There is a convenience function on the tab control for getting all the filenames if that is what you need to do, it returns a list of file names. The index in the list is the same as the tabs from left to right.

Code: Select all
nb = wx.GetApp().GetActiveWindow().GetNotebook()
files = nb.GetFileNames()


For a specific tab

Code: Select all
buff = nb.GetPage(index)
fname = buff.GetFileName()


Or if you want to iterate through them

Code: Select all
for idx in range(nb.GetPageCount()):
    buff = nb.GetPage(idx)
    fname = buff.GetFileName()
User avatar
cody
Site Admin
 
Posts: 1312
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: Open generated files in plugin

Postby weholt » Tue Mar 29, 2011 7:42 pm

cody wrote:Hi,

Here is one way to open the file:

Code: Select all
app = wx.GetApp()
app.OpenFile(filename)


When I do:

Code: Select all
app = wx.GetApp()
for filename in list of filenames:
    app.OpenFile(filename)


my plugin creates a new instance of Editra for each file instead of adding a new tab and opening the file in that tab. How can I add a tab and open the file in that tab? I`ve looked at the docs but there doesn`t seem to be a function in the API that creates a new tab, just one for openfile.

Thomas
weholt
User
 
Posts: 6
Joined: Mon Mar 28, 2011 11:15 am

Re: Open generated files in plugin

Postby cody » Tue Mar 29, 2011 8:21 pm

Hi,

weholt wrote:my plugin creates a new instance of Editra for each file instead of adding a new tab and opening the file in that tab. How can I add a tab and open the file in that tab? I`ve looked at the docs but there doesn`t seem to be a function in the API that creates a new tab, just one for openfile.

Thomas


Check your user preferences in the Preferences dialog. You probably have the "Open files in new windows by default" option checked (Preferences->General->Files).

You can also open it directly with the notebook object

EdPages Api Documentation

Though this is not suggested as it will skip around user preferences on how they want to open files.

There are many examples in other plugins as well, see the filebrowers, projects, launch plugin code. They all open files in the buffer based on user actions.


Cody
User avatar
cody
Site Admin
 
Posts: 1312
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: Open generated files in plugin

Postby weholt » Tue Mar 29, 2011 10:30 pm

My plugin is now working ok. It`s available at https://bitbucket.org/weholt/editra.djangomanagement. It will feature lots of other features as well, but right now it can create a default django project and a reusable app, all from inside Editra.

I hope to extend the plugin further during the weekend. Thanks for making an editor that just works and is easy to extend.

NB! Any suggestions you might have for improvements, ideas etc are very welcome.

Regards,
Thomas Weholt
weholt
User
 
Posts: 6
Joined: Mon Mar 28, 2011 11:15 am

Re: Open generated files in plugin

Postby cody » Wed Mar 30, 2011 2:00 pm

Hi,

I just took a quick look at the source.

1) You shouldn't (i.e dont) use the old wxPython namespace anymore:

i.e) from wxPython.wx import wxMenu

Just use

Code: Select all
import wx
wx.Menu()


2) A number of interface strings are missing the _() wrapper function around them so they wont be translatable.

Other than that from the source looks fine, looks like it has some dependencies that are not built into the standard python library so I haven't had a chance to try and run it but will try to when I get some time.


Cody
User avatar
cody
Site Admin
 
Posts: 1312
Joined: Mon Oct 09, 2006 2:49 am
Location: United States


Return to Technical Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron