Skip to content

Commit 52df59b

Browse files
Initial commit
1 parent f3c3500 commit 52df59b

11 files changed

+696
-0
lines changed

AutoTrack.py

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
AutomaTracks
5+
A QGIS plugin
6+
Automatic tracks with constraint with path point
7+
-------------------
8+
begin : 2018-01-25
9+
git sha : $Format:%H$
10+
copyright : (C) 2018 by Peillet Sébastien
11+
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
"""
23+
from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication, Qt
24+
from PyQt4.QtGui import QAction, QIcon
25+
# Initialize Qt resources from file resources.py
26+
import resources
27+
28+
# Import the code for the DockWidget
29+
from AutoTrack_dockwidget import AutomaTracksDockWidget
30+
import os.path
31+
32+
33+
class AutomaTracks:
34+
"""QGIS Plugin Implementation."""
35+
36+
def __init__(self, iface):
37+
"""Constructor.
38+
39+
:param iface: An interface instance that will be passed to this class
40+
which provides the hook by which you can manipulate the QGIS
41+
application at run time.
42+
:type iface: QgsInterface
43+
"""
44+
# Save reference to the QGIS interface
45+
self.iface = iface
46+
47+
# initialize plugin directory
48+
self.plugin_dir = os.path.dirname(__file__)
49+
50+
# initialize locale
51+
locale = QSettings().value('locale/userLocale')[0:2]
52+
locale_path = os.path.join(
53+
self.plugin_dir,
54+
'i18n',
55+
'AutomaTracks_{}.qm'.format(locale))
56+
57+
if os.path.exists(locale_path):
58+
self.translator = QTranslator()
59+
self.translator.load(locale_path)
60+
61+
if qVersion() > '4.3.3':
62+
QCoreApplication.installTranslator(self.translator)
63+
64+
# Declare instance attributes
65+
self.actions = []
66+
self.menu = self.tr(u'&AutomaTracks')
67+
# TODO: We are going to let the user set this up in a future iteration
68+
self.toolbar = self.iface.addToolBar(u'AutomaTracks')
69+
self.toolbar.setObjectName(u'AutomaTracks')
70+
71+
#print "** INITIALIZING AutomaTracks"
72+
73+
self.pluginIsActive = False
74+
self.dockwidget = None
75+
76+
77+
# noinspection PyMethodMayBeStatic
78+
def tr(self, message):
79+
"""Get the translation for a string using Qt translation API.
80+
81+
We implement this ourselves since we do not inherit QObject.
82+
83+
:param message: String for translation.
84+
:type message: str, QString
85+
86+
:returns: Translated version of message.
87+
:rtype: QString
88+
"""
89+
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
90+
return QCoreApplication.translate('AutomaTracks', message)
91+
92+
93+
def add_action(
94+
self,
95+
icon_path,
96+
text,
97+
callback,
98+
enabled_flag=True,
99+
add_to_menu=True,
100+
add_to_toolbar=True,
101+
status_tip=None,
102+
whats_this=None,
103+
parent=None):
104+
"""Add a toolbar icon to the toolbar.
105+
106+
:param icon_path: Path to the icon for this action. Can be a resource
107+
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
108+
:type icon_path: str
109+
110+
:param text: Text that should be shown in menu items for this action.
111+
:type text: str
112+
113+
:param callback: Function to be called when the action is triggered.
114+
:type callback: function
115+
116+
:param enabled_flag: A flag indicating if the action should be enabled
117+
by default. Defaults to True.
118+
:type enabled_flag: bool
119+
120+
:param add_to_menu: Flag indicating whether the action should also
121+
be added to the menu. Defaults to True.
122+
:type add_to_menu: bool
123+
124+
:param add_to_toolbar: Flag indicating whether the action should also
125+
be added to the toolbar. Defaults to True.
126+
:type add_to_toolbar: bool
127+
128+
:param status_tip: Optional text to show in a popup when mouse pointer
129+
hovers over the action.
130+
:type status_tip: str
131+
132+
:param parent: Parent widget for the new action. Defaults None.
133+
:type parent: QWidget
134+
135+
:param whats_this: Optional text to show in the status bar when the
136+
mouse pointer hovers over the action.
137+
138+
:returns: The action that was created. Note that the action is also
139+
added to self.actions list.
140+
:rtype: QAction
141+
"""
142+
143+
icon = QIcon(icon_path)
144+
action = QAction(icon, text, parent)
145+
action.triggered.connect(callback)
146+
action.setEnabled(enabled_flag)
147+
148+
if status_tip is not None:
149+
action.setStatusTip(status_tip)
150+
151+
if whats_this is not None:
152+
action.setWhatsThis(whats_this)
153+
154+
if add_to_toolbar:
155+
self.toolbar.addAction(action)
156+
157+
if add_to_menu:
158+
self.iface.addPluginToMenu(
159+
self.menu,
160+
action)
161+
162+
self.actions.append(action)
163+
164+
return action
165+
166+
167+
def initGui(self):
168+
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
169+
170+
icon_path = ':/plugins/AutomaTracks/icon.png'
171+
self.add_action(
172+
icon_path,
173+
text=self.tr(u'AutomaTracks'),
174+
callback=self.run,
175+
parent=self.iface.mainWindow())
176+
177+
#--------------------------------------------------------------------------
178+
179+
def onClosePlugin(self):
180+
"""Cleanup necessary items here when plugin dockwidget is closed"""
181+
182+
#print "** CLOSING AutomaTracks"
183+
184+
# disconnects
185+
self.dockwidget.closingPlugin.disconnect(self.onClosePlugin)
186+
187+
# remove this statement if dockwidget is to remain
188+
# for reuse if plugin is reopened
189+
# Commented next statement since it causes QGIS crashe
190+
# when closing the docked window:
191+
# self.dockwidget = None
192+
193+
self.pluginIsActive = False
194+
195+
196+
def unload(self):
197+
"""Removes the plugin menu item and icon from QGIS GUI."""
198+
199+
#print "** UNLOAD AutomaTracks"
200+
201+
for action in self.actions:
202+
self.iface.removePluginMenu(
203+
self.tr(u'&AutomaTracks'),
204+
action)
205+
self.iface.removeToolBarIcon(action)
206+
# remove the toolbar
207+
del self.toolbar
208+
209+
#--------------------------------------------------------------------------
210+
211+
def run(self):
212+
"""Run method that loads and starts the plugin"""
213+
214+
if not self.pluginIsActive:
215+
self.pluginIsActive = True
216+
217+
#print "** STARTING AutomaTracks"
218+
219+
# dockwidget may not exist if:
220+
# first run of plugin
221+
# removed on close (see self.onClosePlugin method)
222+
if self.dockwidget == None:
223+
# Create the dockwidget (after translation) and keep reference
224+
self.dockwidget = AutomaTracksDockWidget()
225+
226+
# connect to provide cleanup on closing of dockwidget
227+
self.dockwidget.closingPlugin.connect(self.onClosePlugin)
228+
229+
# show the dockwidget
230+
# TODO: fix to allow choice of dock location
231+
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
232+
self.dockwidget.show()
233+

AutoTrack_dockwidget.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
AutomaTracksDockWidget
5+
A QGIS plugin
6+
Automatic tracks with constraint with path point
7+
-------------------
8+
begin : 2018-01-25
9+
git sha : $Format:%H$
10+
copyright : (C) 2018 by Peillet Sébastien
11+
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
"""
23+
24+
import os
25+
26+
from PyQt4 import QtGui, uic
27+
from PyQt4.QtCore import pyqtSignal
28+
29+
FORM_CLASS, _ = uic.loadUiType(os.path.join(
30+
os.path.dirname(__file__), 'AutoTrack_dockwidget_base.ui'))
31+
32+
33+
class AutomaTracksDockWidget(QtGui.QDockWidget, FORM_CLASS):
34+
35+
closingPlugin = pyqtSignal()
36+
37+
def __init__(self, parent=None):
38+
"""Constructor."""
39+
super(AutomaTracksDockWidget, self).__init__(parent)
40+
# Set up the user interface from Designer.
41+
# After setupUI you can access any designer object by doing
42+
# self.<objectname>, and you can use autoconnect slots - see
43+
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
44+
# #widgets-and-dialogs-with-auto-connect
45+
self.setupUi(self)
46+
47+
def closeEvent(self, event):
48+
self.closingPlugin.emit()
49+
event.accept()
50+

