roam-qgis / Roam

Simple data collection built using QGIS.
http://roam-docs.readthedocs.org/en/latest/
GNU General Public License v2.0
169 stars 62 forks source link

Plugin model #116

Closed NathanW2 closed 9 years ago

NathanW2 commented 10 years ago

It would be pretty handy to have a plugin model for Roam that allows for new side panels and tools. This would allow the main product to stay focused on basic easy to use core project and others to add what they need on the side with ease.

Current ideas for plugins:

Other ideas welcome.

Having new Github repo for the Roam-Contrib might also also be good to stop bloat of the main code repo.

Some of the code might need to be refactored to support this kind of model.

HeatherHillers commented 10 years ago

This is perfect for the report button. I love it.

Report button is pretty independent of the canvas. Maybe when we think about plugins we may want to also think about plugins whose use case starts with feature selection, and whether that fits in the same design as feature independent plugins. -- we might could move the idea of custom forms and custom save to a plugin model as well.

Is it also maybe time to have a roam user forum outside the github issue tracker?

I used roam to teach a school intern about GIS this month. She had lots of fun with it. :)

On 01.05.2014, at 17:58, Nathan Woodrow notifications@github.com wrote:

It would be pretty handy to have a plugin model for Roam that allows for new side panels and tools. This would allow the main product to stay focused on basic easy to use core project and others to add what they need on the side with ease.

Current ideas for plugins:

Survey tools (offset, preset features, etc) Reporting generateion functions Other ideas welcome.

Having new Github repo for the Roam-Contrib might also also be good to stop bloat of the main code repo.

Some of the code might need to be refactored to support this kind of model.

— Reply to this email directly or view it on GitHub.

bzeeb commented 10 years ago

@HeatherHillers Yes we thought it would be a good fit, perhaps remove your pull request #67 and rework it as a plugin when we get there.

SFrav commented 10 years ago

Good idea.

The reporting tab will be a good plug-in to have.

On Fri, May 2, 2014 at 3:58 AM, Nathan Woodrow notifications@github.comwrote:

It would be pretty handy to have a plugin model for Roam that allows for new side panels and tools. This would allow the main product to stay focused on basic easy to use core project and others to add what they need on the side with ease.

Current ideas for plugins:

  • Survey tools (offset, preset features, etc)
  • Reporting generateion functions

Other ideas welcome.

Having new Github repo for the Roam-Contrib might also also be good to stop bloat of the main code repo.

Some of the code might need to be refactored to support this kind of model.

— Reply to this email directly or view it on GitHubhttps://github.com/DMS-Aus/Roam/issues/116 .

HeatherHillers commented 10 years ago

Hallo Ben,

Sorry I didn’t get back to you earlier. I’ve been on the beach. I’ll remove the pull request when I’m back in the office on Tuesday.

Plugins are going to be great!

Heather

On 02.05.2014, at 09:51, Ben Zeeb notifications@github.com wrote:

@HeatherHillers Yes we thought it would be a good fit, perhaps remove your pull request #67 and rework it as a plugin when we get there.

— Reply to this email directly or view it on GitHub.

HeatherHillers commented 10 years ago

@bzeeb pulling the pull request.

NathanW2 commented 10 years ago

Plugin code concept:

@page(title='Reports')
class MyPage(QWidget):
      # Do your stuff here

@mapplugin
class MapPagePlugin():
     def toolbars():
           return [MyToolBar]

@page is just shorthand for

Roam.addPage(MyPage)
HeatherHillers commented 10 years ago

So Mappageplugin has The hooks into the roam Ui and my page has the main code- sounds fine. How the hooks look like in mappageplugin will be interesting.

I'm locked in a fortran project. I hope I will be out of it and back on this very soon.

On 23.05.2014, at 01:52, Nathan Woodrow notifications@github.com wrote:

Plugin code concept:

@page(title='Reports') class MyPage(QWidget):

Do your stuff here

@mapplugin class MapPagePlugin(): def toolbars(): return [MyToolBar] @page is just shorthand for

Roam.addPage(MyPage) — Reply to this email directly or view it on GitHub.

NathanW2 commented 10 years ago

This is what I currently have working

in plugins\test_plugin.py

from roam.api import plugins

