示例#1
0
文件: ui.py 项目: SV-97/TUInventory
 def __init__(self, parent=None):
     path = utils.absolute_path("login.ui")
     super().__init__(parent)
     self.parent = parent
     self.ui = uic.loadUi(path, self)
     self.b_login.clicked.connect(self.b_login_click)
     self.b_password_lost.clicked.connect(self.b_password_lost_click)
示例#2
0
文件: ui.py 项目: SV-97/TUInventory
 def __init__(self, parent=None):
     path = utils.absolute_path("reset.ui")
     super().__init__(parent)
     self.parent = parent
     self.ui = uic.loadUi(path, self)
     self.b_browse.clicked.connect(self.b_browse_click)
     self.b_password_reset.clicked.connect(self.b_password_reset_click)
     self.b_password_close.clicked.connect(self.b_password_close_click)
     self.t_path.setText(self.filepath)
     self.ui.b_browse.setIcon(QtGui.QIcon("pictures/folder.png"))
     self.ui.b_browse.setIconSize(QtCore.QSize(20, 20))
示例#3
0
def run_icon_tray():
    global icon_tray
    icon_tray = icon(name='name',
                     icon=Image.open(absolute_path(r'resources\icon.png')),
                     title='Hotkey Manager',
                     menu=menu(
                         item('Active',
                              on_clicked,
                              default=True,
                              checked=lambda item: state),
                         item('Exit', menu_exit)))
    icon_tray.run()
示例#4
0
文件: main.py 项目: SV-97/TUInventory
def main():
    public_key_path = keys.PUBLIC_KEY_PATH
    if not public_key_path.exists():
        private_key_path = absolute_path("priv.key")
        keys.generate_key(public_key_path, private_key_path)
    app = QApplication(sys.argv)
    dialog_main = ui.MainDialog()
    dialog_main.showMaximized()

    try:
        videostream = LazyVideoStream()
        videostream.mirror = config["mirror"]
        videostream.start()
        logger.info(f"Camera {videostream.camera_id} succesfully opened")
        video_ui_sync_1 = VideoStreamUISync(dialog_main.ui.videoFeed,
                                            videostream,
                                            dialog_main.code_recognized,
                                            "frames")
        video_ui_sync_2 = VideoStreamUISync(dialog_main.ui.videoFeed,
                                            videostream,
                                            dialog_main.code_recognized,
                                            "codes")
        video_ui_sync_1.start()
        video_ui_sync_2.start()
        logger.info("Connected Camera to UI")
    except IOError as e:
        logger.error(str(e))
        videostream = Dummy()
        video_ui_sync_1 = Dummy()
        video_ui_sync_2 = Dummy()

    settings_manager = SettingsManger(video_ui_sync_1, video_ui_sync_2,
                                      videostream)
    settings_manager.start()
    dialog_main.settings_event = settings_manager.event
    return app.exec_()
示例#5
0
from sqlalchemy.ext.declarative import declarative_base
from PyQt5.QtGui import QImage, QPixmap

from logger import logger
from utils import absolute_path

orm = sqlalchemy.orm

Base = declarative_base()
if __name__ == "__main__":
    print("")
    if not input("Warning! Do you really want to delete the database and write some example data to it? [y/N]: ") in ("y", "Y"):
        exit()
    print("")
    logger.info("Database cleared! This was authorized via a prompt")
    with open(absolute_path("test.db"), "w") as f:
        f.flush()
engine = sqlalchemy.create_engine(f"sqlite:///{absolute_path('test.db')}", echo=False)
# engine = sqlalchemy.create_engine("sqlite:///:memory:", echo=False)


class IntegrityError(IOError):
    """Error to raise if an operation compromises database integrity"""
    def __init__(self, message):
        self.message = message

    def __str__(self):
        return f'Couldn\'t create instance with given Parameters: "{self.message}"'

class BigInt(sqlalchemy.types.TypeDecorator):
    """SQLAlchemy datatype for dealing with ints that potentially overflow a basic SQL Integer"""
示例#6
0
def on_clicked(icon, item):
    global state
    state = not item.checked
    icon_tray.icon = Image.open(
        absolute_path(r'resources\icon.png')) if state else Image.open(
            absolute_path(r'resources\icon-off.png'))
