On Dec 10, 7:15 am, CoolGenie <[EMAIL PROTECTED]> wrote:
> Hi!
> I'm trying to write a small adesklet that will read newsfeeds. Here's
> the code:
>
> #
> #
> # fparser.py
> #
> # P. Kaminski <[EMAIL PROTECTED]>
> # Time-stamp: <>
> ##
> import feedparser
> import adesklets
> from os import getenv, spawnlp, P_NOWAIT
> from os.path import join, dirname
>
> class Config(adesklets.ConfigFile):
> cfg_default = { 'feedsrc' : 'http://slashdot.org/index.rss',
> 'numfeeds' : 5,
> 'numlines' : 4
> }
>
> def __init__(self, id, filename):
> adesklets.ConfigFile.__init__(self, id, filename)
>
> class Events(adesklets.Events_handler):
> def __init__(self, basedir):
> if len(basedir)==0:
> self.basedir='.'
> else:
> self.basedir=basedir
> adesklets.Events_handler.__init__(self)
>
> def __del__(self):
> adesklets.Events_handler.__del__(self)
>
> def ready(self):
> self.config = Config(adesklets.get_id(),
> join(self.basedir, 'config.txt'))
> self.feed = self.config['feedsrc']
> self.numfeeds = self.config['numfeeds']
> self.numlines = self.config['numlines']
>
> self.w = 520
> self.h = 12*self.numfeeds*(self.numlines+1)
> adesklets.window_resize(self.w, self.h)
> adesklets.window_reset(adesklets.WINDOW_UNMANAGED)
> adesklets.window_set_transparency(True)
> adesklets.window_show()
>
> def quit(self):
> print 'Quitting...'
>
> def alarm(self):
> print 'Alarm. Next in 360 seconds.'
> self._display()
> return 360
>
> def _display(self):
> print "Getting feed..."
> y = 0
> x = 0
> d = feedparser.parse(self.feed)
> print d.channel.title
> print d.channel.description
>
> # clear the buffer
> buffer = adesklets.create_image(self.w, self.h)
> adesklets.context_set_image(buffer)
> adesklets.context_set_blend(False)
> adesklets.context_set_color(0,0,0,0)
> adesklets.image_fill_rectangle(0,0,self.w,self.h)
> adesklets.context_set_blend(True)
>
> adesklets.context_set_font(adesklets.load_font('Vera/7'))
> adesklets.context_set_color(255, 0, 0, 255)
> adesklets.text_draw(0, y, str(d.channel.title))
> y+=12
> l = len(d.entries)
> l = min(l, self.numfeeds)
> for i in range(l):
> ent=d.entries[i]
> adesklets.context_set_color(255, 255, 0, 255)
> adesklets.text_draw(0, y, str(ent.title))
> print ent.title
> y+=12
> adesklets.context_set_color(255, 255, 255, 255)
> for k in range(0, min(len(ent.summary)/100,
> self.numlines)):
> print str(ent.summary)[k*100:(k+1)*100]
> adesklets.text_draw(0, y, str(ent.summary)[k*100:(k
> +1)*100])
> y+=12
> adesklets.free_font(0)
> adesklets.free_image(buffer)
>
> Events(dirname(__file__)).pause()
>
> Unfortunately, I'm getting this bug for some time now and I just don't
> know what's going on:
>
> File "./fparser.py", line 40
> self.w = 520
> ^
> SyntaxError: invalid syntax
>
As viewed with Google Groups, lines 40/41, 63/69, and 89 are indented
8 spaces more than they should be.
When I save your file and try to run it, I get this:
C:\junk>coolgenie.py
File "C:\junk\coolgenie.py", line 40
self.w = 520
^
IndentationError: unexpected indent
Possibilities:
(1) Your file contains junk like tabs or no-break spaces. Use a text
editor that will not mask what is really there to find the junk and
edit it out.
(2) You don't understand that:
if some_condition:
blah1
blah2
blah3
is not valid. Blah2 has to be at the same level as blah1 and blah3.
HTH,
John
--
http://mail.python.org/mailman/listinfo/python-list