@plugins.page(name='TestPlugin', title='Test', icon=":/icons/report", projectpage=True)
class ReportPage(QWidget):
    def __init__(self, api, parent=None):
        super(ReportPage, self).__init__(parent)
        self.api = api
        self.setLayout(QGridLayout())
        self.label = QLabel()
        self.layout().addWidget(self.label)
        RoamEvents.selectionchanged.connect(self.selection_updated)

plugins.page will register the page for creation in Roam once it's loaded. Roam will create the widget when it's ready.

HeatherHillers commented 10 years ago

@NathanW2 Hey, I'm Back from the 7th circle of Fortran legacy. I want to get Roam with my Report widget and the copy branch running on Linux in the next couple weeks. While I'm merging with the latest code, I want to put some time into making ReportWidget more plugin-ish.

So,

NathanW2 commented 10 years ago

@HeatherHillers Hey, welcome back. I think you're the only person that I know that does Fortran ;) I'm sure they will say that about Python one day.

The plugin stuff is currently being worked on in https://github.com/DMS-Aus/Roam/tree/plugins

If you checkout that branch you can have a play with what I have in mind. At the moment plugins are support a projectpage mode which means it will show up in the top area, if it's projectpage=False it will show up down the bottom, something like a extra settings page could be added here. We could add project level plugins however lets get this main bit working first then we can do that.

Just be warned it's still a work in progress but we can evolve it.

Any packages in roam\plugins will be picked up and added. You can register a "page" which is a side panel thingo like this:

