Exemple #1
0
def read_zerotime(widget):
    global curtime
    print "read_zerotime"
    zerotime.from_string(getValue(widget, "Initial Time", str(zerotime)))
    karamba.writeConfigEntry(widget, "zerotime", str(zerotime))
    curtime = zerotime.copy()
    showTime(widget, curtime)
Exemple #2
0
def commandOutput(widget, pid, output):
    global chtheme_pid, procoutformat_pid, align_pid
    value = output.strip()

    if pid == chtheme_pid:
        if value != "":
            print "Changing theme to " + value
            karamba.writeConfigEntry(widget, "karamtop theme", value)
            karamba.reloadTheme(widget)

    elif pid == procoutformat_pid:
        if value != "":
            if value[:1] == "%":
                print "Changing procoutformat to " + value
                karamba.writeConfigEntry(widget, "setProcOutformat", value)
            else:
                print "Changing procoutformat to default"
                karamba.writeConfigEntry(widget, "setProcOutformat", "")

            karamba.reloadTheme(widget)

    elif pid == align_pid:
        if value != "":
            if value == "default":
                print "Changing setCmdJustification to default"
                karamba.writeConfigEntry(widget, "setCmdJustification", "")
            else:
                print "Changing setCmdJustification to " + value
                karamba.writeConfigEntry(widget, "setCmdJustification", value)

            karamba.reloadTheme(widget)
Exemple #3
0
def readConfigCPUFormat(widget, theme_cfg):
    global Instances
    id = karamba.readConfigEntry(widget, "id")
    toptext = karamba.getThemeText(widget, "toptext")
    #### Begin reading optional settings from [cpuFormat] ####
    # if one option is missing. Then use defaults
    #  	cpu_padding = karamba.readConfigEntry(widget, "cpu_padding")
    #  	cpu_decimal_1 = karamba.readConfigEntry(widget, "cpu_decimal_1")
    # 	cpu_decimal_0 = karamba.readConfigEntry(widget, "cpu_decimal_0")
    # 	hide_0 = karamba.readConfigEntry(widget, "hide_0")
    # 	cpu_rem_0 = karamba.readConfigEntry(widget, "cpu_rem_0")
    #
    # 	if cpu_decimal_1:
    # 		cpu_more_one = "%0.1f"
    # 	if cpu_decimal_0:
    # 		cpu_less_one = "%0.1f"

    showZero = karamba.readConfigEntry(widget, "showZero")
    if showZero == None:
        karamba.setMenuConfigOption(widget, "showZero", 0)
        karamba.writeConfigEntry(widget, "showZero", "false")
        try:
            hide_0 = theme_cfg.getboolean("cpuFormat", "hide_0")
            if hide_0:
                Instances[id].cpuHideZero()

        except ConfigParser.NoOptionError, (strerror):
            print "Warning: " + str(strerror) + ". Skipping option."
Exemple #4
0
def readConfigCPUFormat(widget, theme_cfg):
	global Instances
	id = karamba.readConfigEntry(widget, "id")
	toptext = karamba.getThemeText(widget, "toptext")
	#### Begin reading optional settings from [cpuFormat] ####
	# if one option is missing. Then use defaults
#  	cpu_padding = karamba.readConfigEntry(widget, "cpu_padding")
#  	cpu_decimal_1 = karamba.readConfigEntry(widget, "cpu_decimal_1")
# 	cpu_decimal_0 = karamba.readConfigEntry(widget, "cpu_decimal_0")
# 	hide_0 = karamba.readConfigEntry(widget, "hide_0")
# 	cpu_rem_0 = karamba.readConfigEntry(widget, "cpu_rem_0")
#
# 	if cpu_decimal_1:
# 		cpu_more_one = "%0.1f"
# 	if cpu_decimal_0:
# 		cpu_less_one = "%0.1f"

	showZero = karamba.readConfigEntry(widget, "showZero")
	if showZero == None:
		karamba.setMenuConfigOption(widget, "showZero", 0)
		karamba.writeConfigEntry(widget, "showZero", "false")
		try:
			hide_0 = theme_cfg.getboolean( "cpuFormat" , "hide_0" )
			if hide_0:
				Instances[id].cpuHideZero()

		except ConfigParser.NoOptionError, (strerror):
			print "Warning: " + str(strerror) + ". Skipping option."
