[gnome-builder] doc: add sample plugin example



commit 7c889b509496f072973d28bcc7dee7d0713fa210
Author: Christian Hergert <christian hergert me>
Date:   Thu Sep 3 15:41:19 2015 -0700

    doc: add sample plugin example

 .../plugins/sample-plugin/sample-plugin.plugin     |   28 ++++++
 .../plugins/sample-plugin/sample_plugin.py         |   98 ++++++++++++++++++++
 2 files changed, 126 insertions(+), 0 deletions(-)
---
diff --git a/doc/examples/plugins/sample-plugin/sample-plugin.plugin 
b/doc/examples/plugins/sample-plugin/sample-plugin.plugin
new file mode 100644
index 0000000..02d7622
--- /dev/null
+++ b/doc/examples/plugins/sample-plugin/sample-plugin.plugin
@@ -0,0 +1,28 @@
+[Plugin]
+
+# The plugin loader to use. Currently python3 and omitting this are supported.
+# Omitting the value means the "C" loader, which loads shared libraries. That
+# means you can technically do C/C++/Vala.
+Loader=python3
+
+
+# The module to load. For python3, this means "sample_plugin.py" or
+# "sample_plugin/__init__.py".
+Module=sample_plugin
+
+
+# Some description of the plugin
+Name=A Sample Plugin
+Description=A sample plugin to show how to use Builder plugins
+Authors=Christian Hergert <christian hergert me>
+Copyright=Copyright © 2015 Christian Hergert
+
+
+# The following is required because we only allow builtin plugins now
+Builtin=true
+
+
+# We specified a completion provider in our plugin.
+# Here we need to specify which languages it is active for.
+# The language "ID" comes from GtkSourceView language id.
+X-Completion-Provider-Languages=python,python3
diff --git a/doc/examples/plugins/sample-plugin/sample_plugin.py 
b/doc/examples/plugins/sample-plugin/sample_plugin.py
new file mode 100644
index 0000000..e19644d
--- /dev/null
+++ b/doc/examples/plugins/sample-plugin/sample_plugin.py
@@ -0,0 +1,98 @@
+# This file is public domain.
+
+
+from gi.repository import Builder
+from gi.repository import Ide
+from gi.repository import GObject
+from gi.repository import GtkSource
+
+class ApplicationAddin(GObject.Object, Builder.ApplicationAddin):
+    """
+    This addin class will be loaded once per application.
+    It is loaded when the application loads, or when the plugin is activated.
+    It is common to use an ApplicationAddin for singleton type features.
+    """
+
+    def do_load(self, app):
+        """
+        Perform startup features.
+
+        If using this class as a singleton, you might want to register a
+        class property to access the instance, such as:
+
+        >>> ApplicationAddin.instance = self
+        """
+        print("My addin has loaded!")
+
+    def do_unload(self, app):
+        """
+        Unload routine.
+
+        Possibly cleanup your singleton instance if you did that.
+        >>> ApplicationAddin.instance = None
+        """
+        print("My addin has unloaded")
+
+class WorkbenchAddin(GObject.Object, Builder.WorkbenchAddin):
+    """
+    This addin class will be loaded once per "Project Window".
+
+    The project window is represented by a "Workbench", and it will
+    have exactly one LibIDE context associated with it (found using
+    workbench.props.context property.
+
+    Use this plugin if you need to do something once-per-project window.
+    """
+
+    def do_load(self, workbench):
+        pass
+
+    def do_unload(self, workbench):
+        pass
+
+class EditorViewAddin(GObject.Object, Builder.EditorViewAddin):
+    """
+    This addin will be loaded once for every editor in Builder.
+    If you need to do something that is per-editor, this is the class for you.
+    """
+
+    def do_load(self, editor):
+        pass
+
+    def do_unload(self, editor):
+        pass
+
+class CompletionProvider(Ide.Object, Ide.CompletionProvider):
+    # See GtkSource.CompletionProvider for all the things you can do.
+
+    # NOTE: You must set X-Completion-Provider-Languages in .plugin file!
+
+    def do_populate(self, context):
+        item = GtkSource.CompletionItem(label='Hi', text='Hi')
+        context.add_proposals(self, [item], True)
+
+class SampleDevice(Ide.Device):
+    def __init__(self):
+        self.set_id('my-sample-id')
+        self.set_display_name('Sample Device')
+
+    def do_get_system_type(self):
+        return 'x86_64-linux-gnu'
+
+class DeviceProvider(Ide.Object, Ide.DeviceProvider):
+    """
+    This IdeDeviceProvider interface allows plugins to provide devices to
+    Builder. This will be expanded to support cross-copmiles, deployment, and
+    other hardware specific features.
+    """
+
+    # Settled means we have finished discovering devices.
+    settled = GObject.Property(type=GObject.TYPE_BOOLEAN)
+
+    def __init__(self, *args, **kwargs):
+        device = SampleDevice()
+        self.emit_device_added(device)
+
+        self.settled = True
+        self.notify("settled")
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]