Esempio n. 1
0
    def __init__(self):
        self.sta_if = WLAN(STA_IF)
        self.settings = Settings().load()
        self.credentials = Credentials().load()

        self.wifi = WifiManager(b"%s-%s" % (PUBLIC_NAME, self.settings.net_id))
        self.mdns = mDnsServer(PUBLIC_NAME.lower(), self.settings.net_id)

        routes = {
            b"/": b"./index.html",
            b"/index.html": b"./index.html",
            b"/scripts.js": b"./scripts.js",
            b"/style.css": b"./style.css",
            b"/favicon.ico": self.favicon,
            b"/connect": self.connect,
            b"/action/previous": self.previous,
            b"/action/next": self.next,
            b"/settings/values": self.settings_values,
            b"/settings/net": self.settings_net,
            b"/settings/group": self.settings_group,
        }

        self.http = HttpServer(routes)
        print("> HTTP server up and running")

        self.sign = Sign()

        self.loop = get_event_loop()
        self.loop.create_task(self.check_wifi())
        self.loop.run_forever()
        self.loop.close()
Esempio n. 2
0
def DoTasker():
    lstUserData = Data.laodUserData()
    emails = []
    for d in lstUserData:
        login = Login(d[0], d[1])
        skey, reason = login.autologin()
        if skey == False:
            # 签到失败,删除用户信息,发送邮件提醒
            email = Data.getUserEmailData(d[0])
            if email != None and len(email) > 0:
                emails.append(email)
            Data.removeUserData(d[0])
            Data.removeUserEmailData(d[0])
        sign = Sign(d[0], skey)
        if sign.autosign() == False:
            pass
        # time.sleep(1)
    # print emails
    if len(emails) > 0:
        email = libs.mail.Message(Config.smtp_user, emails, Config.mail_notify)
        try:
            conn = libs.mail.Connection(Config.smtp_server, 25, Config.smtp_user, Config.smtp_pass)
            conn.send_message(email)
        except:
            pass
Esempio n. 3
0
def DoTasker():
    lstUserData = Data.laodUserData()
    emails = []
    for d in lstUserData:
        login = Login(d[0], d[1])
        skey, reason = login.autologin()
        if skey == False:
            #签到失败,删除用户信息,发送邮件提醒
            email = Data.getUserEmailData(d[0])
            if email != None and len(email) > 0:
                emails.append(email)
            Data.removeUserData(d[0])
            Data.removeUserEmailData(d[0])
        sign = Sign(d[0], skey)
        if sign.autosign() == False:
            pass
        #time.sleep(1)
    #print emails
    if len(emails) > 0:
        email = libs.mail.Message(Config.smtp_user, emails, Config.mail_notify)
        try:
            conn = libs.mail.Connection(Config.smtp_server, 25,
                                        Config.smtp_user, Config.smtp_pass)
            conn.send_message(email)
        except:
            pass
 def __init__(self,pos = (0,0)):
     images = [("ResourceBar.png", 'alpha')]
     self.baseLayer = DrawableObjectGroup(images,pos=pos)
     self.offset = (30,3)
     self.textField = Sign(200, (pos[0]+self.offset[0],pos[1]+self.offset[1]),fsize = 20)
     self.textField.tcolor=(180,180,0)
     self.setResourceCount(0)
 def drawInfo(self, screen): #FIXME I am shitty.
     """Displays health and description"""
     text = '%s \n Description: \n %s' % (self.healthStr(), self.description)
     textBox=Sign(150, (0, 600), image=self.image)
     textBox.addtext(text)
     textBox.render()
     textBox.draw(screen)
