64
53
self.surface = None
66
55
# Initialize the icon view widget
67
self.ui.iconview1.set_text_column(COL_TEXT)
56
self.ui.iconview1.set_text_column(COL_DESC)
68
57
self.ui.iconview1.set_pixbuf_column(COL_PIXBUF)
70
59
# Hide the notebook tabs
71
60
self.ui.notebook1.set_show_tabs(False)
73
self.qr_code_placeholder = 'aa'
62
# Initialize combo boxes
63
self.ui.comboboxtextSecurity.set_active(0)
64
self.ui.comboboxtextProtocol.set_active(0)
66
self.qr_code_placeholder = 'qreator'
68
def on_entryText_changed(self, widget, data=None):
69
self.update_qr_code(widget.get_text(widget.get_start_iter(),
70
widget.get_end_iter(),
75
73
def on_map_widget_button_press_event(self, actor, event, view):
76
74
x, y = event.get_coords()
77
75
lat, lon = view.x_to_longitude(x), view.y_to_latitude(y)
78
print "Mouse click at: %f %f" % (lon, lat)
77
self.ui.lat_entry.set_text(str(lat))
78
self.ui.lon_entry.set_text(str(lon))
80
self.update_qr_code('geo:{0},{1}'.format(str(lon), str(lat)))
81
def on_toolbuttonHome_clicked(self, widget, data=None):
84
def on_toolbuttonNew_clicked(self, widget, data=None):
82
85
'''Shows the home page'''
83
self.ui.notebook1.set_current_page(PAGE_HOME)
86
self.ui.notebook1.set_current_page(PAGE_NEW)
85
88
def on_toolbuttonHistory_clicked(self, widget, data=None):
86
89
'''Shows the history page'''
87
self.ui.notebook1.set_current_page(PAGE_HISTORY)
90
pass # self.ui.notebook1.set_current_page(PAGE_HISTORY)
89
92
def on_toolbuttonSettings_clicked(self, widget, data=None):
90
93
'''Shows the settings page'''
91
self.ui.notebook1.set_current_page(PAGE_SETTINGS)
94
pass # self.ui.notebook1.set_current_page(PAGE_SETTINGS)
93
96
def on_toolbuttonAbout_clicked(self, widget, data=None):
94
97
'''Shows the about page'''
95
98
self.ui.notebook1.set_current_page(PAGE_ABOUT)
100
def _hide_children(self, widget):
101
for child in widget.get_children():
104
def on_qr_url_clicked(self):
105
self._hide_children(self.ui.qr_input)
106
self.ui.qr_url.show_all()
108
def on_qr_wifi_clicked(self):
109
self._hide_children(self.ui.qr_input)
110
self.ui.qr_wifi.show_all()
112
def on_qr_text_clicked(self):
113
# Initialize multi-line text entry
114
textbuffer = self.ui.entryText.get_buffer()
115
textbuffer.connect("changed", self.on_entryText_changed, None)
117
self._hide_children(self.ui.qr_input)
118
self.ui.qr_text.show_all()
120
def on_qr_location_clicked(self):
121
# We're now loading the UI for the location QR type
122
self._hide_children(self.ui.qr_input)
123
self.ui.qr_location.show_all()
125
map_widget = GtkChamplain.Embed()
126
map_widget.set_hexpand(True)
127
map_widget.set_vexpand(True)
129
map_grid = self.ui.qr_location
131
map_grid.set_size_request(-1, 250)
132
map_grid.attach(map_widget, 0, 0, 1, 1)
134
self.map_view = map_widget.get_view()
135
self.map_view.set_reactive(True)
136
map_widget.connect('button-release-event',
137
self.on_map_widget_button_press_event,
140
# Get the current location, center the map on it, and initialize
142
latitude, longitude = get_current_location()
143
self.map_view.center_on(latitude, longitude)
144
if latitude == 0 and longitude == 0:
145
# In case something went wrong in getting the current location
146
self.map_view.set_zoom_level(1)
148
self.map_view.set_zoom_level(15)
149
self.map_view.set_kinetic_mode(True)
151
scale = Champlain.Scale()
152
scale.connect_view(self.map_view)
153
self.map_view.bin_layout_add(scale, Clutter.BinAlignment.START,
154
Clutter.BinAlignment.END)
156
self.ui.qr_location.show_all()
97
158
def on_iconview1_item_activated(self, widget, item):
98
159
'''Loads the UI for the appropriate QR type'''
100
161
model = widget.get_model()
101
qr_type = model[item][COL_ID]
103
# We're loading each UI type inside this grid
106
# FIXME: the way of choosing the page is a bit of a hack for now
107
if qr_type + PAGE_URL == PAGE_URL:
108
# We're now loading the UI for the URL QR type
110
entry1.connect('changed', self.on_entry1_changed)
111
entry1.set_hexpand(True)
113
# Remove the current widgets from the top half of the UI,
114
# replace them with the current QR type's UI
115
children = grid.get_children()
116
grid.remove(children[0])
117
grid.attach(entry1, 0, 0, 1, 1)
119
elif qr_type + PAGE_URL == PAGE_GEO:
120
# We're now loading the UI for the map QR type
121
map_widget = GtkChamplain.Embed()
122
map_widget.set_hexpand(True)
123
map_widget.set_vexpand(True)
125
map_grid = Gtk.Grid()
126
map_grid.attach(map_widget, 0, 0, 2, 1)
128
lat_entry = Gtk.Entry()
129
lat_entry.set_hexpand(True)
130
lat_label = Gtk.Label(_('Latitude:'))
131
lat_label.set_alignment(xalign=0, yalign=0.5)
132
lon_entry = Gtk.Entry()
133
lon_label = Gtk.Label(_('Longitude:'))
134
lon_label.set_alignment(xalign=0, yalign=0.5)
136
map_grid.attach_next_to(lat_label, map_widget,
137
Gtk.PositionType.BOTTOM, 1, 1)
138
map_grid.attach_next_to(lon_label, lat_label,
139
Gtk.PositionType.BOTTOM, 1, 1)
141
map_grid.attach_next_to(lat_entry, lat_label,
142
Gtk.PositionType.RIGHT, 1, 1)
143
map_grid.attach_next_to(lon_entry, lon_label,
144
Gtk.PositionType.RIGHT, 1, 1)
146
# Remove the current widgets from the top half of the UI,
147
# replace them with the current QR type's UI
148
children = grid.get_children()
149
grid.remove(children[0])
150
self.ui.grid1.attach(map_grid, 0, 0, 1, 1)
152
self.map_view = map_widget.get_view()
153
self.map_view.set_reactive(True)
154
map_widget.connect('button-release-event',
155
self.on_map_widget_button_press_event,
158
# Get the current location, center the map on it, and initialize
160
latitude, longitude = get_current_location()
161
self.map_view.center_on(latitude, longitude)
162
self.map_view.set_zoom_level(15)
163
self.map_view.set_kinetic_mode(True)
165
scale = Champlain.Scale()
166
scale.connect_view(self.map_view)
167
self.map_view.bin_layout_add(scale, Clutter.BinAlignment.START,
168
Clutter.BinAlignment.END)
171
self.ui.notebook1.set_current_page(PAGE_URL)
162
qr_callback = getattr(QreatorWindow, model[item][COL_CALLBACK])
166
self.ui.notebook1.set_current_page(PAGE_QR)
173
168
def get_pixbuf_from_drawing_area(self):
174
window = self.ui.drawingarea1.get_window()
169
window = self.ui.qr_drawingarea.get_window()
176
src_x, src_y = self.get_centered_coordinates(self.ui.drawingarea1,
171
src_x, src_y = self.get_centered_coordinates(self.ui.qr_drawingarea,
178
173
image_height = self.surface.get_height()
179
174
image_width = self.surface.get_width()
218
213
pixbuf = self.get_pixbuf_from_drawing_area()
219
214
self.clipboard.set_image(pixbuf)
221
def on_entry1_changed(self, widget, data=None):
222
self.qr_code_placeholder = widget.get_text()
223
self.ui.drawingarea1.queue_draw()
216
def update_qr_code(self, text):
217
self.qr_code_placeholder = text
218
self.ui.qr_drawingarea.queue_draw()
220
def on_entryURL_changed(self, widget, data=None):
221
self.update_url_qr_code(www=widget.get_text())
223
def on_comboboxtextProtocol_changed(self, widget, data=None):
224
self.update_url_qr_code(protocol=widget.get_active_text())
226
def update_url_qr_code(self, protocol=None, www=None):
228
protocol = self.ui.comboboxtextProtocol.get_active_text()
230
www = self.ui.entryURL.get_text()
232
if not protocol or www == '':
235
self.update_qr_code(protocol + www)
237
def update_wifi_qr_code(self, security=None, ssid=None, password=None):
239
security = self.ui.comboboxtextSecurity.get_active_text()
241
ssid = self.ui.entrySSID.get_text()
243
password = self.ui.entryPassword.get_text()
245
if not security or ssid == '' or password == '':
248
wifi_qr_code = 'WIFI:T:{0};S:{1};P:{2};;'.format(security, ssid,
250
self.update_qr_code(wifi_qr_code)
252
def on_comboboxtextSecurity_changed(self, widget, data=None):
253
self.update_wifi_qr_code(security=widget.get_active_text())
255
def on_entrySSID_changed(self, widget, data=None):
256
self.update_wifi_qr_code(ssid=widget.get_text())
258
def on_entryPassword_changed(self, widget, data=None):
259
self.update_wifi_qr_code(password=widget.get_text())
261
def on_checkbutton1_clicked(self, widget):
262
if widget.get_active():
263
self.ui.entryPassword.set_visibility(True)
265
self.ui.entryPassword.set_visibility(False)
225
267
def get_centered_coordinates(self, drawing_area, surface):