# Path: tailor/config.py
# def jpath(*args):
# def reload(path):
# 
# Path: tailor/smtp.py
# class SenderThread:
#     def __init__(self, address, filename):
#         self.address = address
#         self.filename = filename
# 
#     def run(self):
#         sender = pkConfig["email"]["sender"]
#         subject = pkConfig["email"]["subject"]
#         auth_file = "/home/mjolnir/git/tailor/secrets"
# 
#         msg = email.MIMEMultipart.MIMEMultipart("mixed")
#         msg["subject"] = subject
#         msg["from"] = sender
#         msg["to"] = self.address
# 
#         body = email.mime.Text.MIMEText("Here's your photo!\n\nThank you!\n\n")
#         msg.attach(body)
# 
#         file_msg = email.mime.base.MIMEBase("image", "jpeg")
#         file_msg.set_payload(open(self.filename).read())
#         email.encoders.encode_base64(file_msg)
#         file_msg.add_header("Content-Disposition", "attachment;filname=photo.jpg")
#         msg.attach(file_msg)
# 
#         with open(auth_file) as fh:
#             auth = pickle.load(fh)
#             auth = auth["smtp"]
# 
#         with open("email.log", "a") as fh:
#             fh.write("{}\t{}\n".format(self.address, self.filename))
# 
#         smtpout = smtplib.SMTP(auth["host"])
#         smtpout.login(auth["username"], auth["password"])
#         smtpout.sendmail(sender, [self.address], msg.as_string())
#         smtpout.quit()


import os.path
from functools import partial
from kivy.config import Config
from kivy.network.urlrequest import UrlRequest
from kivy.properties import *
from kivy.uix.accordion import AccordionItem
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from ..config import pkConfig
from ..smtp import SenderThread
    from PIL import Image
        from kivy.core.window import Window
            widget.on_touch_up = derp
            widget.on_touch_motion = derp

    def do_print(self):
        filename = self.filename[self.filename.rindex("/") + 1 :]
        url = "http://127.0.0.1:5000/print/" + filename
        for i in range(self.prints):
            req = UrlRequest(url, print)

    def handle_print_touch(self, popup, widget):
        popup.dismiss()

        self.do_print()

        layout = BoxLayout(orientation="vertical")
        label = Label(text="Your prints will be ready soon!", font_size=30)
        button = Button(text="Awesome!", font_size=30, background_color=(0, 1, 0, 1))
        layout.add_widget(label)
        layout.add_widget(button)

        popup = Popup(
            title="Just thought you should know...",
            content=layout,
            size_hint=(0.5, 0.5),
        )

        button.bind(on_release=popup.dismiss)
        popup.open()

    def do_email(self, popup, address, filename, widget):

# Path: tailor/config.py
# def jpath(*args):
# def reload(path):
# 
# Path: tailor/smtp.py
# class SenderThread:
#     def __init__(self, address, filename):
#         self.address = address
#         self.filename = filename
# 
#     def run(self):
#         sender = pkConfig["email"]["sender"]
#         subject = pkConfig["email"]["subject"]
#         auth_file = "/home/mjolnir/git/tailor/secrets"
# 
#         msg = email.MIMEMultipart.MIMEMultipart("mixed")
#         msg["subject"] = subject
#         msg["from"] = sender
#         msg["to"] = self.address
# 
#         body = email.mime.Text.MIMEText("Here's your photo!\n\nThank you!\n\n")
#         msg.attach(body)
# 
#         file_msg = email.mime.base.MIMEBase("image", "jpeg")
#         file_msg.set_payload(open(self.filename).read())
#         email.encoders.encode_base64(file_msg)
#         file_msg.add_header("Content-Disposition", "attachment;filname=photo.jpg")
#         msg.attach(file_msg)
# 
#         with open(auth_file) as fh:
#             auth = pickle.load(fh)
#             auth = auth["smtp"]
# 
#         with open("email.log", "a") as fh:
#             fh.write("{}\t{}\n".format(self.address, self.filename))
# 
#         smtpout = smtplib.SMTP(auth["host"])
#         smtpout.login(auth["username"], auth["password"])
#         smtpout.sendmail(sender, [self.address], msg.as_string())
#         smtpout.quit()


# Path: tailor/uix/sharing.py
import os.path
from functools import partial
from kivy.config import Config
from kivy.network.urlrequest import UrlRequest
from kivy.properties import *
from kivy.uix.accordion import AccordionItem
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from ..config import pkConfig
from ..smtp import SenderThread
    from PIL import Image
        from kivy.core.window import Window

            widget.on_touch_up = derp
            widget.on_touch_motion = derp

    def do_print(self):
        filename = self.filename[self.filename.rindex("/") + 1 :]
        url = "http://127.0.0.1:5000/print/" + filename
        for i in range(self.prints):
            req = UrlRequest(url, print)

    def handle_print_touch(self, popup, widget):
        popup.dismiss()

        self.do_print()

        layout = BoxLayout(orientation="vertical")
        label = Label(text="Your prints will be ready soon!", font_size=30)
        button = Button(text="Awesome!", font_size=30, background_color=(0, 1, 0, 1))
        layout.add_widget(label)
        layout.add_widget(button)

        popup = Popup(
            title="Just thought you should know...",
            content=layout,
            size_hint=(0.5, 0.5),
        )

        button.bind(on_release=popup.dismiss)
        popup.open()

    def do_email(self, popup, address, filename, widget):

        thread = SenderThread(address, filename)