Ninja IDE Documentation: Release 2.3
Ninja IDE Documentation: Release 2.3
Release 2.3
Not me
Contents
Installing NINJA-IDE
1.1 First steps with NINJA-IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1.1
Installation on Mac OS with Homebrew . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Executing NINJA-IDE from source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Plugin Tutorial
2.1 Why do we need plugins on NINJA-IDE?
2.2 Architecture . . . . . . . . . . . . . . .
2.3 How to create plugins . . . . . . . . . .
2.3.1
Plugin Descriptor file . . . . . .
2.3.2
Service locator class . . . . . .
2.3.3
Plugin class . . . . . . . . . . .
Attributes . . . . . . . . . . . . .
PluginLogger . . . . . . . . . . .
Methods . . . . . . . . . . . . .
Example . . . . . . . . . . . . .
2.3.4
Plugins interfaces . . . . . . . .
IProjectTypeHandler . . . . . . .
ISymbolsHandler . . . . . . . . .
IPluginPreferences . . . . . . . .
2.3.5
Services . . . . . . . . . . . . .
editor . . . . . . . . . . . . . . .
toolbar . . . . . . . . . . . . . .
menuApp . . . . . . . . . . . . .
misc . . . . . . . . . . . . . . . .
explorer . . . . . . . . . . . . . .
2.3.6
Testing your plugin . . . . . . .
2.3.7
Debugging your plugin . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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
.
.
.
.
.
.
.
.
.
.
.
.
.
3
3
3
3
5
5
5
5
6
7
7
7
7
7
7
8
8
8
8
9
9
12
14
16
17
21
22
ii
NINJA-IDE (from the recursive acronym: Ninja-IDE Is Not Just Another IDE), is a cross-platform integrated development environment (IDE). NINJA-IDE runs on Linux/X11, Mac OS X and Windows desktop operating systems, and
allows developers to create applications for several purposes using all the tools and utilities of NINJA-IDE, making
the task of writing software easier and more enjoyable.
Contents:
Contents
Contents
CHAPTER 1
Installing NINJA-IDE
Make sure that macfsevents ($ pip install macfsevents) is installed before you install Ninja-IDE.
Or you can get the latest version of the code by downloading this zip:
https://github.com/ninja-ide/ninja-ide/zipball/master
Now you have everything you need to execute NINJA-IDE from source!
Warning: We always try to keep the repository stable, but with the latest code, some kind of new bugs might
appear... The good news is that you can be the first one reporting these kind of things and help us fix it faster.
Ok, so... lets execute NINJA-IDE from source. Go to the ninja-ide folder (the one where you cloned the repository
to, or where you uncompressed the zip file), and just type:
$ python ninja-ide.py
CHAPTER 2
Plugin Tutorial
2.2 Architecture
The image above shows the connection between plugins and NINJA-IDE. Plugins get services by using a service
locator. The service locator returns the specific service and the plugin uses this service to talk with NINJA-IDE.
packages your plugin to share it. You can install**pluginProject** from the Plugin Manager inside NINJA-IDE (Go
to the Plugins menu and choose Manage Plugins).
module: Indicates the name of the module where the plugin class resides, which will be instantiated by NINJAIDE.
class: Indicates the name of the class which implements the plugin.
authors: String with the author(s).
version: Indicates the plugin version.
url: Indicates the url of the plugin (the documentation could be provided here).
description: Plugin description.
6
ISymbolsHandler
This interface is useful if you want to provide symbols for a language distinct of Python.
IPluginPreferences
This interface is useful if you want to add custom preferences for your plugin.
def obtain_symbols(self, source):
"""
Returns the dict needed by the tree
Source code in plain text
"""
2.3.5 Services
Services are the way that plugins talk with NINJA-IDE. Conceptually services are proxies to NINJA-IDE components.
NINJA-IDE defines different components, each one of these has different features.
editor
This service allows to interact with the main parts of NINJA-IDE, such as the editor, the tab manager, listen to signals
which NINJA-IDE emits when saving a file, save project, change the current tab, etc.
Signals
editorKeyPressEvent(QEvent)
Emitted when the user presses a key.
To connect the plugin to this signal use:
SERVICE_NAME = "editor"
editor_service = self.locator.get_service(SERVICE_NAME)
editor_service.editorKeyPressEvent.connect(self._do_something)
def do_something(self, event):
#the code goes here!
beforeFileSaved(fileName)
Emitted before the fileName is saved on disc.
To connect the plugin to this signal use:
SERVICE_NAME = "editor"
editor_service = self.locator.get_service(SERVICE_NAME)
editor_service.beforeFileSaved.connect(self._do_something)
def do_something(self, fileName):
#the code goes here!
fileSaved(fileName)
Emitted when the user saves a file.
To connect the plugin to this signal use:
SERVICE_NAME = "editor"
editor_service = self.locator.get_service(SERVICE_NAME)
editor_service.fileSaved.connect(self._do_something)
def do_something(self, fileName):
#the code goes here!
currentTabChanged(fileName)
Emitted when the user changes the current tab.
To connect the plugin to this signal use:
SERVICE_NAME = "editor"
editor_service = self.locator.get_service(SERVICE_NAME)
editor_service.currentTabChanged.connect(self._do_something)
def do_something(self, fileName):
#the code goes here!
fileExecuted(fileName)
Emitted when the user executes a file.
To connect the plugin to this signal use:
SERVICE_NAME = "editor"
editor_service = self.locator.get_service(SERVICE_NAME)
editor_service.fileExecuted.connect(self._do_something)
def do_something(self, fileName):
#the code goes here!
fileOpened(fileName)
Emitted when the user opens a file
To connect the plugin to this signal use:
SERVICE_NAME = "editor"
editor_service = self.locator.get_service(SERVICE_NAME)
editor_service.fileOpened.connect(self._do_something)
def do_something(self, fileName):
#the code goes here!
Methods
get_tab_manager(self )
This method returns the TabWidget (ninja_ide.gui.main_panel.tab_widget.TabWidget) subclass of QTabWidget.
add_menu(self, menu, lang=.py)
This method adds an extra context menu to the editors context menu (QMenu).
get_opened_documents(self )
This method returns the name of the open file(s).
add_editor(self, fileName=, content=None, syntax=None)
10
11
toolbar
This service allows to interact with the toolbar of NINJA-IDE. The toolbar is an instance of QToolbar, so we can add
actions (QAction) to it.
By default the toolbar of NINJA-IDE looks like the image below:
Methods
add_action(self, action)
12
When this code is added, the toolbar of NINJA-IDE looks like this:
13
14
By default the Plugins Menu of NINJA-IDE looks like the image below:
Methods
add_menu(self, menu)
This method allows to add a menu (QMenu) to the NINJA-IDE plugins menu.
To add one menu to the NINJA-IDE use:
SERVICE_NAME = "menuApp"
menu_service = self.locator.get_service(SERVICE_NAME)
#instantiate a QMenu (or subclass)
one_menu = QMenu(...)
#add the menu to NINJA-IDE
menu_service.add_menu(one_menu)
When this code is added, the Plugins Menu of NINJA-IDE looks like this:
add_action(self, action)
This method allows to add an action (QAction) to the NINJA-IDE plugins menu.
To add one action to NINJA-IDE use:
SERVICE_NAME = "menuApp"
menu_service = self.locator.get_service(SERVICE_NAME)
#instantiate a QAction (or subclass)
one_action = QAction(...)
#add the action to NINJA-IDE
menu_service.add_action(one_action)
When this code is added, the Plugins Menu of NINJA-IDE looks like this:
15
misc
This service allows to interact with the miscellaneous container (misc) of NINJA-IDE. This container is at the bottom
of the user interface. The container has a collection of widgets and shows an icon for each one them. Only one widget
is visible at a time. We can add widgets (QWidget) to the misc container.
By default the Plugins Menu of NINJA-IDE looks like the image below:
The image above shows the misc container, the console and the icons.
Methods
When this code is added, the misc container of NINJA-IDE looks like this:
16
Great! We have added a widget with a QWebView to the misc container of NINJA-IDE.
explorer
This service allows to interact with the NINJA-IDE explorer container which holds the TreeProjectsWidget and the
TreeSymbolsWidget. Before we explain the explorer service, we are going to see some important classes first.
Methods
get_tree_projects(self )
Returns the TreeProjectsWidget.
get_tree_symbols(self )
Returns the TreeSymbolsWidget.
get_current_project_item(self )
Returns the current item of the tree projects (if possible).
self.get_tree_projects().currentItem()
Note:
get_project_item_by_name(self, projectName)
Return a ProjectItem based on the name provided, or None if an item with that name cant be found.
set_symbols_handler(self, file_extension, symbols_handler)
Add a new Symbols handler for the given file extension. Note: symbols_handler SHOULD have a special interface.
See: ninja_ide.core.plugin_interfaces.
Example: If you want to add a new symbols handler for C++, your plugin should include the following code:
SERVICE_NAME = 'explorer'
self.explorer_s = self.locator.get_service(SERVICE_NAME)
cpp_symbols_handler = CppSymbolHandler(...)
self.explorer_s.set_symbols_handler('.cpp', cpp_symbols_handler)
17
Add a new Project Type and the handler for it. Note: project_type_handler SHOULD have a special interface. See:
ninja_ide.core.plugin_interfaces.
Example: If you want to add a custom type of project, your plugin should include the following code:
SERVICE_NAME = 'explorer'
self.explorer_s = self.locator.get_service(SERVICE_NAME)
foo_project_handler = FooProjectHandler(...)
self.explorer_s.set_project_type_handler('Foo Project', foo_project_handler)
Then Foo Project will appear in the New Project wizard and the foo_project_handler instance controls the wizard.
add_tab(self, tab, title)
Add a tab (QTabWidget) with the given title (string).
get_actual_project(self )
Returns the path of the opened projects.
get_opened_projects(self )
Returns a list of strings with the paths of the opened projects, or an empty list if there arent any opened projects.
add_project_menu(self, menu, lang=all)
Add an extra menu(QMenu) to the project explorer for files that are specified by lang. Note: lang is a file extension
such as .php, .py, .cpp. If you want to add an extra menu for any kind of file, you need to specify lang=all.
Example 1: If you want to add an extra menu for Python files, your plugin should include the following code:
SERVICE_NAME = 'explorer'
self.explorer_s = self.locator.get_service(SERVICE_NAME)
extra_menu = MyCustomMenuForPHPFiles()
self.explorer_s.add_project_menu(extra_menu, lang='.php')
Example 2: If you want to add an extra menu for all files, your plugin should include the following code:
SERVICE_NAME = 'explorer'
self.explorer_s = self.locator.get_service(SERVICE_NAME)
extra_menu = MyCustomMenuForPythonFiles()
self.explorer_s.add_project_menu(extra_menu, lang='all')
Signals
projectExecuted(projectPath)
Emitted when the user executes a project.
To connect the plugin to this signal use:
SERVICE_NAME = "explorer"
explorer_service = self.locator.get_service(SERVICE_NAME)
explorer_service.projectExecuted.connect(self._do_something)
def do_something(self, projectPath):
#the code goes here!
projectOpened(projectPath)
Emitted when the user opens a project.
To connect the plugin to this signal use:
18
SERVICE_NAME = "explorer"
explorer_service = self.locator.get_service(SERVICE_NAME)
explorer_service.projectOpened.connect(self._do_something)
def do_something(self, projectPath):
#the code goes here!
TreeProjectsWidget
This class inherits from QTreeWidget and represents a tree with all the NINJA-IDE projects and their content (folders
and files).
ProjectTree
This class inherits from QTreeWidgetItem and is used to represent projects (root of tree).
This class contains general information about the project:
self.path
self.isFolder
self.projectType
self.description
self.url
self.license
19
self.mainFile
self.extensions
self.pythonPath
self.programParams
self.venv
def lang(self)
Returns the programming language of the project.
def get_full_path(self)
Returns the full path of the project.
ProjectItem
This class inherits from QTreeWidgetItem and is used to represent the content of projects (folder and files).
This class contains general information about the file.
self.path: Absolute path to the given item (folder or file).
self.isFolder: Boolean value depending on the item is folder or item.
def get_full_path(self)
Returns the full path of the file.
TreeSymbolsWidget
This class inherits from QTreeWidget and represents the content of a file classes, methods, functions and global
variables. NINJA-IDE only handles symbols for Python files, but we can add handlers for different files.
The TreeSymbolsWidget class looks like this:
20
21
22
Index
add_action(), 12, 15
add_editor(), 10
add_menu(), 10, 15
add_project_menu(), 18
add_tab(), 18
add_widget(), 16
initialize(), 7
insert_text(), 11
B
beforeFileSaved(), 9
J
jump_to_line(), 11
O
open_file(), 11
open_files(), 11
open_image(), 11
currentTabChanged(), 10
projectExecuted(), 18
projectOpened(), 18
editorKeyPressEvent(), 9
F
fileExecuted(), 10
fileOpened(), 10
fileSaved(), 9
finish(), 7
S
save_file(), 11
set_project_type_handler(), 17
set_symbols_handler(), 17
G
get_actual_project(), 18
get_current_project_item(), 17
get_editor(), 11
get_editor_path(), 11
get_file_syntax(), 11
get_lines_count(), 11
get_opened_documents(), 10
get_opened_projects(), 18
get_preferences_widget(), 7
get_project_item_by_name(), 17
get_project_owner(), 11
get_selected_text(), 11
get_tab_manager(), 10
get_text(), 11
get_tree_projects(), 17
get_tree_symbols(), 17
23