This can live in a package or a module inside `\plugins'

from roam.api import plugins

@plugins.page(name='TestPlugin', title='Test', icon=":/icons/report", projectpage=True)
class ReportPage(QWidget):
    def __init__(self, api, parent=None):
        super(ReportPage, self).__init__(parent)
        self.api = api
        self.setLayout(QGridLayout())
        self.label = QLabel()
        self.layout().addWidget(self.label)
        api.events.selectionchanged.connect(self.selection_updated)
        api.events.projectloaded.connect(self.projectloaded)

The events object has stuff you can listen too in order to take action.

Don't do anything too heavy in __init__ for your plugin because it will get called when Roam starts, if you need something heavy you could do it by overriding the showEvent() method.

Your class should just be a QWidget of somekind, so you can just inherit from your custom ui class and good to go.

HeatherHillers commented 10 years ago

@NathanW2 I wish I was the only one I know who does Fortran. Then I could Stop Doing It. Maybe I can make being the only one I know who does Fortran a career Goal. It sounds like a great gig. I'll give the plugin branch a go. Sounds fun!

HeatherHillers commented 10 years ago

Hey, what is the difference between src/plugins, where test_plugin is, and src/roam/plugins, where legend_plugins is?

NathanW2 commented 10 years ago

src/plugins is a folder that will be copied to dist when you build so it will be:

dist/plugins

src/roam/plugins are the core plugins, which are really just me playing with the idea for decoupling the main app.

Your stuff should live in dist/plugins (src/plugins)

On Fri, Jun 13, 2014 at 7:19 PM, Heather Hillers notifications@github.com wrote:

Hey, what is the difference between src/plugins, where test_plugin is, and src/roam/plugins, where legend_plugins is?

— Reply to this email directly or view it on GitHub https://github.com/DMS-Aus/Roam/issues/116#issuecomment-45991406.

HeatherHillers commented 10 years ago

got it.

HeatherHillers commented 10 years ago

Hey, I got my Report widget working as a plugin! And I didn't have to make any changes to the plugins branch to do it, except that test_plugin has a tiny namespace error in init. It's great! Next Thing would be to move plugins to the Project directories for Project specific plugins. or have a way to enable and disable plugins. My plugin is too specific to pull, but I could make the SQL and the titles english and more General and give it in for the wiki, if you like. I'll email you the code for your own perusal.

HeatherHillers commented 10 years ago

@NathanW2

I wasn't sure if I was allowed to send my Project to you the way it is with the data and such, but I converted the generic samplereport from the last pull request, and that's much better for a generic demo Project or as example code for the wiki. It is sitting on branch 4-report-plugin of HeatherHillers/Roam. Thanks again!

NathanW2 commented 10 years ago

@HeatherHillers for plugins I'm thinking we could just have a setting in the project.config to tell it which plugins are enabled.

plugins:
   - report

etc

This means we can keep all in the code in a single place and just manage a list per project.

HeatherHillers commented 10 years ago

Ayup. That sounds great.

On 30.06.2014, at 03:56, Nathan Woodrow notifications@github.com wrote:

@HeatherHillers for plugins I'm thinking we could just have a setting in the project.config to tell it which plugins are enabled.

plugins:

  • report etc

This means we can keep all in the code in a single place and just manage a list per project.

— Reply to this email directly or view it on GitHub.

HeatherHillers commented 10 years ago

Hey, How is the plugin branch doing these days? Anything I can do to help?

NathanW2 commented 9 years ago

Hey, not much, mainly just waiting for me to bring it back up to speed with master. I think I got some merge conflicts last time I did. I should get some time soon.

On Thu, Sep 18, 2014 at 12:14 AM, Heather Hillers notifications@github.com wrote:

Hey, How is the plugin branch doing these days? Anything I can do to help?

— Reply to this email directly or view it on GitHub https://github.com/DMS-Aus/Roam/issues/116#issuecomment-55899351.

HeatherHillers commented 9 years ago

Yeah, it was a bit tricksy. And the testing. Blech. I’m going to the Qgis User Group in Kassel on Friday. I will try to load up my Roam project on my tablet and bring it with for coffee break show and tell. I should also write a tutorial for the wiki for making a custom form and for making a plugin. I have been saying that to myself for a long time, but I should actually do it. It is a week of shoulds.

On 17.09.2014, at 21:29, Nathan Woodrow notifications@github.com wrote:

Hey, not much, mainly just waiting for me to bring it back up to speed with master. I think I got some merge conflicts last time I did. I should get some time soon.

On Thu, Sep 18, 2014 at 12:14 AM, Heather Hillers notifications@github.com wrote:

Hey, How is the plugin branch doing these days? Anything I can do to help?

— Reply to this email directly or view it on GitHub https://github.com/DMS-Aus/Roam/issues/116#issuecomment-55899351.

— Reply to this email directly or view it on GitHub.

HeatherHillers commented 9 years ago

Oh good. Usually when Americans say they have good news it is always followed by bad news. I’m glad Australians don’t do that.
I have a mac at home, so I have to wait until tomorrow to try it (or see if run from source works on my mac…) but I will try it very very very soon.

This is going to be awesome! Thanks!

I was just thinking this weekend that it could be a really comfy happy thing to use Roam to collect data for OSM.

-Heather

On 21.09.2014, at 14:59, Nathan Woodrow notifications@github.com wrote:

@HeatherHillers so I have some good news. There is a new, (better hopefully) plugin model in master.

Keen too see if you like it. It should be a lot cleaner then the old one. Simply make a module with the name plugins\test_plugin.py and follow this example:

from PyQt4.QtGui import QWidget, QGridLayout, QLabel

from roam.api.plugins import Page

def pages(): return [SamplePlugin]

class SamplePlugin(QWidget, Page): title = "Sample Plugin"

def __init__(self, api, parent=None):
    super(LineProfile, self).__init__(parent)
    layout = QGridLayout()
    self.setLayout(layout)
    layout.addWidget(QLabel("Hello World"))

def selection_changed(self, selection):
    print selection.items()

def project_loaded(self, project):
    print project

pages() is now called to get the pages that the plugin exposes. The title, icon, projectpage attributes are defined on the Page class. selection_changed and project_loaded are auto connected for you.

Add:

plugins:

  • test_plugin to the project config to enable the plugin for that project.

Note: All plugins must have the module name, or package name, ending with _plugin

— Reply to this email directly or view it on GitHub.

NathanW2 commented 9 years ago

@HeatherHillers more docs here https://github.com/DMS-Aus/Roam/wiki/Plugins

HeatherHillers commented 9 years ago

Hey Hey Hey! I got my Report plugin working on the new master branch in no time! It is indeed awesome!

NathanW2 commented 9 years ago

Great stuff. On Sep 22, 2014 6:00 PM, "Heather Hillers" notifications@github.com wrote:

Hey Hey Hey! I got my Report plugin working on the new master branch in no time! It is indeed awesome!

— Reply to this email directly or view it on GitHub https://github.com/DMS-Aus/Roam/issues/116#issuecomment-56340442.