-
Notifications
You must be signed in to change notification settings - Fork 1
/
scan_wifi_code.py
68 lines (53 loc) · 2.16 KB
/
scan_wifi_code.py
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
#!/usr/bin/env python
# Copyright 2015 Tobias Mueller <[email protected]>
#
# This file is part of NetworkManager Barcode.
#
# NetworkManager Barcode is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# NetworkManager Barcode is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NetworkManager Barcode. If not, see <http://www.gnu.org/licenses/>.
import logging
from scan_barcode import BarcodeReaderGTK
from parse_barcode import parse
from gi.repository import GLib, Gtk
from gi.repository import Gst
class Scanner(Gtk.Application):
def __init__(self, code=None, *args, **kwargs):
self.code = code
super(Scanner, self).__init__(*args, **kwargs)
self.connect("activate", self.on_activate)
def on_activate(self, data=None):
window = Gtk.ApplicationWindow(type=Gtk.WindowType.TOPLEVEL)
window.set_title("WiFi QRCode scanner")
scanner = BarcodeReaderGTK()
scanner.connect("barcode", self.on_barcode)
window.add(scanner)
window.show_all()
self.add_window(window)
data = self.code
if data:
logging.info('Emitting barcode %r', data)
scanner.emit("barcode", data, None)
def on_barcode(self, reader, barcode, message):
logging.debug('Reader %r message %r', reader, message)
logging.debug('Received barcode! %s', barcode)
parsed = parse(barcode)
logging.info('Parsed %s into %s', barcode, parsed)
def main(code=None):
Gst.init()
app = Scanner(code)
app.run()
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
import sys
code = sys.argv[1] if len(sys.argv) > 1 else None
main(code=code)