示例#1
0
def meterClicked(widget, meter, button):
    """ This gets called when a meter (image, text, etc) is clicked.
        NOTE you must use attachClickArea() to make a meter
        clickable.
          widget = reference to your theme
          meter = the meter clicked
          button = the button clicked
    """
    global active
    global raised_alarm
    global curtime

    if meter == startButton:
        if active == 0:
            print "startButton"
            karamba.showBar(widget, progressBar)
            if zerotime.time < alarmtime.time:
                karamba.setBarMinMax(widget, progressBar, \
                                     zerotime.time, alarmtime.time)
            else:
                karamba.setBarMinMax(widget, progressBar, \
                                     alarmtime.time, zerotime.time)
            karamba.setBarValue(widget, progressBar, curtime.time)
            karamba.hideImage(widget, done)
            karamba.setImagePath(widget, startButton, "img/startpause.png")
            karamba.setImagePath(widget, endButton, "img/stoppause.png")
            active = 1
        else:
            print "startButton (Pause)"
            karamba.setImagePath(widget, startButton, "img/start.png")
            karamba.setImagePath(widget, endButton, "img/stop.png")
            active = 0
    elif meter == endButton:
        if active == 0:
            print "endButton"
            curtime = zerotime.copy()
            showTime(widget, curtime)
            karamba.showImage(widget, done)
            karamba.hideBar(widget, progressBar)
            curtimefh = open(curtimefile, "w")
            curtimefh.write(str(curtime))
            curtimefh.close()
            karamba.setImagePath(widget, startButton, "img/start.png")
            karamba.setImagePath(widget, endButton, "img/stop.png")
            raised_alarm = False
        else:
            print "endButton (Pause)"
            karamba.setImagePath(widget, startButton, "img/start.png")
            karamba.setImagePath(widget, endButton, "img/stop.png")
            active = 0
    elif meter == done:
        print "done"
        alarmtime.from_string(getValue(widget, "Alarm Time", str(alarmtime)))
        karamba.writeConfigEntry(widget, "alarmtime", str(alarmtime))
    else:
        print "anotherbutton"
示例#2
0
def initWidget(widget):
    """ This is called when your widget is initialized"""
    global startButton
    global endButton
    global progressBar
    global curtimefile
    global done      # "done" image widget
    global hours     # these ...
    global minutes   # ... are the...
    global seconds   # widget texts


    # initialize handlers to all meters
    hours = karamba.getThemeText(widget, "hours")
    seconds = karamba.getThemeText(widget, "seconds")
    minutes = karamba.getThemeText(widget, "minutes")
    progressBar = karamba.getThemeBar(widget, "progress")
    karamba.hideBar(widget, progressBar)
    startButton = karamba.getThemeImage(widget, "start")
    karamba.attachClickArea(widget, startButton, "", "", "")
    endButton = karamba.getThemeImage(widget, "end")
    karamba.attachClickArea(widget, endButton, "", "", "")
    done = karamba.getThemeImage(widget, "done")
    karamba.attachClickArea(widget, done, "", "", "")

    # read data from config file
    zerotime_str = str(karamba.readConfigEntry(widget, "zerotime"))
    print "zerotime from config: %s" % zerotime_str
    zerotime.from_string(zerotime_str)
    alarmtime_str= str(karamba.readConfigEntry(widget, "alarmtime"))
    print "alarmtime from config: %s" % alarmtime_str
    alarmtime.from_string(alarmtime_str)


    # set time from last used time
    curtimefile =  os.path.join(os.environ['HOME'], \
                                '.superkaramba', \
                                'stoptimer', \
                                'curtime')
    if os.path.isfile(curtimefile):
        curtimefh = open(curtimefile)
        curtimestring = curtimefh.read()
        curtime.from_string(curtimestring)
        curtimefh.close()
    else:
        if not os.path.isdir( \
         os.path.join(os.environ['HOME'], '.superkaramba')):
            os.mkdir(os.path.join(os.environ['HOME'], '.superkaramba'))
        if not os.path.isdir( \
        os.path.join(os.environ['HOME'], '.superkaramba', 'stoptimer')):
            os.mkdir(os.path.join( \
                     os.environ['HOME'], '.superkaramba', 'stoptimer'))

    showTime(widget, curtime)
示例#3
0
def widgetUpdated(widget):
    global bars, b
    
    # vertical & bitmap
    b = karamba.getBarVertical(widget, bars[7])
    print "getVertical: " + str(b)
    bmp = karamba.getBarImage(widget, bars[7])
    print "getBitmap: " + str(bmp)
    b = (b+1)%2
    karamba.setBarVertical(widget, bars[7], b)
    if(b):
      karamba.setBarImage(widget, bars[7], "ver.png")
      karamba.resizeBar(widget, bars[7], 20, 200)
    else:
      karamba.setBarImage(widget, bars[7], "hor.png")
      karamba.resizeBar(widget, bars[7], 200, 20)

    # size & resize
    size = karamba.getBarSize(widget, bars[1])
    print "getBarSize: " + str(size)
    size = ((b * 100) + 100, size[1])    
    karamba.resizeBar(widget, bars[1], size[0], size[1])
    
    # pos & move
    pos = karamba.getBarPos(widget, bars[2])
    print "getBarPos: " + str(pos)
    pos = (b * 200, pos[1])    
    karamba.moveBar(widget, bars[2], pos[0], pos[1])
    
    # Hide & Show
    if(b):
      karamba.hideBar(widget, bars[3])
    else:
      karamba.showBar(widget, bars[3])
    
    # Value
    v = karamba.getBarValue(widget, bars[5])
    print "getBarValue: ", v
    v = (v + 10) % 110
    karamba.setBarValue(widget, bars[5], v)
    
    # Min Max
    minmax = karamba.getBarMinMax(widget, bars[6])
    print "getBarMinMax: " + str(minmax)
    minmax = (0, (b * 100) + 100)    
    karamba.setBarMinMax(widget, bars[6], minmax[0], minmax[1])
    
    # Sensor
    sensor = karamba.getBarSensor(widget, bars[4])
    print "getSensor: " + str(sensor)
    if(b):
      karamba.setBarSensor(widget, bars[4], 'SENSOR=SENSOR TYPE="cpu_temp"')
    else:
      karamba.setBarSensor(widget, bars[4], 'SENSOR=CPU')
      
    # Create & delete
    if(bars[0]):
      karamba.deleteBar(widget, bars[0])
      bars[0] = 0
    else:
      bars[0] = karamba.createBar(widget, 0, 20, 200, 20)
      karamba.setBarImage(widget, bars[0], "hor.png")
      karamba.setBarValue(widget, bars[0], 100)