示例#7
0
文件: ui.py 项目: SV-97/TUInventory
    def __init__(self, parent=None):
        path = utils.absolute_path("mainScaling.ui")
        super().__init__(parent)
        self.ui = uic.loadUi(path, self)
        self.logged_in_user = None
        self.savepath = None
        self.set_tree()
        self.set_combobox_location_u()
        self.set_combobox_location_u_admin()
        self.set_combobox_location_d()
        self.set_combobox_producer_a()
        self.set_combobox_producer_d()
        self.set_combobox_device_user()
        self.set_combobox_device_location()
        self.set_combobox_article_d()
        self.set_combobox_user_d()
        self.set_combobox_user_admin()
        self.setMouseTracking(True)

        self.ui.rb_mirror_yes.setChecked(config["mirror"])
        self.ui.rb_mirror_no.setChecked(not config["mirror"])

        self.t_path_device.setText(config["qr_path"])

        icon = QtGui.QIcon()
        icon_path = utils.absolute_path("pictures/TUI_Logo.png")
        icon.addFile(f"{icon_path}", QtCore.QSize(256, 256))
        self.setWindowIcon(icon)

        self.ui.b_user_login.clicked.connect(self.b_user_login_click)
        self.ui.b_create_new_qrcode.clicked.connect(
            self.b_create_new_qrcode_click)
        self.ui.b_user_logout.clicked.connect(self.b_user_logout_click)
        self.ui.b_home_1.clicked.connect(self.b_home_1_click)
        self.ui.b_user_change.clicked.connect(self.b_user_change_click)
        self.ui.b_user_change_admin.clicked.connect(
            self.b_user_change_admin_click)
        self.ui.b_user_reset_admin.clicked.connect(self.reset_password)
        self.ui.b_save_device.clicked.connect(self.b_save_device_click)
        self.ui.b_change_device.clicked.connect(self.b_change_device_click)
        self.ui.b_delete_device.clicked.connect(self.b_delete_device_click)
        self.ui.b_create_device.clicked.connect(self.b_create_device_click)
        self.ui.b_create_article.clicked.connect(self.b_create_article_click)
        self.ui.b_create_producer.clicked.connect(self.b_create_producer_click)
        self.ui.b_qr_path.clicked.connect(self.b_qr_path_click)
        self.ui.b_save_settings.clicked.connect(self.mirror_setting)
        self.ui.b_tab_1.clicked.connect(self.b_tab_1_click)
        self.ui.b_tab_2.clicked.connect(self.b_tab_2_click)
        self.ui.b_tab_3.clicked.connect(self.b_tab_3_click)
        self.ui.b_tab_4.clicked.connect(self.b_tab_4_click)
        self.ui.b_tab_5.clicked.connect(self.b_tab_5_click)
        self.ui.in_phone.textChanged.connect(self.set_phonenumber)
        self.ui.in_phone_admin.textChanged.connect(self.set_phonenumber)
        self.ui.cb_producer_d.currentIndexChanged.connect(
            self.reload_combobox_article_d)
        self.ui.cb_user_admin.currentIndexChanged.connect(
            self.reload_user_change)

        foldericon_path = utils.absolute_path("pictures/folder.png")
        self.ui.b_save_device.setIcon(QtGui.QIcon(f"{foldericon_path}"))
        self.ui.b_save_device.setIconSize(QtCore.QSize(20, 20))
        self.ui.b_qr_path.setIcon(QtGui.QIcon(f"{foldericon_path}"))
        self.ui.b_qr_path.setIconSize(QtCore.QSize(20, 20))

        self.setAutoFillBackground(True)  # background / white
        p = self.palette()
        p.setColor(self.backgroundRole(), Qt.white)
        self.setPalette(p)

        palette1 = self.line_1.palette()
        role1 = self.line_1.backgroundRole()
        palette1.setColor(role1, QColor('blue'))
        self.ui.line_1.setPalette(palette1)
        self.ui.line_1.setAutoFillBackground(True)

        palette2 = self.line_2.palette()
        role2 = self.line_2.backgroundRole()
        palette2.setColor(role2, QColor('blue'))
        self.ui.line_2.setPalette(palette2)
        self.ui.line_2.setAutoFillBackground(True)

        palette3 = self.line_3.palette()
        role3 = self.line_3.backgroundRole()
        palette3.setColor(role3, QColor('blue'))
        self.ui.line_3.setPalette(palette3)
        self.ui.line_3.setAutoFillBackground(True)

        palette4 = self.line_4.palette()
        role4 = self.line_4.backgroundRole()
        palette4.setColor(role4, QColor('blue'))
        self.ui.line_4.setPalette(palette4)
        self.ui.line_4.setAutoFillBackground(True)

        palette5 = self.line_5.palette()
        role5 = self.line_5.backgroundRole()
        palette5.setColor(role5, QColor('blue'))
        self.ui.line_5.setPalette(palette5)
        self.ui.line_5.setAutoFillBackground(True)

        palette7 = self.bottom_frame.palette()
        role7 = self.bottom_frame.backgroundRole()
        palette7.setColor(role7, QColor('blue'))
        self.ui.bottom_frame.setPalette(palette7)
        self.ui.bottom_frame.setAutoFillBackground(True)
        self.ui.bottom_frame.setStyleSheet("color: white")

        self.ui.stackedWidget.setCurrentIndex(0)
        self.ui.line_1.show()
        self.ui.line_2.hide()
        self.ui.line_3.hide()
        self.ui.line_4.hide()
        self.ui.line_5.hide()
        self.update_user_dependant()
        self.code_recognized.connect(self.recognized_barcode)

        self.ui.t_setting_timeout.setText(str(config["timeout"]))
        self.ui.t_setting_qr_path.setText(config["qr_path"])
示例#8
0
import json
import os
from datetime import datetime
from os.path import dirname, join, realpath

from flask import Flask, flash, redirect, request, send_from_directory, url_for
from markupsafe import escape
from werkzeug.utils import secure_filename

from utils import ALLOWED_EXTENSIONS, absolute_path, allowed_file, make_message

UPLOAD_FOLDER = "static/data"


app = Flask(__name__, static_url_path="")
app.config["UPLOAD_FOLDER"] = absolute_path(UPLOAD_FOLDER)


@app.route("/data/<path:path>", methods=["GET"])
def upload_data(path):
    return send_from_directory(UPLOAD_FOLDER, path)


@app.route("/api/data", methods=["GET"])
def list_data():
    data = os.listdir(UPLOAD_FOLDER)
    return data


def get_state_file(filename):
    return join(app.config["UPLOAD_FOLDER"], "{}.json".format(escape(filename)))
示例#9
0
 def __init__(self, config_file=absolute_path("config.ini")):
     super().__init__()
     self.config_file = config_file
示例#10
0
        except configparser.NoSectionError:
            self.add_section(section)
            self.set(section, key, value)

    def flush(self):
        with open(self.config_file, "w") as f:
            self.write(f)

    def read(self):
        return super().read(self.config_file)


config = ConfigParserDict()
if not config.config_file.exists():
    if "win32" in sys.platform:
        path = str.title(str(absolute_path("qr_codes")))
    else:
        path = str(absolute_path("qr_codes"))

    config["mirror"] = True
    config["qr_path"] = path
    config["timeout"] = 15.0
    config.flush()
config.read()


class SettingsManger(Thread):
    def __init__(self, video_ui_sync_1, video_ui_sync_2, videostream):
        super().__init__(name=f"{self.__class__.__name__}Thread_{id(self)}")
        self.video_ui_sync_1 = video_ui_sync_1
        self.video_ui_sync_2 = video_ui_sync_2
示例#11
0
 def create_cert_request(self, content):
     path = "certificates/pending/{}_{}.csr".format(self.id,
                                                    int(time.time()))
     f = open(utils.absolute_path(path), "w+")
     f.write(content)
     f.close()
示例#12
0
文件: keys.py 项目: SV-97/TUInventory
"""Generation and reading of RSA keys for asymmetric encryption"""

try:
    from Cryptodome.Cipher import PKCS1_OAEP
    from Cryptodome.PublicKey import RSA
except ImportError as e:
    try:
        from Crypto.Cipher import PKCS1_OAEP
        from Crypto.PublicKey import RSA
    except ImportError as err:
        raise err

from utils import absolute_path

PUBLIC_KEY_PATH = absolute_path("pub.key")


def generate_key(path_public, path_private):
    """Generate new RSA key-pair and save it to the given paths

        Args:
            path_public: Path where the public-key should be stored
            path_private: Path where th private-key should be stored
    """
    key = RSA.generate(4096)
    with open(path_public, "wb") as f:
        f.write(key.publickey().exportKey())
    with open(path_private, "wb") as f:
        f.write(key.exportKey())

示例#13
0
def load_flatfile():
    absolute = absolute_path('data/db.json')
    with open(absolute) as flatfile:
        return json.load(flatfile)
示例#14
0
"""logging interface for consistent formatting"""

import logging

from utils import absolute_path

handler = logging.FileHandler(filename=absolute_path("protocol.log"))
formatter = logging.Formatter(
    fmt='{asctime} [{levelname:8}] from {module:>20}.{funcName:30} "{message}"', 
    style="{", 
    datefmt="%Y-%m-%dT%H:%m:%S")

handler.setFormatter(formatter)
logger = logging.getLogger()
logger.addHandler(handler)
logger.setLevel(logging.INFO)

del handler
del formatter