# Path: pyrikura/smtp.py
# class SenderThread(threading.Thread):
#     def __init__(self, address, filename):
#         threading.Thread.__init__(self)
#         self.address = address
#         self.filename = filename
# 
#     def run(self):
#         sender = pkConfig.get('email', 'sender')
#         subject = pkConfig.get('email', 'subject')
#         auth_file = '/home/mjolnir/git/PURIKURA/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: pyrikura/config.py
# def reload(path):


import shutil
from functools import partial
from kivy.uix.accordion import Accordion
from kivy.uix.accordion import AccordionItem
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.properties import *
from ..smtp import SenderThread
from ..config import Config as pkConfig
        from kivy.core.window import Window




MAXIMUM_PRINTS = pkConfig.getint('kiosk', 'max-prints')


def handle_print_number_error(value):
    if value < 1:
        return 1
    elif value > MAXIMUM_PRINTS:
        return MAXIMUM_PRINTS


class IconAccordionItem(AccordionItem):
    icon_source = StringProperty()
    icon_size = ListProperty()


class SharingControls(FloatLayout):
    prints = BoundedNumericProperty(1, min=1, max=MAXIMUM_PRINTS,
                                    errorhandler=handle_print_number_error)

    email_addressee = StringProperty('')
    twitter_acct = StringProperty(

# Path: pyrikura/smtp.py
# class SenderThread(threading.Thread):
#     def __init__(self, address, filename):
#         threading.Thread.__init__(self)
#         self.address = address
#         self.filename = filename
# 
#     def run(self):
#         sender = pkConfig.get('email', 'sender')
#         subject = pkConfig.get('email', 'subject')
#         auth_file = '/home/mjolnir/git/PURIKURA/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: pyrikura/config.py
# def reload(path):


# Path: pyrikura/uix/sharing.py
import shutil
from functools import partial
from kivy.uix.accordion import Accordion
from kivy.uix.accordion import AccordionItem
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.properties import *
from ..smtp import SenderThread
from ..config import Config as pkConfig
        from kivy.core.window import Window





MAXIMUM_PRINTS = pkConfig.getint('kiosk', 'max-prints')


def handle_print_number_error(value):
    if value < 1:
        return 1
    elif value > MAXIMUM_PRINTS:
        return MAXIMUM_PRINTS


class IconAccordionItem(AccordionItem):
    icon_source = StringProperty()
    icon_size = ListProperty()


class SharingControls(FloatLayout):
    prints = BoundedNumericProperty(1, min=1, max=MAXIMUM_PRINTS,
                                    errorhandler=handle_print_number_error)

    email_addressee = StringProperty('')
    twitter_acct = StringProperty(

        pkConfig.get('twitter', 'account')