Ejemplo n.º 1
0
def _init():
    def create_beep(Hz, last):
        def __func_bepp():
            winsound.Beep(Hz, last)

        return __func_bepp

    import time

    def create_sleep(last):
        def __func_sleep():
            time.sleep(last)

        return __func_sleep

    import data
    from initUtil import warn
    import sine.propertiesReader as reader

    # 读入beep样式信息
    beep_filename = 'beep.conf'
    default_pattern = [(600, 50), (200, ), (600, 50), (300, )]
    lines = []
    try:
        data.useDefault(data.data['location'], beep_filename)
        lines = reader.readAsList(data.data['location'].join(beep_filename))
    except Exception, e:
        warn('load beep pattern from file', beep_filename,
             'failed, will use default value.', e)
        beep_pattern = default_pattern
Ejemplo n.º 2
0
def _init():
    def boolConverter(s):
        '''对空或者0开头的字符串视为False,其余视为True'''
        if s == '' or s.startswith('0'):
            return False
        return True

    import sine.propertiesReader as reader
    from sine.path import Path
    from initUtil import warn

    location = Path(__file__).join('..')
    data['location'] = location

    # 从文件读入全局配置,暂时保存为字符串
    conf_filename = 'clock.conf'
    allMiss = False
    config = {}
    try:
        useDefault(location, conf_filename)
        config = reader.readAsDict(location.join(conf_filename))
    except Exception, e:
        warn('load config from file', conf_filename, 'failed, will use default value.', e)
        allMiss = True
Ejemplo n.º 3
0
        data['clocks'] = []
        with open(_data_filepath, 'a+') as file:
            for line in file:
                data['clocks'].append(eval(line))
    except Exception, e:
        print 'load data from file', _data_filepath, 'failed.', e
        import sys
        sys.exit(1)

    # 检查音频文件是否存在
    from player import isLegal
    from exception import ClientException
    from initUtil import warn
    for clock in data['clocks']:
        if not isLegal(clock['sound']):
            warn('illeagal sound \'' + clock['sound'] + '\' of', clock, '.')
    if not isLegal(data['config']['default_sound']):
        warn('default sound illeagal, will use default beep.', e)
        data['config']['default_sound'] = 'default'

def getReminds():
    '''供Output提示'''
    reminds = []
    now = getNow()
    for clock in data['clocks']:
        if clock.checkRemind(now):
            reminds.append(clock)
    return reminds

@synchronized('clocks')
def add(clock):
Ejemplo n.º 4
0
def _taskbar(stop_event):
    import time
    while 1:
        if stop_event.is_set():
            break
        _flash()
        time.sleep(1)
    return


try:
    if config['taskbar_flash']:
        from sine.flashWindow import flash as _flash
        _taskbarThread = _ReStartableThread(target=_taskbar)
except ImportError, e:
    warn('taskbar flashing not supported.', e)
finally:
    if '_taskbarThread' not in locals():
        _taskbarThread = _ReStartableThread(target=None)

tokens = config['screen_flash_mode']


def _screen(stop_event):
    import manager
    from sine.helpers import cls
    import time
    import formatter
    fmt = formatter.create(config, config['flash_format'])
    sleep_len = 1.0 / len(tokens)
    pos = 0
Ejemplo n.º 5
0
    ('default_remindAhead', 60, int),
    ('default_sound', 'default', None),
    ('format', '%Y-%m-%d %H:%M:%S %%warn %%3idx %%3state %%msg', None),
    ('flash_format', '%Y-%m-%d %H:%M:%S %%msg', None),
    ('warn', '!!!', None),
    ('state.ON', 'ON', None),
    ('state.OFF', 'OFF', None),
    ('datafile', 'clocks.txt', None)]

    if allMiss:
        for (key, default, converter) in default_config:
            config[key] = default
    else:
        for (key, default, converter) in default_config:
            if not config.has_key(key):
                warn('missing config \'' + key + '\', will use default value \'' + str(default) + '\'.')
                config[key] = default
            elif converter:
                try:
                    config[key] = converter(config[key])
                except Exception, e:
                    warn('parsing config \'' + key + '=' + str(config[key]) + '\' failed, will use default value \'' + str(default) + '\'.', e)
                    config[key] = default

    data['config'] = config

    # 读入日期和时间格式配置
    format_filename = 'time.conf'
    try:
        useDefault(location, format_filename)
        config = reader.readAsList(location.join(format_filename))
Ejemplo n.º 6
0
                    if (duration <= 0):
                        raise ClientException(
                            'duration must be positive, but meet ' + duration)
                    if (duration > 10000):
                        raise ClientException(
                            'duration is too big, more than 10000, but meet ' +
                            duration)
                    beep_pattern.append((frequency, duration))
                else:
                    last = int(array[0].strip())
                    if (last <= 0):
                        raise ClientException(
                            'last must be positive, but meet ' + last)
                    beep_pattern.append((last, ))
    except Exception, e:
        warn('parse beep pattern failed, will use default value.', e)
        beep_pattern = default_pattern

    for s in beep_pattern:
        if len(s) > 1:
            _list.append(create_beep(s[0], s[1]))
        else:
            _list.append(create_sleep(s[0] / 1000.0))


_init()


def _alarm(stop_event):
    while 1:
        for func in _list: