forked from quentinsf/pygarmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnome-pygarmin
More file actions
executable file
·267 lines (216 loc) · 8.56 KB
/
Copy pathgnome-pygarmin
File metadata and controls
executable file
·267 lines (216 loc) · 8.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/usr/bin/env python
"""
gnome-pygarmin
This is a GNOME user application for communicating with Garmin
GPS receivers.
To use it you will need the gnome-python package installed, which
can be found at ftp://ftp.daa.com.au/pub/james/python/
This is released under the Gnu General Public Licence. A copy of
this can be found at http://www.opensource.org/licenses/gpl-license.html
For the latest information about PyGarmin, please see
http://pygarmin.sourceforge.net/
(c) 2000 James A. H. Skillen <jahs@jahs.net>
"""
import sys, garmin, gtk.glade
from gtk import *
from gnome.ui import *
import gnome
import gconf
class GnomePygarmin:
def __init__(self):
gnome.init("myapp", "0.8")
self.widgets = glade.XML("gnome-pygarmin.glade",
"gnome_pygarmin")
signals = {
"on_gnome_pygarmin_destroy" : self.exit,
# File
"on_menu_new_activate" : self.new,
"on_menu_open_activate" : self.open,
"on_menu_save_activate" : self.save,
"on_menu_save_as_activate" : self.save_as,
"on_menu_exit_activate" : self.exit,
# Edit
"on_menu_cut_activate" : self.cut,
"on_menu_copy_activate" : self.copy,
"on_menu_paste_activate" : self.paste,
"on_menu_clear_activate" : self.clear,
"on_menu_properties_activate" : self.properties,
# GPS
"on_menu_download_activate" : self.download,
"on_menu_info_activate" : self.info,
# Settings
"on_menu_preferences_activate" : self.prefs,
# Help
"on_menu_about_activate" : self.about,
# Toolbar
"on_toolbar_open_clicked" : self.open,
"on_toolbar_save_clicked" : self.save,
"on_toolbar_download_clicked" : self.download,
"on_toolbar_info_clicked" : self.info
}
self.widgets.signal_autoconnect(signals)
self.wpt_list = gtk.ListStore(str, str, str)
self.widgets.get_widget('wpt_view').set_model(self.wpt_list)
cell = gtk.CellRendererText()
column = gtk.TreeViewColumn('Name', cell, text=0)
self.widgets.get_widget('wpt_view').append_column(column)
cell = gtk.CellRendererText()
column = gtk.TreeViewColumn('Longitude', cell, text=1)
self.widgets.get_widget('wpt_view').append_column(column)
cell = gtk.CellRendererText()
column = gtk.TreeViewColumn('Latitude', cell, text=2)
self.widgets.get_widget('wpt_view').append_column(column)
self.gps = None
self.client = gconf.client_get_default()
device = self.client.get_string("/apps/gnome-pygarmin/Preferences/serial_device")
self._init_gps(device)
self.widgets.get_widget('gnome_pygarmin').show()
def _init_gps(self, device = None):
if device == None:
self.prefs(None)
d = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
flags=gtk.DIALOG_MODAL,
buttons=gtk.BUTTONS_CLOSE,
parent=self.widgets.get_widget("gnome_pygarmin"),
message_format="Please enter the serial device to which your GPS is connected.")
d.connect('response', lambda dialog, response: dialog.destroy())
d.run()
else:
try:
phys = garmin.SerialLink(device)
self.gps = garmin.Garmin(phys)
except:
msg = str(sys.exc_info()[1])
if msg:
self.prefs(None)
d = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
flags=gtk.DIALOG_MODAL,
buttons=gtk.BUTTONS_CLOSE,
message_format=msg)
d.connect('response', lambda dialog, response: dialog.destroy())
d.run()
def _not_done(self):
e = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
flags=gtk.DIALOG_MODAL,
buttons=gtk.BUTTONS_OK,
parent=self.widgets.get_widget("gnome_pygarmin"),
message_format="Not yet implemented!")
e.connect('response', lambda dialog, response: dialog.destroy())
e.run()
# File
def new(self, widget):
self._not_done()
def open(self, widget):
self._not_done()
def save(self, widget):
self._not_done()
def save_as(self, widget):
self._not_done()
def exit(self, widget):
self.client.suggest_sync()
gtk.main_quit()
# Edit
def cut(self, widget):
self._not_done()
def copy(self, widget):
self._not_done()
def paste(self, widget):
self._not_done()
def clear(self, widget):
self._not_done()
def properties(self, widget):
self._not_done()
# GPS
def download(self, widget):
Download(self)
def info(self, widget):
self._not_done()
# Settings
def prefs(self, widget):
Preferences(self)
# Help
def about(self, widget):
About(self)
class Preferences:
def __init__(self, pygarmin):
self.pygarmin = pygarmin
self.widgets = glade.XML("gnome-pygarmin.glade",
"preferences")
signals = {
"on_prefs_ok_clicked" : self.ok,
"on_prefs_apply_clicked" : self.apply,
"on_prefs_cancel_clicked" : self.cancel
}
self.widgets.signal_autoconnect(signals)
window = self.widgets.get_widget("preferences")
text_entry = self.widgets.get_widget("device")
device = pygarmin.client.get_string("/apps/gnome-pygarmin/Preferences/serial_device")
if device == None:
device = ""
text_entry.set_text(device)
window.show()
def ok(self, widget):
text_entry = self.widgets.get_widget("device")
device = text_entry.get_text()
self.pygarmin._init_gps(device)
self.pygarmin.client.set_string("/apps/gnome-pygarmin/Preferences/serial_device", device)
self.cancel(None)
def apply(self, widget):
text_entry = self.widgets.get_widget("device")
device = text_entry.get_text()
self.pygarmin._init_gps(device)
self.cancel(None)
def cancel(self, widget):
window = self.widgets.get_widget("preferences")
window.destroy()
class Download:
def __init__(self, pygarmin):
self.pygarmin = pygarmin
self.widgets = glade.XML("gnome-pygarmin.glade",
"download")
signals = {
"on_download_ok_clicked" : self.ok,
"on_download_cancel_clicked" : self.cancel
}
self.widgets.signal_autoconnect(signals)
window = self.widgets.get_widget("download")
window.show()
def _waypoints(self):
if not self.pygarmin.gps:
self.pygarmin._init_gps()
return
wpts = self.pygarmin.gps.getWaypoints()
self.pygarmin.wpt_list.clear()
for w in wpts:
self.pygarmin.wpt_list.append((w.ident,
str(garmin.degrees(w.slat)),
str(garmin.degrees(w.slon))))
def ok(self, widget):
w = self.widgets.get_widget("download_waypoints")
r = self.widgets.get_widget("download_routes")
t = self.widgets.get_widget("download_tracks")
get_w = w.get_active()
self.cancel(None)
if get_w:
w = gtk.MessageDialog(type=gtk.MESSAGE_INFO,
flags=gtk.DIALOG_MODAL,
parent=self.widgets.get_widget("gnome_pygarmin"),
message_format="Downloading waypoints")
w.show()
self._waypoints()
w.destroy()
def cancel(self, widget):
window = self.widgets.get_widget("download")
window.destroy()
class About:
def __init__(self, pygarmin):
self.pygarmin = pygarmin
self.widgets = glade.XML("gnome-pygarmin.glade",
"about")
window = self.widgets.get_widget("about")
window.show()
def main():
app = GnomePygarmin()
gtk.main()
if __name__ == "__main__":
main()