Skip to content

Commit 51a63a2

Browse files
committed
Update genicons.sh script
1 parent 0345b35 commit 51a63a2

5 files changed

Lines changed: 85 additions & 76 deletions

File tree

pyauth/AuthEntryPanel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import wx
2121

2222
from Logging import GetLogger
23-
from QrCode import QrCodeFrame
23+
from QrCodeFrame import QrCodeFrame
2424

2525

2626
class AuthEntryPanel(wx.Panel):

pyauth/QrCodeFrame.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright (C) 2017 Silverglass Technical
4+
# Author: Todd Knarr (tknarr)
5+
6+
import wx
7+
8+
from QrCodePanel import QrCodePanel
9+
10+
11+
class QrCodeFrame(wx.Frame):
12+
def __init__(self, parent, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize,
13+
style = wx.DEFAULT_FRAME_STYLE, name = wx.FrameNameStr, uri = None, border = 0):
14+
wx.Frame.__init__(self, parent, id, title, pos, size, style, name)
15+
self.panel = QrCodePanel(self, uri = uri, border = border)
16+
self.panel.SetFocus()

pyauth/QrCodeImage.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright (C) 2017 Silverglass Technical
4+
# Author: Todd Knarr (tknarr)
5+
6+
import wx
7+
from io import BytesIO
8+
9+
import qrcode
10+
11+
12+
class QrCodeImage:
13+
"""Represents a QR code image."""
14+
15+
def __init__(self, uri, box_size):
16+
self.uri = uri
17+
self.box_size = box_size
18+
19+
def GetImage(self):
20+
qr = qrcode.QRCode(version = None, box_size = self.box_size,
21+
error_correction = qrcode.constants.ERROR_CORRECT_M)
22+
qr.add_data(self.uri)
23+
qr.make(fit = True)
24+
img = qr.make_image()
25+
strm = BytesIO()
26+
img.save(strm, "PNG")
27+
strm.seek(0)
28+
image = wx.ImageFromStream(strm, wx.BITMAP_TYPE_PNG)
29+
return image
Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,12 @@
11
# -*- coding: utf-8 -*-
2-
"""Generate a QR code image for an entry."""
32

4-
## PyAuth - Google Authenticator desktop application
5-
## Copyright (C) 2016 Todd T Knarr <tknarr@silverglass.org>
3+
# Copyright (C) 2017 Silverglass Technical
4+
# Author: Todd Knarr (tknarr)
65

7-
## This program is free software: you can redistribute it and/or modify
8-
## it under the terms of the GNU General Public License as published by
9-
## the Free Software Foundation, either version 3 of the License, or
10-
## (at your option) any later version.
11-
12-
## This program is distributed in the hope that it will be useful,
13-
## but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15-
## GNU General Public License for more details.
16-
17-
## You should have received a copy of the GNU General Public License
18-
## along with this program. If not, see http://www.gnu.org/licenses/
19-
20-
import qrtools
21-
import tempfile
226
import wx
23-
from io import BytesIO
247

258
import Configuration
26-
import qrcode
27-
28-
29-
class QrCodeUri:
30-
"""Represents a provisioning URI decoded from a QR code image."""
31-
32-
def __init__(self):
33-
self.uri = None
34-
self.temp_dir = Configuration.GetConfigDirectory()
35-
self.qr = qrtools.QR()
36-
37-
def GetUri(self):
38-
return self.uri
39-
40-
def decode_file(self, filename):
41-
# TODO decode file
42-
pass
43-
44-
def decode_url(self, url):
45-
# TODO fetch image from url and decode
46-
pass
47-
48-
def decode_image(self, image):
49-
temp_file = tempfile.NamedTemporaryFile(dir = self.temp_dir, suffix = ".png")
50-
# TODO write image into temp file
51-
self.uri = self.decode_file(temp_file.name)
52-
temp_file.close()
53-
return self.uri
54-
55-
56-
class QrCodeImage:
57-
"""Represents a QR code image."""
58-
59-
def __init__(self, uri, box_size):
60-
self.uri = uri
61-
self.box_size = box_size
62-
63-
def GetImage(self):
64-
qr = qrcode.QRCode(version = None, box_size = self.box_size,
65-
error_correction = qrcode.constants.ERROR_CORRECT_M)
66-
qr.add_data(self.uri)
67-
qr.make(fit = True)
68-
img = qr.make_image()
69-
strm = BytesIO()
70-
img.save(strm, "PNG")
71-
strm.seek(0)
72-
image = wx.ImageFromStream(strm, wx.BITMAP_TYPE_PNG)
73-
return image
9+
from QrCodeImage import QrCodeImage
7410

7511

7612
class QrCodePanel(wx.Panel):
@@ -192,11 +128,3 @@ def UpdateBitmap(self):
192128
frame_size = self.ClientSizeToFrameSize(client_size)
193129
p = self.GetParent()
194130
p.SetSize(frame_size)
195-
196-
197-
class QrCodeFrame(wx.Frame):
198-
def __init__(self, parent, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize,
199-
style = wx.DEFAULT_FRAME_STYLE, name = wx.FrameNameStr, uri = None, border = 0):
200-
wx.Frame.__init__(self, parent, id, title, pos, size, style, name)
201-
self.panel = QrCodePanel(self, uri = uri, border = border)
202-
self.panel.SetFocus()

pyauth/QrCodeUri.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright (C) 2017 Silverglass Technical
4+
# Author: Todd Knarr (tknarr)
5+
6+
import qrtools
7+
import tempfile
8+
9+
import Configuration
10+
11+
12+
class QrCodeUri:
13+
"""Represents a provisioning URI decoded from a QR code image."""
14+
15+
def __init__(self):
16+
self.uri = None
17+
self.temp_dir = Configuration.GetConfigDirectory()
18+
self.qr = qrtools.QR()
19+
20+
def GetUri(self):
21+
return self.uri
22+
23+
def decode_file(self, filename):
24+
# TODO decode file
25+
pass
26+
27+
def decode_url(self, url):
28+
# TODO fetch image from url and decode
29+
pass
30+
31+
def decode_image(self, image):
32+
temp_file = tempfile.NamedTemporaryFile(dir = self.temp_dir, suffix = ".png")
33+
# TODO write image into temp file
34+
self.uri = self.decode_file(temp_file.name)
35+
temp_file.close()
36+
return self.uri

0 commit comments

Comments
 (0)