
cree.py用プラグイン
cree.py 用のプラグイン
cree.py のアーキテクチャでは、複数のユーザー定義の位置情報ソースを利用できます。これらのソースはプラグインとして定義され、インストールディレクトリ内の plugins フォルダにコピーすることで cree.py にインストールできます。
他のユーザーと共有したい場合は、新しいプラグインのプルリクエストを作成してください。確認後、リポジトリにマージします。
cree.py のプラグインには少なくとも 3 つのファイルが必要です。
モジュールアーキテクチャは yapsy (http://yapsy.sourceforge.net) の助けを借りて構築されています。
plugin_name.yapsy-plugin ファイルに以下の情報を含めてください。
[Core]
Name = Plugin Name
Module = plugin_name
[Documentation]
Author =
Version =
Website =
Description =
プラグインのロジックを含む Python ファイルです。これは InputPlugin クラスを拡張し、最低限いくつかのメソッドを実装する必要があります。そのため、以下のように定義する必要があります(インラインコメントを参照):
from models.InputPlugin import InputPlugin
class PluginName(InputPlugin):
name="plugin_name"
'''
If your plugin configuration needs to invoke a wizard
(for example for oAuth authorization) this must be set to true
'''
hasWizard=True
def searchForTargets(self, search_term):
'''
Parameters
----------
search_term : str
The search term that the user entered in the New Project wizard. It could be a mail, id,
username, full name, it is the plugin's responsibility to differentiate between
different types if needed
Accepts a string parameter from the user and performs a search in the respective service/source
for identifying possible targets to be included in the process.
Returns a list of dictionaries, one for each identified target or an empty list if no results were
found. The dictionaries need to include the following keys :
target = {'pluginName':'Plugin Name',
'targetUserid' : 'The userid of the target in the service/source',
'targetUsername' : 'The username of the target in the service/source',
'targetPicture' : 'the filename of the profile picture of the target ( profile_pic_targetUserid )',
'targetFullname' : 'The full name of the target'}
'''
your_code_here()
def runConfigWizard(self):
'''
If your plugin's configuration needs a wizard, create it here. You need to save the configuration
values to the plugin's config file before returning.
Access to the plugin configuration file is offered through the
readConfiguration(category) method that is inhereted from from the InputPlugin. This returns a tuple
config,options where
-- config is the ConfigObj file that you can use to save the configuration by
calling it's write() method
-- options is the dictionary containing your configuration category options.
'''
def isConfigured(self):
'''
Returns a tuple. The first element is True or False, depending if the plugin is configured or not. The second
element contains an optional message for the user
'''
def returnLocations(self, target, search_params):
'''
Parameters
----------
target : dict
search_params : dict
Returns a list of location dictionaries (or empty list if no locations were found) for the specified
target using the specified search parameters
Target is a dictionary with information as defined in searchForTargets and search_params is a
dictionary with search parameters that you would have defined as available in your configuration file
(see plugin_name.conf below).
The location dictionary needs to contain the following keys :
loc = {'plugin' : 'twitter'
'context' : 'Context of the location"
'infowindow' : "HTML with information in the location to be shown in the infoWindow on the map"
'date' : 'a datetime.datetime object with information on when the gelocation was created'
'lat' : 'latitude of the location'
'lon' : 'longitude of the location'
'shortName' : 'short name describing the location, empty string if not available'}
'''
プラグインが Python に標準で含まれていない外部モジュールを必要とする場合は、その旨を明示し、可能であれば各プラットフォームでの依存関係のインストール手順をユーザーに提示する必要があります。
このファイルにはすべての設定オプションが含まれ、以下のセクションが必要です(一部またはすべてが空の場合もあります)。
[string_options]
key1 = value
[boolean_options]
key2 = True
key3 = False
[search_string_options]
key4 = some value
[search_boolean_options]
key5 = True
string_options と boolean_options はプラグイン設定ダイアログの設定オプションとして表示されます。
search_string_options と search_boolean_options は新しいプロジェクトウィザードで検索オプションとして使用できます。
値を GUI でマスクする必要がある場合(パスワード、アクセストークンなど)、キーの前に hidden_ を付けると、cree.py が処理します。
設定オプションに GUI でよりユーザーフレンドリーな名前を付けたい場合は、ここでラベルを指定できます。例えば、上記の conf ファイルを参考にすると、plugin_name.labels ファイルは次のようになります。
[labels]
key1 = Label For Key 1
key2 = Label For Key 2
key3 = Label For Key 3
key4 = Label For Key 4
key5 = Label For Key 5
キーにラベルを指定しない場合、そのキーが GUI に表示されます。
上記のすべてのファイルを plugin_name という名前のフォルダにまとめ、そのフォルダをインストール済みアプリケーションの plugins ディレクトリにコピーします。とても簡単です!