Re: [pygtk] Re: LCD-style display widget

2008-06-22 Thread Frédéric
Le 17/6/2008, "John Stowers" <[EMAIL PROTECTED]> a écrit:

> You can zoom in and out with scroll
>wheel (and change brightness with ctrl+scroll). Double click to change
>text.

Hi,

I finally got something from the code you posted. I made a LCDLabel
widget, which is a simplified version of the LCD gui. There is only 1
row. I also corrected a bug: in the original code, moving the window
made the text disappear.

But I still have some problems:

1) I can't set the text before the label is shown, because the pixmap
does not exist yet... This is a design problem with the current GTK
internals usage :o/

2) The widget does not work when I embed it in my GUI. As I work with
glade, I simply added an empty HBox, and in my code, I instanciate the
LCDLabel, and add it to the HBox.

BTW, is there a better way to embed a custom widget in glade?

Thanks for your help,
#!/usr/bin/python
# -*- coding: latin1 -*-

# Copyright (C) 2005 Gerome Fournier 

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# Problems:
# * don't display text given before parent window is shown

import sys
import os.path

import gtk
import gtk.glade

CHARS_FILENAME = "lcd_chars.txt"


class LCDLabel(gtk.DrawingArea):
""" GTK LCD Label
"""
def __init__(self, text=None):
""" Init LCD widget
"""
gtk.DrawingArea.__init__(self)
self._text = text

self._table = {}
self._pixmap = None

self._width_chars = 10
self._border = 5
self._cborder = 3
self._cwidth = 9
self._cheight = 13
self._width = 2 * self._border + (self._cwidth + self._cborder) * self._width_chars + self._cborder
self._height = 2 * self._border + (self._cheight + self._cborder) * 1 + self._cborder
self.set_size_request(self._width, self._height)

self.connect("configure_event", self._configure)
self.connect("expose_event", self._expose)

def _configure(self, widget, event):
print "_configure()"
if self._pixmap is None:
x, y, width, height = widget.get_allocation()
self._pixmap = gtk.gdk.Pixmap(widget.window, width, height)
self.set_brightness(100)
self._pixmap.draw_rectangle(self._back, True, 0, 0, width, height)
#self._load_font_definition() # Already done in set_brightness()
#self.clear()
return True

def _expose(self, widget, event):
print "_expose()"
if self._pixmap is not None:
widget.window.draw_drawable(self._back, self._pixmap, 0, 0, 0, 0, self._width, self._height)
return False

def set_width_chars(self, n_chars):
""" Set the desired width in chars of the LCD widget
"""
print "set_width_chars()"
self._width_chars = n_chars
self._width = 2 * self._border + (self._cwidth + self._cborder) * self._width_chars + self._cborder
self.refresh()

def get_width_chars(self):
""" Return the width (in chars) of the widget
"""
return self._width_chars

def refresh(self):
""" Refresh the LCD widget
"""
print "refresh()"
self.queue_draw_area(0, 0, self._width, self._height)

def set_text(self, text):
""" Set the LCD label text
"""
print "set_text()"
self._text = text
if self._pixmap is not None:
self.clear()
for col, char in enumerate(text):
self._draw_char(col, ord(char))
#self.refresh() # Not needed

def get_text(self):
""" Return the LCD label text
"""
return self._text

def _draw_char(self, col, char_index):
""" Draw the character stored at position 'char_index' in the internal
character definition table, on the LCD widget
"""
if self._pixmap is not None:
x = col * (self._cwidth + self._cborder) + self._border + self._cborder
y = 0 + self._border + self._cborder
self._pixmap.draw_drawable(self._back, self._table[char_index], 0, 0, x, y, self._cwidth, self._cheight)