Exemple #5
0
def commandOutput(widget, pid, output):
	global chtheme_pid, procoutformat_pid, align_pid
	value = output.strip()

	if pid == chtheme_pid:
		if value != "":
			print "Changing theme to " + value
			karamba.writeConfigEntry(widget, "karamtop theme", value)
			karamba.reloadTheme(widget)

	elif pid == procoutformat_pid:
		if value != "":
			if value[:1] == "%":
				print "Changing procoutformat to " + value
				karamba.writeConfigEntry(widget, "setProcOutformat", value)
			else:
				print "Changing procoutformat to default"
				karamba.writeConfigEntry(widget, "setProcOutformat", "")

			karamba.reloadTheme(widget)

	elif pid == align_pid:
		if value != "":
			if value == "default":
				print "Changing setCmdJustification to default"
				karamba.writeConfigEntry(widget, "setCmdJustification", "")
			else:
				print "Changing setCmdJustification to " + value
				karamba.writeConfigEntry(widget, "setCmdJustification", value)

			karamba.reloadTheme(widget)
Exemple #6
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"
Exemple #7
0
def readConfigThreading(widget):
    global Instances
    id = karamba.readConfigEntry(widget, "id")
    disableThreading = karamba.readConfigEntry(widget, "disableThreading")
    if disableThreading == None or disableThreading == "true":
        karamba.setMenuConfigOption(widget, "disableThreading", 1)
        karamba.writeConfigEntry(widget, "disableThreading", "true")
        disableThreading = True
    else:
        disableThreading = False

    Instances[id].setDisableThreading(disableThreading)
Exemple #8
0
def getLocale(widget):
	GetLocale = karamba.readConfigEntry(widget, "locale") # have you set any language?
	if GetLocale == None:
		# no language found, using english
		# print "No locale-setting was found. Using English en_US"
		karamba.writeConfigEntry(widget, "locale", "en_US")
		SetLocale = "en_US.ISO8859-1"	
	else:
		# language found! using it
		# print "Locale-setting " + SetLocale + " was found!"
		SetLocale = GetLocale + ".ISO8859-1"
	return SetLocale
Exemple #9
0
def readConfigThreading(widget):
	global Instances
	id = karamba.readConfigEntry(widget, "id")
	disableThreading = karamba.readConfigEntry(widget, "disableThreading")
	if disableThreading == None or disableThreading == "true":
		karamba.setMenuConfigOption(widget, "disableThreading", 1)
		karamba.writeConfigEntry(widget, "disableThreading", "true")
		disableThreading = True
	else:
		disableThreading = False

	Instances[id].setDisableThreading(disableThreading)
Exemple #10
0
def initWidget(widget):
    global Instances, titletext, themePath, theme_dir

    #Using a unique ID for multiple instances of karamTop
    id = karamba.readConfigEntry(widget, "id")
    if id == None:
        id = str(int(time.time() * 100))
        karamba.writeConfigEntry(widget, "id", id)

    # Figure out what theme to use. flatgray is the default
    theme = karamba.readConfigEntry(widget, "karamtop theme")
    if theme == None or theme == "":
        theme = "flatgray"

    theme_dir = "themes/"
    themePath = karamba.getThemePath(widget)
    ### Thanks to liquid weather for dealing with the skz format
    home_directory = os.popen("echo $HOME").readline()[0:-1]
    if themePath[-3:] == "skz":
        skz_file = zipfile.ZipFile(themePath, 'r')
        theme_file = skz_file.read(theme_dir + theme + "/" + theme + ".cfg")
        try:
            os.mknod(home_directory + '/.superkaramba/ktop_theme_conf')
        except (OSError):
            pass

        ktop_file = open(home_directory + '/.superkaramba/ktop_theme_conf',
                         'w')
        ktop_file.write(theme_file)
        ktop_file.close()
        theme_cfg_file = (home_directory + '/.superkaramba/ktop_theme_conf')
        skz_file.close()
    else:
        theme_cfg_file = (themePath + theme_dir + theme + "/" + theme + ".cfg")

    theme_cfg = ConfigParser.ConfigParser()
    theme_cfg.readfp(open(theme_cfg_file))

    toptext = karamba.getThemeText(widget, "toptext")
    ##########################################################
    #### Initialize the Top class ####
    try:
        Instances[id] = None
        Instances[id] = (pytop.Top(widget, toptext))
    except NameError, (strerror):
        Instances = {}
        Instances[id] = (pytop.Top(widget, toptext))
