def buttons(self, table): """ table is a dict. The key represents the key combinations (i.e. '{ modkey }, 1' means modkey+mouse_butt1). The value is a lua function. For example: butts['{}, 1'] = "function () awful.util.spawn('amixer -q set Master 5%+') end" """ # Adds a table like: # widgetbuttons = "widgetbuttons = awful.util.table.join(awful.button({ }, 1, function() ... end))" for k, v in table.items(): mods = k[0] key = k[1] func_wrap = "function() python.execute(" + v + ") end" pass butts = [] for k, v in table.items(): butts.append("awful.button(" + k + ", " + v + ")") butts = ", ".join(butts) widgetbuttons = "widgetbuttons = awful.util.table.join(" + butts + ")" # print(widgetbuttons) execute(widgetbuttons) return execute("{0}:{1}({2})".format(self.widget_name, "buttons", "widgetbuttons"))
def text(self, txt): """text: The text to display.""" if type(txt) != str: raise TypeError('Error: txt=' + str(txt) + ' must be a string.') execute("{0}.{1} = '{2}'".format(self.widget_name, 'text', to_lua(txt)))
def buttons(self, table): """ table is a dict. The key represents the key combinations (i.e. '{ modkey }, 1' means modkey+mouse_butt1). The value is a lua function. For example: butts['{}, 1'] = "function () awful.util.spawn('amixer -q set Master 5%+') end" """ # Adds a table like: # widgetbuttons = "widgetbuttons = awful.util.table.join(awful.button({ }, 1, function() ... end))" for k, v in table.items(): mods = k[0] key = k[1] func_wrap = "function() python.execute(" + v + ") end" pass butts = [] for k, v in table.items(): butts.append('awful.button(' + k + ', ' + v + ')') butts = ', '.join(butts) widgetbuttons = "widgetbuttons = awful.util.table.join(" + butts + ")" #print(widgetbuttons) execute(widgetbuttons) return execute("{0}:{1}({2})".format(self.widget_name, 'buttons', 'widgetbuttons'))
def border_width(self, bw): """border_width: The border width to draw around.""" if type(bw) != int and type(bw) != float: raise TypeError('Error: bw=' + str(bw) + ' must be a int or float.') execute("{0}.{1} = '{2}'".format(self.widget_name, 'border_width', to_lua(bw)))
def align(self, a): """align: Text alignment, left, center or right.""" if type(a) != str: raise TypeError("Error: a=" + str(a) + " must be a string.") if a != "left" and a != "center" and a != "right": raise ValueError("Error: align can be either left, center or right.") execute("{0}.{1} = '{2}'".format(self.widget_name, "align", to_lua(a)))
def bg(self, bk): """bk: Background color. Put 'trasparent' for a trasparent color. """ if type(bk) != str: raise TypeError('Error: bk=' + str(bk) + ' must be a string.') if bk == 'trasparent': bk = '#00000000' execute("{0}.{1} = '{2}'".format(self.widget_name, 'bg', to_lua(bk)))
def align(self, a): """align: Text alignment, left, center or right.""" if type(a) != str: raise TypeError('Error: a=' + str(a) + ' must be a string.') if a != 'left' and a != 'center' and a != 'right': raise ValueError( 'Error: align can be either left, center or right.') execute("{0}.{1} = '{2}'".format(self.widget_name, 'align', to_lua(a)))
def border_color(self, bc): """border_color: The border color. Put 'trasparent' for a trasparent color. """ if type(bc) != str: raise TypeError("Error: bc=" + str(bc) + " must be a string.") if bc == "trasparent": bc = "#00000000" execute("{0}.{1} = '{2}'".format(self.widget_name, "border_color", to_lua(bc)))
def bg(self, bk): """bk: Background color. Put 'trasparent' for a trasparent color. """ if type(bk) != str: raise TypeError("Error: bk=" + str(bk) + " must be a string.") if bk == "trasparent": bk = "#00000000" execute("{0}.{1} = '{2}'".format(self.widget_name, "bg", to_lua(bk)))
def border_color(self, bc): """border_color: The border color. Put 'trasparent' for a trasparent color. """ if type(bc) != str: raise TypeError('Error: bc=' + str(bc) + ' must be a string.') if bc == 'trasparent': bc = '#00000000' execute("{0}.{1} = '{2}'".format(self.widget_name, 'border_color', to_lua(bc)))
def set_height(self, height): """Set the graph height. Parameters: height: The height to set. """ if type(height) != int and type(height) != float: raise TypeError('Error: height=' + str(height) + ' must be a int or float.') execute("{0}:{1}({2})".format(self.widget_name, 'set_height', to_lua(height)))
def set_scale(self, scale): """ Set the graph to automatically scale its values. Default is false. Parameters: scale: A boolean value """ if type(scale) != bool: raise TypeError('Error: scale=' + str(scale) + ' must be a bool.') execute("{0}:{1}({2})".format(self.widget_name, 'set_scale', to_lua(scale)))
def set_stack(self, stack): """ Set the graph to draw stacks. Default is false. Parameters: stack: A boolean value. """ if type(stack) != bool: raise TypeError('Error: stack=' + str(stack) + ' must be a bool.') execute("{0}:{1}({2})".format(self.widget_name, 'set_stack', to_lua(stack)))
def set_stack_colors(self, stack_colors): """ Set the graph stacking colors. Order matters. Parameters: stack_colors: A table with stacking colors. """ if type(stack_colors) != dict: raise TypeError('Error: stack_colors=' + str(stack_colors) + ' must be a dict.') execute("{0}:{1}({2})".format(self.widget_name, 'set_stack_colors', to_lua(stack_colors)))
def set_color(self, color): """ Set the graph foreground color. Parameters: color: The graph color. """ if type(color) != str: raise TypeError('Error: color=' + str(color) + ' must be a string.') execute("{0}:{1}('{2}')".format(self.widget_name, 'set_color', to_lua(color)))
def set_width(self, width): """ Set the graph width. Parameters: width: The width to set. """ if type(width) != int and type(width) != float: raise TypeError('Error: width=' + str(width) + ' must be a int or float.') execute("{0}:{1}({2})".format(self.widget_name, 'set_width', to_lua(width)))
def set_gradient_angle(self, gradient_angle): """ Set the graph foreground colors gradient angle. Default is 270 degrees (horizontal). Parameters: gradient_angle: Angle of gradient in degrees. """ if type(gradient_angle) != int and type(gradient_angle) != float: raise TypeError('Error: gradient_angle=' + str(gradient_angle) + ' must be a int or float.') execute("{0}:{1}({2})".format(self.widget_name, 'set_gradient_angle', to_lua(gradient_angle)))
def set_border_color(self, color): """ Set the graph border color. If the value is nil, no border will be drawn. Parameters: color: The border color to set. """ if type(color) != str: raise TypeError('Error: color=' + str(color) + ' must be a string.') execute("{0}:{1}('{2}')".format(self.widget_name, 'set_border_color', to_lua(color)))
def set_max_value(self, value): """ Set the maximum value the graph should handle. If "scale" is also set, the graph never scales up below this value, but it automatically scales down to make all data fit. Parameters: value: The value. """ if type(value) != int and type(value) != float: raise TypeError('Error: value=' + str(value) + ' must be a int or float.') execute("{0}:{1}({2})".format(self.widget_name, 'set_max_value', to_lua(value)))
def set_gradient_colors(self, gradient_colors): """ Set the graph foreground color as a gradient. Parameters: gradient_colors: A table with gradients colors. The distance between each color can also be specified. Example: { "red", "blue" } or { "red", "green", "blue", blue = 10 } to specify blue distance from other colors. """ if type(gradient_colors) != set: raise TypeError('Error: gradient_colors=' + str(gradient_colors) + ' must be a dict.') execute("{0}:{1}({2})".format(self.widget_name, 'set_gradient_colors', to_lua(gradient_colors)))
def add_value(self, value, group=None): """ Add a value to the graph Parameters: value: The value between 0 and 1. group: The stack color group index. """ if type(value) != float and type(value) != int: raise TypeError('Error: value=' + str(value) + ' must be a float or int.') if value < 0 or value > 1: raise ValueError('Error: value=' + value + '. It must be between 0 and 1.') execute("{0}:{1}({2})".format(self.widget_name, 'add_value', to_lua(value)))
def __init__(self, widget_name): """Constructor""" if widget_name == None: raise ValueError( 'You must specify the name of a widget declared in rc.lua.') # Checks if the widget already exists in rc.lua otherwise launch Exception out = execute('return ' + widget_name) if not out: raise WidgetDoesNotExist self.widget_name = widget_name
def __init__(self, widget_name): """widget_name (str) string of the widget declared in rc.lua""" if widget_name == None: raise ValueError("You must specify the name of a widget declared in rc.lua.") # Checks if the widget already exists in rc.lua otherwise launch Exception out = to_python(execute("return " + widget_name)) if not out: raise WidgetDoesNotExist("Error: The widget: " + widget_name + " doesn't exist in rc.lua.") if out[:6] != "widget": print(out) raise WidgetTypeError("Error: The " + widget_name + " is not a widget.") self.widget_name = widget_name
def __init__(self, widget_name): """widget_name (str) string of the widget declared in rc.lua""" if widget_name == None: raise ValueError( 'You must specify the name of a widget declared in rc.lua.') # Checks if the widget already exists in rc.lua otherwise launch Exception out = to_python(execute('return ' + widget_name)) if not out: raise WidgetDoesNotExist("Error: The widget: " + widget_name + " doesn't exist in rc.lua.") if out[:6] != 'widget': print(out) raise WidgetTypeError("Error: The " + widget_name + " is not a widget.") self.widget_name = widget_name
def visible(self, b): if type(b) != bool: raise TypeError("Error: b=" + str(b) + " must be a bool.") execute("{0}.{1} = {2}".format(self.widget_name, "visible", to_lua(b)))
def visible(self): """Returns whether the widget is visible.""" return to_python(execute("return {0}.{1}".format(self.widget_name, "visible")))
def border_color(self): """Define the border color of the widget.""" return to_python( execute("return {0}.{1}".format(self.widget_name, 'border_color')))
def bg(self): """return The background to display.""" return to_python(execute("return {0}.{1}".format(self.widget_name, "bg")))
def image(self, img): """image: The image to display. """ execute("{0}.{1} = '{2}'".format(self.widget_name, "image", img))
def align(self): """Define the tetxt alignment: left, center or right.""" return to_python( execute("return {0}.{1}".format(self.widget_name, 'align')))
def image(self, img): """image: The image to display. """ execute("{0}.{1} = '{2}'".format(self.widget_name, 'image', img))
def border_color(self): """Define the border color of the widget.""" return to_python(execute("return {0}.{1}".format(self.widget_name, "border_color")))
def border_width(self, bw): """border_width: The border width to draw around.""" if type(bw) != int and type(bw) != float: raise TypeError("Error: bw=" + str(bw) + " must be a int or float.") execute("{0}.{1} = '{2}'".format(self.widget_name, "border_width", to_lua(bw)))
def width(self): """Define the width of the widget.""" return to_python( execute("return {0}.{1}".format(self.widget_name, 'width')))
def bg(self): """return The background to display.""" return to_python( execute("return {0}.{1}".format(self.widget_name, 'bg')))
def text(self): """return The text to display.""" return to_python( execute("return {0}.{1}".format(self.widget_name, 'text')))
def width(self, w): """width(int or float): The width of the textbox. Set to 0 for auto.""" if type(w) != int and type(w) != float: raise TypeError('Error: w=' + str(w) + ' must be a int or float.') execute("{0}.{1} = '{2}'".format(self.widget_name, 'width', to_lua(w)))
def align(self): """Define the tetxt alignment: left, center or right.""" return to_python(execute("return {0}.{1}".format(self.widget_name, "align")))
def text(self): """return The text to display.""" return to_python(execute("return {0}.{1}".format(self.widget_name, "text")))
def width(self): """Define the width of the widget.""" return to_python(execute("return {0}.{1}".format(self.widget_name, "width")))
def text(self, txt): """text: The text to display.""" if type(txt) != str: raise TypeError("Error: txt=" + str(txt) + " must be a string.") execute("{0}.{1} = '{2}'".format(self.widget_name, "text", to_lua(txt)))
def visible(self): """Returns whether the widget is visible.""" return to_python( execute("return {0}.{1}".format(self.widget_name, 'visible')))
def width(self, w): """width(int or float): The width of the textbox. Set to 0 for auto.""" if type(w) != int and type(w) != float: raise TypeError("Error: w=" + str(w) + " must be a int or float.") execute("{0}.{1} = '{2}'".format(self.widget_name, "width", to_lua(w)))
def visible(self, b): if type(b) != bool: raise TypeError('Error: b=' + str(b) + ' must be a bool.') execute("{0}.{1} = {2}".format(self.widget_name, 'visible', to_lua(b)))