зеркало из https://github.com/microsoft/InQRy.git
extract __init__.py contents to modules
This commit is contained in:
Родитель
22ec8eb7d7
Коммит
0d444819dd
|
@ -0,0 +1,33 @@
|
|||
import os
|
||||
|
||||
import qrcode
|
||||
|
||||
from inqry.gui import error_message_box
|
||||
|
||||
|
||||
class AssetQRCode(qrcode.QRCode):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def make_new_asset_qr(self, data) -> qrcode.image:
|
||||
self.add_data(data)
|
||||
return self.make_image()
|
||||
|
||||
def make_new_model_qr(self, data) -> qrcode.image:
|
||||
self.add_data(data)
|
||||
return self.make_image()
|
||||
|
||||
def save(self, file_name, data):
|
||||
desktop = os.path.expanduser('~/Desktop')
|
||||
qrcode_png = os.path.join(desktop, '{}.png'.format(file_name))
|
||||
self.prevent_duplicate_file(qrcode_png)
|
||||
with open(qrcode_png, 'wb') as fp:
|
||||
return self.make_new_asset_qr(data).save(fp)
|
||||
|
||||
def display(self, data):
|
||||
img = self.make_new_asset_qr(data)
|
||||
img.show()
|
||||
|
||||
def prevent_duplicate_file(self, file):
|
||||
if os.path.exists(file):
|
||||
error_message_box('QR code already exists.')
|
|
@ -0,0 +1,24 @@
|
|||
DELAY = '~d'
|
||||
TAB = '~t'
|
||||
ENTER = '~e'
|
||||
SPACE = '\x20'
|
||||
|
||||
|
||||
def textify(value: str) -> str:
|
||||
contents = [value, TAB]
|
||||
return ''.join([delayify(item) for item in contents if item is not None])
|
||||
|
||||
|
||||
def listify(value: str) -> str:
|
||||
contents = [SPACE, value, ENTER, TAB]
|
||||
return ''.join([delayify(item) for item in contents])
|
||||
|
||||
|
||||
def delayify(value: str, amount=1) -> str:
|
||||
delay_count = DELAY * amount
|
||||
return delay_count + value
|
||||
|
||||
|
||||
def tabify(amount=1) -> str:
|
||||
tab_count = TAB * amount
|
||||
return tab_count
|
|
@ -0,0 +1,94 @@
|
|||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from tkinter import Button, E, Entry, Label, OptionMenu, StringVar, Tk, messagebox
|
||||
|
||||
from inqry.asset_qrcode import AssetQRCode
|
||||
from inqry.form_instructions import FormInstructions
|
||||
|
||||
|
||||
class InQRyGUI: # TODO: Extract GUI attributes to methods
|
||||
def __init__(self):
|
||||
self.form_instructions = FormInstructions()
|
||||
self.asset_qr = AssetQRCode()
|
||||
|
||||
self.root_window = Tk()
|
||||
self.root_window.title('InQRy')
|
||||
|
||||
self.alias_label = Label(self.root_window, text='Alias:')
|
||||
self.alias_label.grid(row=1, column=1, sticky=E)
|
||||
|
||||
self.alias_entry = Entry(self.root_window)
|
||||
self.alias_entry.grid(row=1, column=2)
|
||||
|
||||
self.asset_tag_label = Label(self.root_window, text='Asset Tag:')
|
||||
self.asset_tag_label.grid(row=2, column=1, sticky=E)
|
||||
|
||||
self.asset_tag_entry = Entry(self.root_window)
|
||||
self.asset_tag_entry.grid(row=2, column=2)
|
||||
|
||||
self.form_options = tuple(self.form_instructions.form_types.keys())
|
||||
self.form_selection = StringVar()
|
||||
self.form_selection.set(self.form_options[0])
|
||||
self.form_menu = OptionMenu(self.root_window, self.form_selection, *self.form_options)
|
||||
self.form_menu.grid(row=3, column=1)
|
||||
|
||||
self.qrcode_options = ('Asset', 'Model')
|
||||
self.qrcode_selection = StringVar()
|
||||
self.qrcode_selection.set(self.qrcode_options[0])
|
||||
self.qrcode_menu = OptionMenu(self.root_window, self.qrcode_selection, *self.qrcode_options)
|
||||
self.qrcode_menu.grid(row=3, column=2)
|
||||
|
||||
self.generate_qr_button = Button(self.root_window, text='Display', command=self.display)
|
||||
self.generate_qr_button.grid(row=4, column=1)
|
||||
|
||||
self.generate_qr_button = Button(self.root_window, text='Save to Desktop', command=self.save)
|
||||
self.generate_qr_button.grid(row=4, column=2)
|
||||
|
||||
def save(self):
|
||||
alias = self.alias_entry.get().lower()
|
||||
asset_tag = self.asset_tag_entry.get()
|
||||
try:
|
||||
file_name = alias + '-' + asset_tag
|
||||
data = self.gather_user_input()
|
||||
return self.asset_qr.save(file_name, self.form_instructions.gui_helper(*data))
|
||||
except TypeError:
|
||||
error_message_box('Missing or improperly\nformatted entry.')
|
||||
|
||||
def display(self):
|
||||
data = self.gather_user_input()
|
||||
return self.asset_qr.display(self.form_instructions.gui_helper(*data))
|
||||
|
||||
def gather_user_input(self) -> tuple:
|
||||
return (
|
||||
self.qrcode_selection.get(), self.asset_tag_entry.get(), self.alias_entry.get(), self.form_selection.get())
|
||||
|
||||
def valid_asset(self, asset_tag: str): # TODO: Define custom exceptions inside FormInstructions
|
||||
pattern = re.compile(r'^E?\d{7}$')
|
||||
return asset_tag if bool(re.match(pattern, asset_tag)) else False
|
||||
|
||||
def valid_alias(self, alias: str): # TODO: Define custom exception inside FormInstructions
|
||||
pattern = re.compile(r'^(v\-)?[A-Za-z]+$')
|
||||
return alias if bool(re.match(pattern, alias)) else False
|
||||
|
||||
|
||||
def error_message_box(message: str):
|
||||
messagebox.showerror('Oops!', message)
|
||||
|
||||
|
||||
def mobile_capability(): # TODO: Re-implement mobile_capability() into GUI
|
||||
if sys.platform == 'darwin':
|
||||
try:
|
||||
subprocess.check_output(['/usr/local/bin/cfgutil'])
|
||||
return 'active'
|
||||
except FileNotFoundError:
|
||||
print(
|
||||
'''
|
||||
No such file or directory: "/usr/local/bin/cfgutil"
|
||||
|
||||
You must install cfgutil using Apple Configurator in order to
|
||||
use InQRy with a mobile device.
|
||||
''')
|
||||
return 'disable'
|
||||
else:
|
||||
pass
|
Загрузка…
Ссылка в новой задаче