Exemple #11
0
def initWidget(widget):
    global Instances, titletext, themePath, theme_dir

    #Using a unique ID for multiple instances of karamTop
    id = karamba.readConfigEntry(widget, "id")
    if id == None:
    	id = str( int( time.time() * 100 ) )
	karamba.writeConfigEntry(widget, "id", id)

    # Figure out what theme to use. flatgray is the default
    theme = karamba.readConfigEntry(widget, "karamtop theme")
    if theme == None or theme == "":
	    theme = "flatgray"

    theme_dir = "themes/"
    themePath = karamba.getThemePath(widget)
    ### Thanks to liquid weather for dealing with the skz format
    home_directory = os.popen("echo $HOME").readline()[0:-1]
    if themePath[-3:] == "skz":
	skz_file = zipfile.ZipFile(themePath, 'r')
	theme_file = skz_file.read(theme_dir + theme + "/" + theme + ".cfg")
	try:
		os.mknod(home_directory + '/.superkaramba/ktop_theme_conf')
	except(OSError):
		pass

	ktop_file = open(home_directory + '/.superkaramba/ktop_theme_conf','w')
	ktop_file.write(theme_file)
	ktop_file.close()
	theme_cfg_file = (home_directory + '/.superkaramba/ktop_theme_conf')
	skz_file.close()
    else:
    	theme_cfg_file = ( themePath + theme_dir + theme + "/" + theme + ".cfg" )

    theme_cfg = ConfigParser.ConfigParser()
    theme_cfg.readfp( open( theme_cfg_file ) )

    toptext = karamba.getThemeText(widget, "toptext")
    ##########################################################
    #### Initialize the Top class ####
    try:
	Instances[id] = None
    	Instances[id] = ( pytop.Top( widget, toptext ) )
    except NameError, (strerror):
	Instances = {}
	Instances[id] = ( pytop.Top( widget, toptext ) )
Exemple #12
0
def commandOutput(widget, pid, output):
	global browsercommand
	if pid == browser_pid:
		karamba.writeConfigEntry(widget, "browser", output)
		browserCommand = output
	pass
Exemple #13
0
def menuOptionChanged(widget, key, value):
    global themePath, theme_dir, chtheme_pid, procoutformat_pid, align_pid

    chtheme_pid = None
    procoutformat_pid = None
    align_pid = None

    chtheme_cmd = [
        'kdialog', '--title', 'Choose theme', '--radiolist', 'Choose theme'
    ]
    align_cmd = [
        'kdialog', '--title', 'Set Alignment', '--radiolist',
        'Set the alignment for the command text.', 'left', 'Left', 'off',
        'right', 'Right', 'off', 'default', 'Reset to theme default', 'on'
    ]
    # 	padding_cmd = ['kdialog', '--title', 'Set Padding', '--inputbox', 'Set maximum length for the command text. Enter an integer number. The default value for flatgray is 13', '13']
    procoutformat_cmd = [
        'kdialog', '--title', 'Set Output format', '--inputbox',
        'Set the column order for the output. Syntax is important here. Must include all columns.\n\nType \"default\" to reset to the default.\n\nDefault value is: %(cpu_percent)s %(command)s %(memory)s\n\nExamples: %(memory)s %(command)s %(cpu_percent)s\n%(command)s %(cpu_percent)s %(memory)s',
        '%(cpu_percent)s %(command)s %(memory)s'
    ]

    if key == "theme":
        listing = []
        if themePath[-3:] == "skz":
            skz_file = zipfile.ZipFile(themePath, 'r')
            ziplisting = skz_file.namelist()
            skz_file.close()
            for member in ziplisting:
                if member.find(theme_dir) > -1:
                    path = member.split("/")
                    if len(path) == 3 and path[2] == "":
                        listing.append(path[1])
        else:
            listing = os.listdir(themePath +
                                 theme_dir)  # list the files in themes/

        for theme in listing:
            # kdialog wants 3 parameters per item.
            # tag is what the value is and item is what is display
            # not sure about status. so just putting anything there
            chtheme_cmd.append(theme)  # one for tag
            chtheme_cmd.append(theme)  # one for item
            chtheme_cmd.append("on")  # one for status

        karamba.setMenuConfigOption(widget, "theme", 0)
        chtheme_pid = karamba.executeInteractive(widget, chtheme_cmd)

    elif key == "setProcOutformat":
        karamba.setMenuConfigOption(widget, "setProcOutformat", 0)
        procoutformat_pid = karamba.executeInteractive(widget,
                                                       procoutformat_cmd)

    elif key == "showZero":
        if value == 1:
            print "Changing to config to show zeros."
            karamba.writeConfigEntry(widget, "showZero", "true")
        else:
            print "Changing to config to hide zeros."
            karamba.writeConfigEntry(widget, "showZero", "false")

        karamba.reloadTheme(widget)

    elif key == "setCmdJustification":
        karamba.setMenuConfigOption(widget, "setCmdJustification", 0)
        align_pid = karamba.executeInteractive(widget, align_cmd)

    elif key == "disableThreading":
        if value == 1:
            print "Disable threading."
            karamba.writeConfigEntry(widget, "disableThreading", "true")
        else:
            print "Enable threading."
            karamba.writeConfigEntry(widget, "disableThreading", "false")

        karamba.reloadTheme(widget)