class ResourceBar():
    """
    A bar at the top of the screen indicating the amount of resources the player has on the current world

    @param baseLayer: background image
    @type baseLayer: DrawableObjectGroup(list(tuple(str,  str)), tuple(int, int))

    @param offset: position of amount of resource relative to ResourceBar
    @type offset: tuple(int, int)

    @param textField: Displays amount of resources own
    @type textField: Sign

    @param value: amount of resource owned
    @type value: int
    """
    def __init__(self,pos = (0,0)):
        images = [("ResourceBar.png", 'alpha')]
        self.baseLayer = DrawableObjectGroup(images,pos=pos)
        self.offset = (30,3)
        self.textField = Sign(200, (pos[0]+self.offset[0],pos[1]+self.offset[1]),fsize = 20)
        self.textField.tcolor=(180,180,0)
        self.setResourceCount(0)

    def setResourceCount(self,val=0):
        self.value = val
        self.textField.clear()
        self.textField.addtext(str(self.value))

    def draw(self,screen):
        #FIXME Add font here
        self.baseLayer.draw(screen)
        self.textField.render(screen)
 def __init__(self,pos = (0,768-36-186)):
      #FIXME Remove this dependency - replace image with thumbnail
     from Overlay import Bar
     #Format for each tuple is (imagePath, [colorKey, [offset]])
     images = [("BarTop.png",'alpha')]
     images.append(("BarRight.png",'alpha',(325,36)))
     images.append(("DescBoxCentral.png",None,(0,36)))
     self.baseLayer = DrawableObjectGroup(images,pos=pos)
     self.entity = None
     self.descriptionOffset = (35,73+36)
     self.description = Sign(260, (pos[0]+self.descriptionOffset[0],pos[1]+self.descriptionOffset[1]),fsize = 18)
     self.description.tcolor=(180,180,0)
     self.pos = pos
     self.thumbnailOffset = (12,14+36)
 def getInfo(self):
     text = '%s \n Description: \n %s' % (self.healthStr(), self.description)
     textBox=Sign(150, (0,0))
     textBox.addtext(text)
     textBox.render()
     return textBox
Esempio n. 9
0
class Main:
    def __init__(self):
        self.sta_if = WLAN(STA_IF)
        self.settings = Settings().load()
        self.credentials = Credentials().load()

        self.wifi = WifiManager(b"%s-%s" % (PUBLIC_NAME, self.settings.net_id))
        self.mdns = mDnsServer(PUBLIC_NAME.lower(), self.settings.net_id)

        routes = {
            b"/": b"./index.html",
            b"/index.html": b"./index.html",
            b"/scripts.js": b"./scripts.js",
            b"/style.css": b"./style.css",
            b"/favicon.ico": self.favicon,
            b"/connect": self.connect,
            b"/action/previous": self.previous,
            b"/action/next": self.next,
            b"/settings/values": self.settings_values,
            b"/settings/net": self.settings_net,
            b"/settings/group": self.settings_group,
        }

        self.http = HttpServer(routes)
        print("> HTTP server up and running")

        self.sign = Sign()

        self.loop = get_event_loop()
        self.loop.create_task(self.check_wifi())
        self.loop.run_forever()
        self.loop.close()

    async def check_wifi(self):
        while True:
            await sleep_ms(2000)

            while not self.sta_if.isconnected():
                await sleep_ms(1000)

            while self.sta_if.isconnected():
                await sleep_ms(1000)

    def settings_values(self, params):
        essid = self.credentials.essid

        if not essid:
            essid = b""

        result = b'{"ip": "%s", "netId": "%s", "group": "%s", "essid": "%s"}' % (
            self.wifi.ip,
            self.settings.net_id,
            self.settings.group,
            essid,
        )

        return result

    def favicon(self, params):
        print("> NOT sending the favico :-)")

    def connect(self, params):
        self.credentials.essid = params.get(b"essid", None)
        self.credentials.password = params.get(b"password", None)
        self.credentials.write()

        self.loop.create_task(self.wifi.connect())

    def previous(self, params):
        self.sign.previous()

    def next(self, params):
        pass
        self.sign.next()

    def settings_net(self, params):
        id = params.get(b"id", None)

        if id:
            self.settings.net_id = id
            self.settings.write()
            self.mdns.set_net_id(id)

            self.wifi.set_ap_essid(b"%s-%s" % (PUBLIC_NAME, id))
            self.mdns.set_net_id(id)

    def settings_group(self, params):
        name = params.get(b"name", None)

        if name:
            self.settings.group = name
            self.settings.write()