def set_brightness(self, brightness):
print "set_brightness()"
fg_colors = {
100: "#00ff96",
75: "#00d980",
50: "#00b269",
25: "#008c53",
  

Re: [pygtk] Re: LCD-style display widget

2008-06-21 Thread Frédéric
On dimanche 22 juin 2008, John Stowers wrote:

> This sounds like more of a OOP/gtk question than a pyGTK question I
> think.

Yes, you may be right...

> Google reveals the following might be useful

Thanks!

-- 
Frédéric

http://www.gbiloba.org
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-21 Thread John Stowers
On Sat, 2008-06-21 at 11:17 +0200, Frédéric wrote:
> On mardi 17 juin 2008, John Stowers wrote:
> 
> > You can zoom in and out with scroll
> > wheel (and change brightness with ctrl+scroll). Double click to change
> > text.
> >
> > I attached the files also.
> 
> Hello,
> 
> I'm trying to use this code, and I would like to first create a real PyGTK 
> widget, with the same interface as, say, label widget (for the most 
> usefull part at first).
> 
> But I'm not familiar enough with PyGTK... Could you drive me on the right 
> way? I think to inherits from gtk.Misc, as gtk.Label does. Is it a good 
> idea? Then, what methods do I need to overwrite? What methods in this 
> gslimp3 example code should I use/rewrite?

This sounds like more of a OOP/gtk question than a pyGTK question I
think.

Google reveals the following might be useful
http://www.pygtk.org/articles/writing-a-custom-widget-using-pygtk/writing-a-custom-widget-using-pygtk.htm
http://davyd.livejournal.com/237414.html

John

> 
> Thanks for your help.
> 

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-21 Thread Frédéric
On mardi 17 juin 2008, John Stowers wrote:

> You can zoom in and out with scroll
> wheel (and change brightness with ctrl+scroll). Double click to change
> text.
>
> I attached the files also.

Hello,

I'm trying to use this code, and I would like to first create a real PyGTK 
widget, with the same interface as, say, label widget (for the most 
usefull part at first).

But I'm not familiar enough with PyGTK... Could you drive me on the right 
way? I think to inherits from gtk.Misc, as gtk.Label does. Is it a good 
idea? Then, what methods do I need to overwrite? What methods in this 
gslimp3 example code should I use/rewrite?

Thanks for your help.

-- 
Frédéric

http://www.gbiloba.org
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-17 Thread Frédéric Mantegazza
On mardi 17 juin 2008, Paul Malherbe wrote:

> I had to upgrade bzr to version .92 or later after which it worked OK.

I'm using the 1.5...

-- 
   Frédéric

   http://www.gbiloba.org
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-17 Thread Paul Malherbe





John Stowers wrote:

  On Tue, 2008-06-17 at 11:06 +0200, Frédéric Mantegazza wrote:
  
  
On mardi 17 juin 2008, John Stowers wrote:



  

  bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/
  

Many thanks, but I can't get the package: bzr waits forever, after
creating the pygtk-lcd-widget/ dir and .bzr/ sub-dir...

  
  Are you sure?

I just did a fresh checkout on another pc and it worked fine
  

With this command?:

$ bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/

(I'm not familiar with bazar...). As I said, some files are first 
downloaded (I can see a progressbar going to 100%), then, it does nothing, 
and does not return...

  
  
Weird, maybe a bzr bug. What does the output with 

bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/ --verbose

say? Can anyone else test this. You can zoom in and out with scroll
wheel (and change brightness with ctrl+scroll). Double click to change
text.

I attached the files also.



  
  
  
  

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
  


Hi

I had to upgrade bzr to version .92 or later after which it worked OK.

Regards, Paul


___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-17 Thread Frédéric Mantegazza
On mardi 17 juin 2008, Gian Mario Tagliaretti wrote:

> 2008/6/17 John Stowers <[EMAIL PROTECTED]>:> Weird, maybe a
> bzr bug. What does the output with
>
> > bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/ --verbose
> >
> > say? Can anyone else test this. You can zoom in and out with scroll
> > wheel (and change brightness with ctrl+scroll). Double click to change
> > text.
>
> Works here:
>
> [EMAIL PROTECTED]:~/Repos$ bzr branch
> http://johnstowers.co.nz/bzr/pygtk-lcd-widget/ Branched 2 revision(s).

Ok, it seems to be a bazaar problem on my system: I tried to update another 
repository, which used to work, and it also failed...

-- 
   Frédéric

   http://www.gbiloba.org
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-17 Thread Gian Mario Tagliaretti
2008/6/17 John Stowers <[EMAIL PROTECTED]>:> Weird, maybe a
bzr bug. What does the output with
>
> bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/ --verbose
>
> say? Can anyone else test this. You can zoom in and out with scroll
> wheel (and change brightness with ctrl+scroll). Double click to change
> text.

Works here:

[EMAIL PROTECTED]:~/Repos$ bzr branch 
http://johnstowers.co.nz/bzr/pygtk-lcd-widget/
Branched 2 revision(s).

cheers
-- 
Gian Mario Tagliaretti
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-17 Thread Frédéric Mantegazza
On mardi 17 juin 2008, John Stowers wrote:

> Weird, maybe a bzr bug. What does the output with
>
> bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/ --verbose
>
> say?

Absolutly nothing :o/

> Can anyone else test this. You can zoom in and out with scroll 
> wheel (and change brightness with ctrl+scroll). Double click to change
> text.
>
> I attached the files also.

Works fine for me :o)

-- 
   Frédéric

   http://www.gbiloba.org
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-17 Thread John Stowers
On Tue, 2008-06-17 at 11:06 +0200, Frédéric Mantegazza wrote:
> On mardi 17 juin 2008, John Stowers wrote:
> 
> > > > bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/
> > >
> > > Many thanks, but I can't get the package: bzr waits forever, after
> > > creating the pygtk-lcd-widget/ dir and .bzr/ sub-dir...
> >
> > Are you sure?
> >
> > I just did a fresh checkout on another pc and it worked fine
> 
> With this command?:
> 
> $ bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/
> 
> (I'm not familiar with bazar...). As I said, some files are first 
> downloaded (I can see a progressbar going to 100%), then, it does nothing, 
> and does not return...

Weird, maybe a bzr bug. What does the output with 

bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/ --verbose

say? Can anyone else test this. You can zoom in and out with scroll
wheel (and change brightness with ctrl+scroll). Double click to change
text.

I attached the files also.



> 
# Character set for the Squeezebox display

00
0
0
0
0
0
0
0

01
0
0
0
0
0
0
0

02
0
0
0
0
0
0
0

03
0
0
0
0
0
0
0

04
0
0
0
0
0
0
0

05
0
0
0
0
0
0
0

06
0
0
0
0
0
0
0

07
0
0
0
0
0
0
0

08
0
0
0
0
0
0
0

09
0
0
0
0
0
0
0

0a
0
0
0
0
0
0
0

0b
0
0
0
0
0
0
0

0c
0
0
0
0
0
0
0

0d
0
0
0
0
0
0
0

0e
0
0
0
0
0
0
0

0f
0
0
0
0
0
0
0

10
1
1
1
1
1
1
1

11
11000
11000
11000
11000
11000
11000
11000

12
11100
11100
11100
11100
11100
11100
11100

13
0
0
0
0
0
0
0

14
1
1
1
1
1
1
1

15
0
0
0
0
0
0
0

16
00111
00111
00111
00111
00111
00111
00111

17
00011
00011
00011
00011
00011
00011
00011

18
1
1
1
1
1
1
1

19
00100
00110
00101
00101
01101
11100
01100

1a
11000
11000
0
00111
01000
01000
00111

1b
11000
11000
0
0
01000
01110
01000

1c
0
0
1
01110
00100
0
0

1d
0
01000
01100
01110
01100
01000
0

1e
0
00010
00110
01110
00110
00010
0

1f
0
0
00100
01110
1
0
0

20
0
0
0
0
0
0
0

21
00100
00100
00100
00100
0
0
00100

22
01010
01010
01010
0
0
0
0

23
01010
01010
1
01010
1
01010
01010

24
00100
0
10100
01110
00101
0
00100

25
11000
11001
00010
00100
01000
10011
00011

26
01100
10010
10100
01000
10101
10010
01101

27
01100
00100
01000
0
0
0
0

28
00010
00100
01000
01000
01000
00100
00010

29
1
01000
00100
00100
00100
01000
1

2a
0
00100
10101
01110
10101
00100
0

2b
0
00100
00100
1
00100
00100
0

2c
0
0
0
0
01100
00100
01000

2d
0
0
0
1
0
0
0

2e
0
0
0
0
0
11000
11000

2f
0
1
00010
00100
01000
1
0

30
01110
10001
10011
10101
11001
10001
01110

31
00100
01100
00100
00100
00100
00100
01110

32
01110
10001
1
00010
00100
01000
1

33
1
00010
00100
00010
1
10001
01110

34
00010
00110
01010
10010
1
00010
00010

35
1
1
0
1
1
10001
01110

36
00110
01000
1
0
10001
10001
01110

37
1
1
00010
00100
01000
01000
01000

38
01110
10001
10001
01110
10001
10001
01110

39
01110
10001
10001
0
1
00010
01100

3a
0
01100
01100
0
01100
01100
0

3b
0
01100
01100
0
01100
00100
01000

3c
00010
00100
01000
1
01000
00100
00010

3d
0
0
1
0
1
0
0

3e
1
01000
00100
00010
00100
01000
1

3f
01110
10001
1
00010
00100
0
00100

40
01110
10001
1
01101
10101
10101
01110

41
01110
10001
10001
10001
1
10001
10001

42
0
10001
10001
0
10001
10001
0

43
01110
10001
1
1
1
10001
01110

44
11100
10010
10001
10001
10001
10010
11100

45
1
1
1
0
1
1
1

46
1
1
1
0
1
1
1

47
01110
10001
1
10111
10001
10001
0

48
10001
10001
10001
1
10001
10001
10001

49
01110
00100
00100
00100
00100
00100
01110

4a
00111
00010
00010
00010
00010
10010
01100

4b
10001
10010
10100
11000
10100
10010
10001

4c
1
1
1
1
1
1
1

4d
10001
11011
10101
10101
10001
10001
10001

4e
10001
10001
11001
10101
10011
10001
10001

4f
01110
10001
10001
10001
10001
10001
01110

50
0
10001
10001
0
1
1
1

51
01110
10001
10001
10001
10101
10010
01101

52
0
10001
10001
0
10100
10010
10001

53
0
1
1
01110
1
1
0

54
1
00100
00100
00100
00100
00100
00100

55
10001
10001
10001
10001
10001
10001
01110

56
10001
10001
10001
100

Re: [pygtk] Re: LCD-style display widget

2008-06-17 Thread Frédéric Mantegazza
On mardi 17 juin 2008, John Stowers wrote:

> > > bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/
> >
> > Many thanks, but I can't get the package: bzr waits forever, after
> > creating the pygtk-lcd-widget/ dir and .bzr/ sub-dir...
>
> Are you sure?
>
> I just did a fresh checkout on another pc and it worked fine

With this command?:

$ bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/

(I'm not familiar with bazar...). As I said, some files are first 
downloaded (I can see a progressbar going to 100%), then, it does nothing, 
and does not return...

-- 
   Frédéric

   http://www.gbiloba.org
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-17 Thread John Stowers
On Tue, 2008-06-17 at 08:02 +0200, Frédéric Mantegazza wrote:
> On mardi 17 juin 2008, John Stowers wrote:
> 
> > On Mon, 2008-06-16 at 18:21 +0200, Frédéric Mantegazza wrote:
> > > On lundi 16 juin 2008, Jeffrey Barish wrote:
> > > > I noticed that the application gslimp3
> > > > (http://jefke.free.fr/coding/python/gslimp3/) has such a display.
> > > > Perhaps you can find something useful in its code.
> > >
> > > Nice! Thanks for the link :o)
> >
> > I thought this widget was cool so I extracted it from the gslim
> > application. You can see the standalone lcd widget at
> >
> > bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/
> 
> Many thanks, but I can't get the package: bzr waits forever, after creating 
> the pygtk-lcd-widget/ dir and .bzr/ sub-dir...

Are you sure? 

I just did a fresh checkout on another pc and it worked fine

John

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-16 Thread Frédéric Mantegazza
On mardi 17 juin 2008, John Stowers wrote:

> On Mon, 2008-06-16 at 18:21 +0200, Frédéric Mantegazza wrote:
> > On lundi 16 juin 2008, Jeffrey Barish wrote:
> > > I noticed that the application gslimp3
> > > (http://jefke.free.fr/coding/python/gslimp3/) has such a display.
> > > Perhaps you can find something useful in its code.
> >
> > Nice! Thanks for the link :o)
>
> I thought this widget was cool so I extracted it from the gslim
> application. You can see the standalone lcd widget at
>
> bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/

Many thanks, but I can't get the package: bzr waits forever, after creating 
the pygtk-lcd-widget/ dir and .bzr/ sub-dir...

-- 
   Frédéric

   http://www.gbiloba.org
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-16 Thread John Stowers
On Mon, 2008-06-16 at 18:21 +0200, Frédéric Mantegazza wrote:
> On lundi 16 juin 2008, Jeffrey Barish wrote:
> 
> > I noticed that the application gslimp3
> > (http://jefke.free.fr/coding/python/gslimp3/) has such a display. 
> > Perhaps you can find something useful in its code.
> 
> Nice! Thanks for the link :o)

I thought this widget was cool so I extracted it from the gslim
application. You can see the standalone lcd widget at

bzr branch http://johnstowers.co.nz/bzr/pygtk-lcd-widget/

John

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Re: LCD-style display widget

2008-06-16 Thread Frédéric Mantegazza
On lundi 16 juin 2008, Jeffrey Barish wrote:

> I noticed that the application gslimp3
> (http://jefke.free.fr/coding/python/gslimp3/) has such a display. 
> Perhaps you can find something useful in its code.

Nice! Thanks for the link :o)

-- 
   Frédéric

   http://www.gbiloba.org
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/