For starters, here is some modified code. I think you want readlines instead of read on line 128. read is generally used to read a specific number of bytes while readlines reads the entire file. A print statement was added to show what was read. Also, you want to consider breaking this up even further. Adding options could become a separate function for example. It's easier to understand and debug..
Code:
#
# make new html source from values in config settings
self.fh = open(str(self.mypath)+'LastWidgetSource.html', 'r') # declare LastWidgetSource.html as fh
self.fh1_data = self.fh.readlines() # read fh and declare it as fh1
self.fh.close() # we're done with fh, close it
print self.fh1_data
#
fh2 = open(str(self.mypath)+'gtoload.html', 'w') # write file gtoload.html, declare it as fh2
for line_in in self.fh1_data:
print "original line =", line_in
if 'USERNAME' in line_in:
line_in = line_in.replace('USERNAME',str(int(380*self.scale))) # replace in fh1. what?
if 'COLOUR' in line_in:
line_in = line_in.replace('COLOUR', (self.widget_colour)) # replace in fh1. what?
if 'MODE' in line_in:
line_in = line_in.replace('MODE', (self.widget_mode)) # replace in fh1. what?
#
print "modified line =", line_in, "\n\n"
fh2.write(line_in) # write fh1 into fh2
#
fh2.close() # we're done with fh2, close it
I don't know anything about screenlets, but generally you have to retrieve the selection with some sort of get statement which I don't see in your code. But again, I am not familiar with screenlets.
Bookmarks