1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
from copy import copy
class virtual:
"this method is unimplemented in this base class"
class table_info_template:
"reads info about a table, to create widgets about it"
#######dictionaries:
#a description is a sequence of 7-uples of the form
#(name, type_code, display_size, internal_size, precision, scale, null_ok)
#field to description
#where 'description' is the 7-uple above
field_description={}
# field to columninfo
# where columninfo = (Field, Type, Null, Key, Default, Extra)
#note that the above is the format used by mySQL
field_columninfo={}
####### other info:
#list of field names
fields=[]
#and number of fields
n_fields=0
#default row
default_row=[]
# some special Fields
#list of fields which are part of the primary key
primary_key_fields=[]
#and the index of the last one in the list 'fields'
n_primary=None
#list of fields which have keys
key_fields=[]
#and the index of the last one in the list 'fields'
n_key=None
##the method of initizialization is:
#def __init__(self,db,db_name,table_name):
##where 'db' can be obtained by
## db=MySQLdb.connect() or other module that implements "python db api"
class entry_widget_template:
"template for class for a row entry (that is, for the value of a column)"
#widget that implements the GUI
widget=None
#or also
__widget=None
def __init__(self,columninfo,description):
(Field, Type, Null, Key, Default, Extra) = columninfo
(name, type_code, display_size, internal_size, precision, scale, null_ok)=description
self.columninfo=copy(columninfo)
self.description=copy(description)
#can this entry be null?
self.not_null=not null_ok
#FIXME not portable?
self.type=Type
self.default=Default
#self.key = Key
#standard methods of this class
def set(self,value):
#puts the value in the appropriate widget
raise virtual
def get(self):
#gets the value from the widget
raise virtual
def set_editable(self,flag):
#sets the widget so that it can/cannot be edited
raise virtual
def log(self,level,text):
print "LOG("+str(level)+"): "+ text
class row_widget_template:
"""template for class for a row (that is, for the value of a row).
Note that a row_widget class implements the methods of
an entry_widget class --- and can be used as such, for joins"""
#widget that implements the GUI
widget=None
#or
__widget=None
#methods
def get(self):
#return the value of the primary
return self.primary
def set(self,v):
#it does an SQL SELECT to find the row where primary key=v
raise virtual
def get_row(self):
raise virtual
def set_row(self,r):
raise virtual
def set_editable(self,flag):
#sets the widget so that it can/cannot be edited
raise virtual
# a fallback log method
def log(self,level,text):
print "LOG("+str(level)+"): "+ text
|