示例#1
0
#!/usr/bin/python3

import time

import AdminServer
import Clock
import Radio
import LED

AdminServer.start_in_background()
try:
    from display.OledDisplay import OledDisplay
    display = OledDisplay()
except ModuleNotFoundError:
    from display.Display import Display
    display = Display()

display.set_contrast(0)
try:
    while True:
        display.clear()
        Clock.update()
        time_str = Clock.get_time()
        alarm = Clock.get_alarm()
        alarm_str = f'{str(alarm.hour).zfill(2)}:{str(alarm.minute).zfill(2)} [{Clock.get_days_str(alarm.day_of_week)}]'

        display.draw_text((20, 0), time_str, font=display.big_font)
        if Clock.maybe_trigger_alarm() and not Radio.is_playing():
            volume = Radio.get_volume()
            Radio.set_volume(0)
            if not Radio.play_radio(triggered_by_alarm=alarm):
示例#2
0
    def endElement(self, name):

        oname, attrs = self.__nesting_stack.pop()
        state = self.__state[-1]
        if (not name == oname):
            # nesting errors in XML are detected by the SAX parser; if we
            # get here, it means our parser is buggy, not the XML input
            log("Nesting error: expected %s, got %s." % (oname, name))
            return


        elif (state == _STATE_DISPLAY):
            settings = self.__create_settings(attrs)
            # if there is no ID given, guess a unique one
            ident = attrs.get("id", Display.make_id())
            settings["id"] = ident

            # build the tree of children from bottom up
            children = self.__children_stack.pop()
            self.__children_stack[-1].append((name, settings, children))

        elif (state == _STATE_META):
            self.__metadata = attrs

        elif (state == _STATE_SCRIPT):
            # Some distros ship a broken SAX parser and
            # their users are too lazy to reportbug. (doesn't have __contains__)
            # So we have to use has_key()
            # if ((name == "script") and ("uri" in attrs)):
            if (name == "script" and attrs.has_key("uri")):
                path = attrs["uri"]
                filename = os.path.join(self.__path, path)
                try:
                    self.__script += "\n" + vfs.read_entire_file(filename)
                except:
                    log("File doesn't exist or couldn't be loaded: %s"
                        % (path,))
                    dialog.warning(_("File doesn't exist or couldn't be "
                                     "loaded"),
                                   _("A file which contains a script isn't "
                                     "available for further execution."))
            else:
                filename = self.__filename

            # collect script by script to be able to execute them one by one
            # later; we would get problems with different indentation otherwise
            self.__scripts.append((self.__script, filename))

        # deprecated sensor stuff
        elif (state == _STATE_SENSOR):
            from utils import typeconverter
            ident = attrs["id"]
            moduledata = typeconverter.str2type(TYPE_LIST, attrs["module"])
            module = moduledata[0]
            args = moduledata[1:]
            sensorctrl = self.__control_factory.get_control(_SENSOR_CONTROL)

            if (sensorctrl):
                sensorctrl.sensor = (module, args)
                sensorctrl.config_id = self.__id + ident
                self.__sensors.append((ident, sensorctrl))
            else:
                raise RuntimeError(_("Could not load sensor"))

        elif (state == _STATE_CONTROL):
            ident = attrs["id"]
            interface = attrs["interface"]
            
            if not attrs.has_key("length"):
                attrs["length"] = "0"
            length = int(attrs["length"])

            script = "%s = get_control('%s', %d)" % \
                     (ident, interface, length)
            self.__scripts.append((script, self.__filename))

        elif (state == _STATE_PREFS):
            if (name == "prefs"):
                pass
            else:
                if (name in ("boolean", "color", "date", "enum", "float", "font",
                             "integer", "list", "radio", "string", "toggle", "uri")
                    and not attrs.has_key("bind")):
                    dialog.warning(_("<%s> needs a bind attribute") % \
                                                                      (name,),
                                   _("The <prefs> section of this "
                                     "desklet file is broken."))
                    raise AttributeError("<%s> needs a bind attribute" % \
                                                                      (name,))

                # use global prefs callback if no callback was given
                if (self.__prefs_callback and not attrs.has_key("callback")):
                    attrs["callback"] = self.__prefs_callback

                self.__config_items.append((name, attrs))


        if (name in ("display", "sensor", "control", "meta",
                     "prefs", "script")):
            self.__state.pop()
示例#3
0
    def __handle_open_display(self, callback, path):

        ident = Display.make_id()
        self.__handle_open_display_with_id(callback, path, ident)