AutoTrack_dockwidget_base.ui

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>AutomaTracksDockWidgetBase</class>
4+
<widget class="QDockWidget" name="AutomaTracksDockWidgetBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>232</width>
10+
<height>141</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>AutomaTracks</string>
15+
</property>
16+
<widget class="QWidget" name="dockWidgetContents">
17+
<layout class="QGridLayout" name="gridLayout">
18+
<item row="0" column="0">
19+
<widget class="QLabel" name="label">
20+
<property name="text">
21+
<string>Replace this QLabel
22+
with the desired
23+
plugin content.</string>
24+
</property>
25+
</widget>
26+
</item>
27+
</layout>
28+
</widget>
29+
</widget>
30+
<resources/>
31+
<connections/>
32+
</ui>

__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
AutomaTracks
5+
A QGIS plugin
6+
Automatic tracks with constraint with path point
7+
-------------------
8+
begin : 2018-01-25
9+
copyright : (C) 2018 by Peillet Sébastien
10+
11+
git sha : $Format:%H$
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
This script initializes the plugin, making it known to QGIS.
23+
"""
24+
25+
26+
# noinspection PyPep8Naming
27+
def classFactory(iface): # pylint: disable=invalid-name
28+
"""Load AutomaTracks class from file AutomaTracks.
29+
30+
:param iface: A QGIS interface instance.
31+
:type iface: QgsInterface
32+
"""
33+
#
34+
from .AutoTrack import AutomaTracks
35+
return AutomaTracks(iface)

i18n/af.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE TS><TS version="2.0" language="af" sourcelanguage="en">
3+
<context>
4+
<name>@default</name>
5+
<message>
6+
<location filename="test_translations.py" line="48"/>
7+
<source>Good morning</source>
8+
<translation>Goeie more</translation>
9+
</message>
10+
</context>
11+
</TS>

icon.png

1.01 KB
Loading

0 commit comments

Comments
 (0)