Author: jblum Date: 2007-06-11 01:41:42 -0600 (Mon, 11 Jun 2007) New Revision: 5765
Added: grc/branches/jblum_work/readme.txt Removed: grc/branches/jblum_work/README.txt Modified: grc/branches/jblum_work/src/DataType.py grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py Log: doxygen for DataType Deleted: grc/branches/jblum_work/README.txt Copied: grc/branches/jblum_work/readme.txt (from rev 5751, grc/branches/jblum_work/README.txt) =================================================================== --- grc/branches/jblum_work/readme.txt (rev 0) +++ grc/branches/jblum_work/readme.txt 2007-06-11 07:41:42 UTC (rev 5765) @@ -0,0 +1,13 @@ +Hello! + +Thank you for downloading GNU Radio Companion. +This program is free software. +A GPL license is distributed with this program. +This license covers all the source code/python files. +You will also find a "creative common license" for the grc icon. + +Intructions for GRC are available at: +http://gnuradio.org/trac/wiki/GNURadioCompanion + +If you have questions, problems, suggestions, or want to contribute, +please email me at jblum at jhu dot edu Modified: grc/branches/jblum_work/src/DataType.py =================================================================== --- grc/branches/jblum_work/src/DataType.py 2007-06-10 20:59:23 UTC (rev 5764) +++ grc/branches/jblum_work/src/DataType.py 2007-06-11 07:41:42 UTC (rev 5765) @@ -27,30 +27,50 @@ from gnuradio import gr class DataType: - ''' The base class for all data types, holds data and provides parsing. - Do not use, this is a base class only. ''' + """ + The base class for all data types. + Hold data and provide parsing. + Do not use, this is a base class only. + """ base_type = None def __init__(self, data='0', min=None, max=None): - ''' Set the data to the default value. ''' - self.set_data(data) - self.max = max - self.min = min - self.msg = '' + """! + DataType constructor. + @param data the data + @param min the minimum + @param max the maximum + """ + self.set_data(data) + self.max = max + self.min = min + self.msg = '' #parser messages def set_data(self, data): - ''' Store the data as a string. ''' + """! + Store the data as a string. + @param data the data + """ self.data = str(data) def get_data(self): - ''' Get the data as a string. ''' + """! + Get the data as a string. + @return the data """ return self.data def parse(self): - ''' Replace all variable instances with the variable's string representation. ''' + """! + Substitute in variables. + Replace all variable instances with the variable's string representation. + @return the data without variables""" return Variables.replace_var_instances(self.get_data()) def is_valid(self): - ''' True if the data can be parsed, otherwise False. + """! + Is this data type valid? + True if the data can be parsed, otherwise False. If min or max was specified, the parsed value must be less than or equal to min and/or greater than or equal to max. If the parsed value is a vector, - then the value is the length of the vector. ''' + then the value is the length of the vector. + @return boolean, true if valid + """ try: value = self.parse() self.msg = '' @@ -59,17 +79,28 @@ self.msg = str(e) return False def get_type(self): - ''' Get a string describing the specific data type. ''' + """! + Get a string describing the specific data type. + @return type string + """ return self.type def get_base_type(self): - ''' Get a string describing the basic data type. ''' + """! + Get a string describing the base (category) of this data type. + @return base type string + """ return self.base_type def get_num_bytes(self): - ''' How man bytes in this data type? ''' + """! + How man bytes in this data type? + @return number of bytes + """ return self.num_bytes - def verify_bounds(self, value): - ''' Is the value within the bounds of this data type. - Raise an exception if not. ''' + def _verify_bounds(self, value): + """! + Is the value within the bounds of this data type? + @throw ValueError out of bounds. + """ if self.max != None and value > self.max: raise ValueError('Value "%s" was greater than the max "%s".'%(value, self.max)) if self.min != None and value < self.min: raise ValueError('Value "%s" was greater than the min "%s".'%(value, self.min)) @@ -77,104 +108,154 @@ # Regular Types ############################################################################################# class Number(DataType): - ''' The base class for numeric data types. - Do not use, this is a base class only. ''' + """ + A number data type. + The base class for numeric data types. + Do not use, this is a base class only. + """ base_type = 'number' def parse(self): - ''' Evaluate the math expressions in the data type. ''' + """! + Evaluate the math expressions in the data type. + @return a number + """ num = MathExprParser.eval_expr(DataType.parse(self)) parsed = self.parser(num) - self.verify_bounds(parsed) + self._verify_bounds(parsed) return parsed class Int(Number): - ''' The integer data type. ''' + """The integer data type.""" type = 'int' num_bytes = gr.sizeof_int def parser(self, value): - ''' Return an int value or raise error. ''' + """! + Parse the data for an integer value or raise an error. + @throw Exception non integer + @return integer + """ return MathExprParser.verify_int(value) class Byte(Int): - ''' The byte data type is identical to int in this case. ''' + """The byte data type is identical to int. """ type = 'byte' num_bytes = gr.sizeof_char class Short(Int): - ''' The short data type is identical to int in this case. ''' + """The short data type is identical to int.""" type = 'short' num_bytes = gr.sizeof_short class Float(Number): - ''' The float data type. ''' + """The float data type.""" type = 'float' num_bytes = gr.sizeof_float def parser(self, value): - ''' Return a float value or raise error. ''' + """! + Parse the data for an float value or raise an error. + @throw Exception non float + @return float + """ return MathExprParser.verify_float(value) class Complex(Number): - ''' The complex data type. ''' + """The complex data type.""" type = 'complex' num_bytes = gr.sizeof_gr_complex def parser(self, value): - ''' Return the value as complex. ''' + """! + Parse the data for an complex value or raise an error. + @throw Exception non complex + @return complex + """ return MathExprParser.verify_complex(value) ############################################################################################# # Special Types ############################################################################################# class RawExpr(DataType): - ''' A raw mathematical expression. ''' + """A raw mathematical expression.""" type = 'raw' def __init__(self, data=''): - ''' Raw data type contructor. Default value is blank string. ''' + """! + Raw data type contructor. + @param data the data + """ DataType.__init__(self, data) def parse(self): - ''' Return the raw data returned by the parser ''' + """! + Get the raw data returned by the math parser. + @throw Exception malformed expression + @return the evaluated mathematical expression + """ data = DataType.parse(self) return MathExprParser.eval_expr(data) class String(DataType): - ''' The string data type. ''' + """The string data type.""" type = 'string' def __init__(self, data='', min=None, max=None): - ''' String data type contructor. Default value is blank string. ''' + """! + String data type contructor. + @param data the data + @param min the minimum length of the string + @param max the maximum length of the string + """ DataType.__init__(self, data, min, max) def parse(self): - ''' Verify the the string's length is in bounds. ''' + """! + Get the data as a string. + @throw Exception string length out of bounds + @return the data + """ string = DataType.parse(self) - self.verify_bounds(len(string)) + self._verify_bounds(len(string)) return string class Hex(DataType): - ''' The hex data type. ''' + """The hex data type.""" type = 'hex' def parse(self): - ''' Return the value as an hex type. ''' + """! + Get the data as an integer parsed from a hex string. + @return the data + """ return int(DataType.parse(self),16) class File(String): - ''' A file data type. - Do not use, this is a base class only. ''' + """A file data type. Do not use, this is a base class only.""" base_type = 'file' def __init__(self, data='', allow_blank=False): - ''' File data type contructor. Allow blank lets blank filename pass validation. ''' + """! + File data type contructor. + Allow blank lets blank filename pass validation. + @param data the file path + @param allow_blank allow empty paths(true/false) + """ String.__init__(self, data) self.allow_blank = allow_blank class FileOpen(File): - ''' A file data type. ''' + """A file data type for choosing existing files.""" type = 'fileopen' def is_valid(self): + """! + Does the file path exist? + @return true if valid + """ if self.allow_blank and self.parse() == '': return True from os import path return path.isfile(self.parse()) class FileSave(File): - ''' A file data type. ''' + """A file data type for choosing files to save.""" type = 'filesave' - def is_valid(self): + def is_valid(self): + """! + Is the file path possible? + The directory must exist and the filename must not be an existing directory. + @return true if validcannonical name + """ if self.allow_blank and self.parse() == '': return True from os import path my_path = self.parse() @@ -184,78 +265,141 @@ return path.basename(my_path) != '' class Variable(DataType): - ''' The variable data type. Gets its data type from an Enum of Data Types. ''' + """ + The variable data type. + Takes properties from an enumerated data type of data types. + """ def __init__(self, enum_data_type, data='0', index=None, min=None, max=None): - ''' Init the DataType and set the enumerated data type. ''' + """! + Variable constructor. + The enumerated type must contain other data types in its choices. + The index is the index of the data type in the enum's tuple. + If index is None, enum must parse to a data type. + @param enum_data_type an enumerated data type + @param data the data + @param index the index of the data type in the enum's choice + @param min the minimum + @param max the maximum + """ DataType.__init__(self, data, min, max) self.enum_data_type = enum_data_type self.index = index def parse_enum_data_type(self): - ''' Parse the selected data type. If there is an index, get the data type from a tuple instead. ''' + """! + Parse the selected data type. + If there is an index, get the data type from a tuple instead. + @return the data type + """ if self.index is None: return self.enum_data_type.parse() else: return self.enum_data_type.parse()[self.index] def get_type(self): - ''' Retrieve the type from the enumerated data type. ''' + """! + Get the type from the enumerated data type. + @return the type + """ return self.parse_enum_data_type().get_type() def get_base_type(self): - ''' Retrieve the base type from the enumerated data type. ''' + """! + Get the base type from the enumerated data type. + @return the base type + """ return self.parse_enum_data_type().get_base_type() def get_num_bytes(self): - ''' Retrieve the num bytes from the enumerated data type. ''' + """! + Get the number of bytes from the enumerated data type. + @return the number of bytes. + """ return self.parse_enum_data_type().get_num_bytes() def parse(self): - ''' Use the parser from the enumerated data type. ''' + """! + Use the parser from the enumerated data type. + @return the parsed data + """ data_type = self.parse_enum_data_type() data_type.set_data(self.get_data()) return data_type.parse() class Enum(DataType): - ''' The enumerated type holds a finite set of choices. + """The enumerated data type. + The enumerated type holds a finite set of choices. The selected choice is determined by the data. - The data must represent an integer index. ''' + The data must represent an integer index. """ type = 'enum' base_type = 'enum' def __init__(self, choices=[('',0)], data='0'): - ''' Init the DataType and set the choices list. - choices = [(cname0, choice0),(cname1, choice1),...]''' + """! + Enum constructor. + choices = [(cname0, choice0),(cname1, choice1),...] + @param choices the list of choices + @param data the choice index 0-> len(choices)-1 + """ self.choices = choices DataType.__init__(self, data) def set_data(self, data): - ''' Before setting the data, try to use it as an index for choices. - Exceptions may be raised. ''' + """! + Set the data. + Try to use data as an index for choices. + @param data the data + @throw Exception bad index + """ self.choices[int(data)] DataType.set_data(self, data) def parse(self): - ''' Parse the data by returning the current selection pointed to by the data. ''' + """! + Parse the data by returning the current selection pointed to by the data. + @return the choice at the index held in data + """ return self.choices[int(self.get_data())][1] def get_cname(self): - ''' Get the cname of the currently selected choice. ''' + """! + Get the cannonical name of the currently selected choice. + @return the cannonical name + """ return self.choices[int(self.get_data())][0] def get_cnames_list(self): - ''' Get a list of the cnames from the choices (in order). ''' + """! + Get a list of the cannonical names from the choices (in order). + @return a list of all the cannonical names + """ cnames = list() for cname,choice in self.choices: cnames.append(cname) return cnames class VariableKeySelector(DataType): - ''' The variable enumerated type holds list of variable keys. - The data must be a key in the variable registry. ''' + """ + The variable key selector data type. + This data type allows the user to select a variable key in the variable registry. + """ type = 'variable enum' base_type = 'variable enum' def __init__(self, data='', all_variables=False): - ''' Initialize the data type. + """! + Variable key selector contructor. If the all variables flag is true, this data type can represent any variable key. - If the all variables flag is false, variables with ranges will not be allowed. ''' + If the all variables flag is false, variables with ranges will not be allowed. + @param data the variable key + @param all_variables boolean to allow certain variables + """ DataType.__init__(self, data) self.all_variables = all_variables def parse(self): - ''' Parse the data by returning the current key. ''' + """! + Parse the data by returning the current key. + @return the var key + """ return self.get_data().strip() def is_valid(self): - ''' To be valid, the data must be in the keys list''' + """! + Is the variable key valid? + The data must be in the keys list. + @return true if valid""" return self.parse() in self.get_variables_list() def get_variables_list(self): - ''' Get a list of the keys. ''' + """! + Get a list of the keys. + Use all_variables to restrict the list. + @return a list of possible keys + """ var_keys = list() for key in Variables.get_keys(): # use the key if we specified all variables or the key was not for a ranged variable @@ -263,10 +407,18 @@ return var_keys class Bool(Enum): - ''' The Bool (boolean) type is an Enum with two choices. - One choice will parse to True, the other False. ''' + """ + The boolean data type. + This boolean type is an Enum with two choices. + One choice will parse to True, the other False. """ type = 'bool' def __init__(self, true='True', false='False', default=True): + """! + Bool contructor. + @param true the cname for the true choice + @param false the cname for the false choice + @param default the default choice + """ if default: data = 0 #determine the default index else: data = 1 Enum.__init__(self, choices=[(true, True), (false, False)], data=data) @@ -275,42 +427,61 @@ # Vectors Types ############################################################################################# class Vector(DataType): - ''' The base class for vectors. - Do not use, this is a base class only. ''' + """ + A vector data type. + The base class for vectors. + Do not use, this is a base class only. + """ base_type = 'vector' def parse(self): - ''' Verify that the length of the vector is within bounds. ''' + """! + Parse the vector data type. + The length of the vector must be within bounds. + The data must pass the math expression parser. + @throw Exception not in bounds + @throw Exception invalid syntax + @return the vector + """ elements = MathExprParser.eval_expr(DataType.parse(self)) if type(elements) != type(list()): elements = [elements] #ensure that elements is a list - self.verify_bounds(len(elements)) + self._verify_bounds(len(elements)) return map(lambda v: self.parser(v), elements) class ByteVector(Vector, Byte): - ''' A vector of bytes ''' + """A vector of bytes.""" type = 'byte vector' class IntVector(Vector, Int): - ''' A vector of ints ''' + """A vector of ints.""" type = 'int vector' class ShortVector(Vector, Short): - ''' A vector of shorts ''' + """A vector of shorts.""" type = 'short vector' class FloatVector(Vector, Float): - ''' A vector of floats ''' + """A vector of floats.""" type = 'float vector' class ComplexVector(Vector, Complex): - ''' A vector of complex ''' + """A vector of complex.""" type = 'complex vector' def can_connect(dt1, dt2): - """ Given 2 data types, return True if they can connect. Type strings must match. """ + """! + Can these data types connect? + @param dt1 a data type + @param dt2 another data type + @return true if the types match + """ return dt1.get_type() == dt2.get_type() def vectorize(data_type): - """ Take a regular data type and return its vector form. """ + """! + Take a regular data type and return its vector form. + @param data_type a regular data type + @return a vector data type + """ type = data_type.get_type() regular_to_vector_dict = { Byte().get_type() : ByteVector(), Modified: grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py =================================================================== --- grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py 2007-06-10 20:59:23 UTC (rev 5764) +++ grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py 2007-06-11 07:41:42 UTC (rev 5765) @@ -39,10 +39,6 @@ """ Implement a flow graph builder, and provide access functions for the xmlrpc server. """ - def get_var_key_list(self): - """ Get a list of all possible variable keys. """ - return self.var_keys #the var keys in order - def get_var_range(self, key): """ Return the min and the max of a variable (strings). """ value, min, max, step = Variables.get_values(key) @@ -76,7 +72,7 @@ # register access methods # server.register_function(lambda key: bool(Variables.is_ranged(key)), "var_has_range") server.register_function(lambda key: bool(Variables.has_key(key)), "var_exists") - server.register_function(fg.get_var_key_list, "get_var_key_list") + server.register_function(lambda: fg.var_keys, "get_var_key_list") server.register_function(lambda key: str(Variables.get_value(key)), "get_var") server.register_function(fg.get_var_range, "get_var_range") server.register_function(fg.set_var, "set_var") _______________________________________________ Commit-gnuradio mailing list [email protected] http://lists.gnu.org/mailman/listinfo/commit-gnuradio