Exemple #14
0
def commandOutput(widget, pid, output):
	if pid == localePid:
		localeString = output.replace('\n','')
		print "New language " + localeString + " was selected!"
		karamba.writeConfigEntry(widget, "locale", localeString)
		getLocale(widget)
Exemple #15
0
def menuOptionChanged(widget, key, value):
	global themePath, theme_dir, chtheme_pid, procoutformat_pid, align_pid

	chtheme_pid = None
	procoutformat_pid = None
	align_pid = None

	chtheme_cmd = ['kdialog', '--title', 'Choose theme', '--radiolist', 'Choose theme']
	align_cmd = ['kdialog', '--title', 'Set Alignment', '--radiolist', 'Set the alignment for the command text.', 'left', 'Left', 'off', 'right', 'Right', 'off', 'default','Reset to theme default', 'on']
# 	padding_cmd = ['kdialog', '--title', 'Set Padding', '--inputbox', 'Set maximum length for the command text. Enter an integer number. The default value for flatgray is 13', '13']
	procoutformat_cmd = ['kdialog', '--title', 'Set Output format', '--inputbox', 'Set the column order for the output. Syntax is important here. Must include all columns.\n\nType \"default\" to reset to the default.\n\nDefault value is: %(cpu_percent)s %(command)s %(memory)s\n\nExamples: %(memory)s %(command)s %(cpu_percent)s\n%(command)s %(cpu_percent)s %(memory)s', '%(cpu_percent)s %(command)s %(memory)s']


	if key == "theme":
		listing = []
		if themePath[-3:] == "skz":
			skz_file = zipfile.ZipFile(themePath, 'r')
			ziplisting = skz_file.namelist()
			skz_file.close()
			for member in ziplisting:
				if member.find(theme_dir) > -1:
					path = member.split("/")
					if len(path) == 3 and path[2] == "":
						listing.append( path[1] )
		else:
			listing = os.listdir(themePath + theme_dir) # list the files in themes/

		for theme in listing:
			# kdialog wants 3 parameters per item.
			# tag is what the value is and item is what is display
			# not sure about status. so just putting anything there
			chtheme_cmd.append(theme) # one for tag
			chtheme_cmd.append(theme) # one for item
			chtheme_cmd.append("on") # one for status

		karamba.setMenuConfigOption(widget, "theme", 0)
		chtheme_pid = karamba.executeInteractive(widget, chtheme_cmd)

	elif key == "setProcOutformat":
		karamba.setMenuConfigOption(widget, "setProcOutformat", 0)
		procoutformat_pid = karamba.executeInteractive(widget, procoutformat_cmd)

	elif key == "showZero":
		if value == 1:
			print "Changing to config to show zeros."
			karamba.writeConfigEntry(widget, "showZero", "true")
		else:
			print "Changing to config to hide zeros."
			karamba.writeConfigEntry(widget, "showZero", "false")

		karamba.reloadTheme(widget)

	elif key == "setCmdJustification":
		karamba.setMenuConfigOption(widget, "setCmdJustification", 0)
		align_pid = karamba.executeInteractive(widget, align_cmd)

	elif key == "disableThreading":
		if value == 1:
			print "Disable threading."
			karamba.writeConfigEntry(widget, "disableThreading", "true")
		else:
			print "Enable threading."
			karamba.writeConfigEntry(widget, "disableThreading", "false")

		karamba.reloadTheme(widget)