예제 #1
0
파일: Battery.py 프로젝트: dzeban/batti-gtk
 def __init__(self):
     self.__systray = gtk.StatusIcon()
     self.__notifer = Notificator()
     
     self.__shown_charging = False
     self.__shown_on_bat = False
     self.__shown_bat_low = False
     self.__shown_bat_critical = False
     self.__shown_bat_charged = False
     self.__show_notify = True
     
     self._set_icon_visibility(True)
예제 #2
0
    def start(self):
        # Do not change
        width = 352
        height = 352
        # output to capture image
        output = np.empty((height, width, 3), dtype=np.uint8)
        # Init camera
        camera = Camera(width, height)
        # Init image saver
        imageSaver = ImageSaver()
        # Init model
        model = self.getModel()
        # Init notificator
        notificator = Notificator()
        # Start predicting
        tempCount = 1
        while True:
            #print("Step...")
            #start = time.time()
            # Capture image to output
            camera.capture(output)
            imageToCrop = Image.fromarray(output)
            image = self.cropImage(imageToCrop, 110, 87, 224)
            tempName = 'temp{}.jpg'.format(tempCount)
            image.save(tempName)
            tempCount += 1
            if tempCount > Notificator.PREDICTIONS_LENGTH:
                tempCount = 1
            # Predict
            prediction = model.predict(imagePath=tempName)
            # Save image to disk with label and probability
            imageSaver.save(image, prediction)
            # Manage Notification
            notificator.manageNotification(prediction)
            #print("Step took {} seconds".format(time.time()-start))

        camera.close()
예제 #3
0
파일: Battery.py 프로젝트: dzeban/batti-gtk
class Battery(object):
    
    def __init__(self):
        self.__systray = gtk.StatusIcon()
        self.__notifer = Notificator()
        
        self.__shown_charging = False
        self.__shown_on_bat = False
        self.__shown_bat_low = False
        self.__shown_bat_critical = False
        self.__shown_bat_charged = False
        self.__show_notify = True
        
        self._set_icon_visibility(True)
        
        
    def __del__(self):
        self._set_icon_visibility(False)
        del self.__systray
    
    
    def destroy(self):
        self.__del__()
    
        
    def update(self):
        pass
    
    
    def set_left_popup_menu_action(self, menu_action):
        self.__systray.connect('button_press_event', menu_action)
  
  
    def set_value(self, info):
        
        self._set_icon_visibility(info._present)
        
        if info._time == 0:
            tooltip = _("Battery level: %s%%") % (info._percentage)
            notification = tooltip
        else:
            time_str = self._str_time(info._time)
            tooltip = _('Battery level: %(level)s%%\nProviding power for approximately %(time)s') % {'level': info._percentage, 'time': time_str}
            notification = _('Power for approximately <b>%s</b> remaining') % time_str
        
        if info._state == STATE_CHARGING:
            self.__systray.set_blinking(False)
            self.__systray.set_tooltip(_('Charging battery\nBattery level: %s%%') % info._percentage)
            if info._percentage > 80:
                icon = 'battery-full-charging'
            elif info._percentage > 40:
                icon = 'battery-good-charging'
            elif info._percentage > 20:
                icon = 'battery-low-charging'
            else:
                icon = 'battery-caution-charging'
            self.__set_tray_icon(icon)
            
            self.__shown_bat_charged = False
            if not self.__shown_charging:
                self.__shown_bat_critical = False
                self.__shown_bat_low = False
                self.__shown_charging = True
                self.__shown_on_bat = False
                self._notify(False, icon, _('Charging battery'), notification)
                
        elif info._state == STATE_DISCHARGING:
            self.__systray.set_tooltip(tooltip)
            if info._percentage > 80:
                icon = 'battery-full'
            elif info._percentage > 40:
                icon = 'battery-good'
            elif info._percentage > 20:
                icon = 'battery-low'
            elif info._percentage > 5:
                icon = 'battery-caution'
                if not self.__shown_bat_low:
                    self._notify(True, icon, _('Low battery level'), notification)
                    self.__shown_bat_low = True
            else:
                icon = 'battery-empty'
                self.__systray.set_blinking(True)
                if not self.__shown_bat_critical:
                    self._notify(True, icon, _('Critical battery level'), notification)
                    self.__shown_bat_critical = True
            self.__set_tray_icon(icon)
            self.__shown_bat_charged = False
            if not self.__shown_on_bat:
                self._notify(False, icon, _("Discharging battery"), notification)
                self.__shown_charging = False
                self.__shown_on_bat = True
                    
        elif info._state == STATE_CHARGED:
            self.__systray.set_tooltip(_('Battery charged\n%s') % tooltip)
            self.__set_tray_icon('battery-full')
            self.__systray.set_blinking(False)
            if not self.__shown_bat_charged:
                self._notify(False, 'battery-full-charging', _('Battery charged'), notification)
                self.__shown_bat_charged = True
                     
    
    def __set_tray_icon(self, icon_name):
        self.__systray.set_from_icon_name(icon_name)
    
    
    def _set_icon_visibility(self, visible):
        self.__systray.set_visible(visible)
    
        
    def _notify(self, urgent, icon, subject, msg):
        if self.__show_notify:
            posrect = self.__systray.get_geometry()[1]
            posx = posrect.x + posrect.width/2
            posy = posrect.y + posrect.height
            self.__notifer.setPosition(posx, posy)
            if urgent:
                self.__notifer.show_urgent(icon, subject, msg)
            else: 
                self.__notifer.show(icon, subject, msg)
    
    
    def set_notification_enabled(self, enabled):
        self.__show_notify = enabled
        
        
    def get_notification_enabled(self):
        return self.__show_notify
    
    
    def _str_time(self, seconds):
        if seconds < 0:
            return _('unknown time')
       
        minutes = seconds / 60
        hours = minutes / 60
        minutes = minutes % 60                    
       
        #FIXME: The string below needs to be i18n-ized properly
        return self._format_time(hours, _('Hour'), _('Hours')) + " " + self._format_time(minutes, _('Minute'), _('Minutes'))


    def _format_time(self, time, singular, plural):
        if time == 0:
            return ""
        elif time == 1:
            return "1 %s" % singular
        else:
            return "%s %s" % (time, plural)
예제 #4
0
import time
from getpass import getpass
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from SubscriberGroups import Subscriber
from Websites import LoginWebsite, ScrapableWebsite
from Notificator import Notificator

#senderMail = input("Please enter the email for sending notifications:\n")
senderMail = "*****@*****.**"
#senderPassword = getpass("Please enter the password:\n")
senderPassword = "******"
mailman = Notificator(senderMail, senderPassword)
scrapableSitesList = list()
while (True):
    scrapableSitesList = ScrapableWebsite.generateList(scrapableSitesList)
    loginSitesList = LoginWebsite.generateList()
    for site in scrapableSitesList:
        if (site.currentState == " "):
            if (site.newPageRequest(loginSitesList) == True):
                break
            print("Added new site")
        else:
            if (site.compareStates(loginSitesList, mailman) == True):
                break
            pass
    timestamp = time.strftime("%H:%M:%S", time.localtime())
    print("\n****************  {0}  *****************\n".format(timestamp))
    time.sleep(300)
print("How the f**k did I get here?")