Skip to content

Commit

Permalink
More qgsfunctions
Browse files Browse the repository at this point in the history
Exposed time frame size and type, as well as animation start and end time stamp. Fixes #194
  • Loading branch information
anitagraser committed Jan 14, 2018
1 parent d9e5b88 commit c69c8f3
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions timemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ def initGui(self):
"""Initialize the gui"""
control.load()

def unload(self):
"""Unload the plugin"""
control.unload()
QgsExpression.unregisterFunction("$animation_datetime")
QgsExpression.unregisterFunction("animation_datetime")

def changeI18n(self, new_lang):
"""
Change internationalisation for the plugin.
Expand Down Expand Up @@ -99,8 +93,44 @@ def changeI18n(self, new_lang):
if new_lang != "en":
warn("Translation failed for lang {}, falling back to English".format(new_lang))

def unload(self):
"""Unload the plugin"""
control.unload()
QgsExpression.unregisterFunction("$animation_datetime")
QgsExpression.unregisterFunction("animation_datetime")
QgsExpression.unregisterFunction("$animation_time_frame_size")
QgsExpression.unregisterFunction("animation_time_frame_size")
QgsExpression.unregisterFunction("$animation_time_frame_type")
QgsExpression.unregisterFunction("animation_time_frame_type")
QgsExpression.unregisterFunction("$animation_start_datetime")
QgsExpression.unregisterFunction("animation_start_datetime")
QgsExpression.unregisterFunction("$animation_end_datetime")
QgsExpression.unregisterFunction("animation_end_datetime")

@qgsfunction(0, "TimeManager")
def animation_datetime(values, feature, parent):
"""Called by QGIS to determine the current animation time"""
"""Current animation time"""
return time_util.datetime_to_str(control.getTimeLayerManager().getCurrentTimePosition(),
time_util.DEFAULT_FORMAT)

@qgsfunction(0, "TimeManager")
def animation_time_frame_size(values, feature, parent):
"""Animation time frame size"""
return control.getTimeLayerManager().getTimeFrameSize()

@qgsfunction(0, "TimeManager")
def animation_time_frame_type(values, feature, parent):
"""Unit of time frame, i.e. days, hours, minutes, seconds, ..."""
return control.getTimeLayerManager().getTimeFrameType()

@qgsfunction(0, "TimeManager")
def animation_start_datetime(values, feature, parent):
"""Earliest time stamp"""
return time_util.datetime_to_str(control.getTimeLayerManager().getProjectTimeExtents()[0],
time_util.DEFAULT_FORMAT)

@qgsfunction(0, "TimeManager")
def animation_end_datetime(values, feature, parent):
"""Last time stamp"""
return time_util.datetime_to_str(control.getTimeLayerManager().getProjectTimeExtents()[1],
time_util.DEFAULT_FORMAT)

0 comments on commit c69c8f3

Please sign in to comment.