class DescriptionBox():
    """
    The largest HUD element which describes the hovered unit
    and its properties (those which are player-relevant)

    @param baseLayer:  background image
    @type baseLayer: DrawableObjectGroup(list(tuple(str,  str)), tuple(int, int))

    @param entity: Entity whose information is being displayed
    @type entity: Entity

    @param descriptionOffset: position of description of entity relative to DescriptionBox
    @type descriptionOffset: tuple(int, int)

    @param description: Text description of entity
    @type descritpion: Sign

    @param pos: position of DescriptionBox on screen
    @type pos: tuple(int, int)

    @param thumbnailOffset: position of thumbnail relative to DescriptionBox
    @type thumbnailOffset: tuple(int, int)
    """
    def __init__(self,pos = (0,768-36-186)):
         #FIXME Remove this dependency - replace image with thumbnail
        from Overlay import Bar
        #Format for each tuple is (imagePath, [colorKey, [offset]])
        images = [("BarTop.png",'alpha')]
        images.append(("BarRight.png",'alpha',(325,36)))
        images.append(("DescBoxCentral.png",None,(0,36)))
        self.baseLayer = DrawableObjectGroup(images,pos=pos)
        self.entity = None
        self.descriptionOffset = (35,73+36)
        self.description = Sign(260, (pos[0]+self.descriptionOffset[0],pos[1]+self.descriptionOffset[1]),fsize = 18)
        self.description.tcolor=(180,180,0)
        self.pos = pos
        self.thumbnailOffset = (12,14+36)

    def updateDisplayedEntity(self,entity):
        """
        Changes entity displayed
        """
        import pygame
        from Overlay import Bar
        self.entity = entity
        self.thumbnail = self.entity.getDefaultImage()
        self.thumbnail = pygame.transform.scale(self.thumbnail, (44, 44))
        self.description.clear()
        self.description.addtext(entity.description)
        self.healthBar = Bar(self.entity.maxHealth,118,6,fullColor=(0,255,0),emptyColor=(30,30,30)) 

    def draw(self,screen):
        self.baseLayer.draw(screen)
        if self.entity:
            self.healthBar.updateBarWithValue(self.entity.curHealth)

            #if entity is building something, displays
            #building status
            if hasattr(self.entity,'currentTask'):
                if self.entity.currentTask:
                    if hasattr(self.entity.currentTask,'timeSpentBuilding'):
                        from Overlay import Bar
                        self.buildBar = Bar(self.entity.currentTask.timeToBuild,118,6,fullColor=(0,180,255),emptyColor=(30,30,30))
                        self.buildBar.updateBarWithValue(self.entity.currentTask.timeSpentBuilding)
                        self.buildBar.draw(screen,(self.pos[0]+78,self.pos[1]+69))
            
            screen.blit(self.thumbnail, (self.pos[0]+self.thumbnailOffset[0],self.pos[1]+self.thumbnailOffset[1]))
            self.healthBar.draw(screen,(self.pos[0]+78,self.pos[1]+56))
            
            self.description.render(screen)
 def __init__ (self, text='This is a Notification. Consider yourself notified.', pos=(0,0), color=(255, 255, 0), width=200, time=5):
     Sign.__init__(self, width, pos)
     self.addtext(text)
     self.tcolor=color
     self.timeLeft=time*1000
Esempio n. 12
0
import sys, os
sys.path.append(os.path.abspath('../Network'))
import LedBurnProtocol as network
import time

from operator import itemgetter, attrgetter, methodcaller

sys.path.append(os.path.abspath('../UIElements'))
from Flower import Flower
flower = Flower()
from SmallSheep import SmallSheep
sheep = SmallSheep()
from Grass import Grass
grass = Grass()
from Sign import Sign
sign = Sign()

from FireScene import FireScene
from RoundRobinScene import RoundRobinScene
scene = RoundRobinScene(flower, sheep, grass, sign)

speed = 25  # in 50 hrz
current_time = 0
frame_id = 0

while True:

    time_precent = float(current_time) / speed

    scene.apply(time_precent)