Re: [pygtk] [Fwd: Using cairo to shape windows]
I have changed it to be a simple window with a HScale slider in the middle to dictate how round the edges are, so that it might actually be a demonstratable application, as per pachi's request. Additionally, the window when resized will scale and maintain the rounding of the corner. Natan >On Sun, 04 Jun 2006 15:29:12 +0100 >"Gustavo J. A. M. Carneiro" <[EMAIL PROTECTED]> wrote: > I have modified it slightly in order to expunge the last traces of > gdk.GC and gdk.draw_* APIs, which are now deprecated. > > Cheers. > > Sáb, 2006-06-03 às 20:13 -0300, Johan Dahlin escreveu: > > anexo mensagem de e-mail (Using cairo to shape windows) > > > -- Mensagem Reencaminhada -- > > > De: Natan Zohar <[EMAIL PROTECTED]> > > > Para: [EMAIL PROTECTED] > > > Assunto: Using cairo to shape windows > > > Data: Sat, 03 Jun 2006 16:31:50 -0400 > > > Aplicação de Email: Sylpheed-Claws 2.2.0 (GTK+ 2.8.17; > > > i686-pc-linux-gnu) > > > > > > Hi, > > > > > > pachi (from #pygtk on GIMPNet) told me to shoot along an > > > email over here with some sample pygtk code for shaping windows > > > (as there isn't much out there about it). Attached is some code > > > for shaping a window into a rounded rectangle and (commented out) > > > a circle, that I wrote. I hope it helps you. > > > > > > Natan Zohar > > ___ > > 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/ > -- > Gustavo J. A. M. Carneiro > <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> > The universe is always one step beyond logic #!/usr/bin/env python # A simple demonstration of using cairo to shape windows. # Natan 'whatah' Zohar import gtk import math import cairo class ShapedGUI: def __init__(self): self.window = gtk.Window() self.window.set_default_size(200,200) self.window.set_border_width(10) self.rounded = 0 self.padding = 5 self.scale = gtk.HScale() self.scale.set_range(0, 100) self.window.add(self.scale) self.window.connect('size-allocate', self.size_allocate_cb) self.scale.connect('adjust-bounds', self.slider_moved_cb) self.window.show_all() # Find how round the edges should be based on slider value (maximum rounding is = min(width,height)/2) def find_edge_rounding(self): val = self.scale.get_value() val = min(100, val) val = max(self.padding, val) self.rounded = (val / 100.0) * min(self.width, self.height) / 2 - self.padding # Slide callback def slider_moved_cb(self, obj, data): self.window.set_default_size(self.width, self.height) # size allocation callback. # Shape the window into a rounded rectangle def size_allocate_cb(self, obj, allocation): w,h = allocation.width, allocation.height self.width, self.height = h,w self.find_edge_rounding() bitmap = gtk.gdk.Pixmap(None, w, h, 1) cr = bitmap.cairo_create() # Clear the bitmap # Clear the bitmap cr.set_source_rgb(0,0,0) cr.set_operator(cairo.OPERATOR_DEST_OUT) cr.paint() cr.set_operator(cairo.OPERATOR_OVER) # Draw our shape into the pixmap using cairo # Let's try drawing a rectangle with rounded edges. padding=self.padding # Padding from the edges of the window rounded=self.rounded # How round to make the edges cr.set_source_rgb(0,0,0) # Move to top corner cr.move_to(0+padding+rounded, 0+padding) # Top right corner and round the edge cr.line_to(w-padding-rounded, 0+padding) cr.arc(w-padding-rounded, 0+padding+rounded, rounded, math.pi/2, 0) # Bottom right corner and round the edge cr.line_to(w-padding, h-padding-rounded) cr.arc(w-padding-rounded, h-padding-rounded, rounded, 0, math.pi/2) # Bottom left corner and round the edge. cr.line_to(0+padding+rounded, h-padding) cr.arc(0+padding+rounded, h-padding-rounded, rounded, math.pi+math.pi/2, math.pi) # Top left corner and round the edge cr.line_to(0+padding, 0+padding+rounded) cr.arc(0+padding+rounded, 0+padding+rounded, rounded, math.pi/2, 0) # Fill in the shape. cr.fill() # Set the window shape self.window.shape_combine_mask(bitmap, 0, 0) self.window.show() shapedWin = ShapedGUI() shapedWin.window.connect("destroy", lambda w: gtk.main_quit()) gtk.main() ___ 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] User defined interface
On Sun, 2006-04-06 at 10:36 +0200, Preben Randhol wrote: > Hi > > First I'm new to Python and PyGTK, but I have used Gtk for some years > now. Currently I'm making an application with PyGTK. The application is > supposed to show some data that is read from an XML file. Now what I > need is to give the user the flexibility that she/he can set up how > she/he wants the display widget to look like. My idea is to use a table > widget as the base and that the user can put Labels, Pixmaps, and choose > where in the table to display the data (and later also be able to edit > data). > > So my question is: Given that the layout is defined in an XML file is it > better to: > >1. in some way (if possible) to use libglade to read a XML file that > doesn't have a main window but only a Table widget as the base? > As the layout will change depending on what data to display. > >2. make ones own parser to read and generate the display GUI from the > XML structure. I'm also thinking that later when I want to add > edit capabilities I need to hook callbacks to the different > edit widgets and that may be easier without libglade > >3. or has somebody already made something like this that is available > in as a library or similar? > > The program will be licensed as GPL or BSD if finished. > > Thanks in advanced for any hints. > > Preben Look at Gaspacho and Kiwi. It sounds like that may be able to do what you would like. Or at least part way to what you are trying to achieve. -- Brian <[EMAIL PROTECTED]> ___ 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] [Fwd: Using cairo to shape windows]
I have modified it slightly in order to expunge the last traces of gdk.GC and gdk.draw_* APIs, which are now deprecated. Cheers. Sáb, 2006-06-03 às 20:13 -0300, Johan Dahlin escreveu: > anexo mensagem de e-mail (Using cairo to shape windows) > > -- Mensagem Reencaminhada -- > > De: Natan Zohar <[EMAIL PROTECTED]> > > Para: [EMAIL PROTECTED] > > Assunto: Using cairo to shape windows > > Data: Sat, 03 Jun 2006 16:31:50 -0400 > > Aplicação de Email: Sylpheed-Claws 2.2.0 (GTK+ 2.8.17; > > i686-pc-linux-gnu) > > > > Hi, > > > > pachi (from #pygtk on GIMPNet) told me to shoot along an email over > > here with some sample pygtk code for shaping windows (as there isn't > > much out there about it). Attached is some code for shaping a window > > into a rounded rectangle and (commented out) a circle, that I wrote. I > > hope it helps you. > > > > Natan Zohar > ___ > 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/ -- Gustavo J. A. M. Carneiro <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> The universe is always one step beyond logic #!/usr/bin/env python # A simple demonstration of using cairo to shape windows. # Natan 'whatah' Zohar import gtk import math import cairo class ShapedGUI: def __init__(self): self.window = gtk.Window() self.window.show() # We show here so the window gets a border on it by the WM x,y,w,h = self.window.get_allocation() self.window.set_size_request(w,h) self.window.connect('size-allocate', self.reshaperect) #self.window.connect('size-allocate', self.reshapecircle) self.window.show() # Shape the window into a rounded rectangle def reshaperect(self, obj, allocation): w,h = allocation.width, allocation.height bitmap = gtk.gdk.Pixmap(None, w, h, 1) cr = bitmap.cairo_create() # Clear the bitmap cr.set_source_rgb(0,0,0) cr.set_operator(cairo.OPERATOR_DEST_OUT) cr.paint() cr.set_operator(cairo.OPERATOR_OVER) # Draw our shape into the pixmap using cairo # Let's try drawing a rectangle with rounded edges. padding=5 # Padding from the edges of the window rounded=30 # How round to make the edges cr.set_source_rgba(0,0,0,1) # Move to top corner cr.move_to(0+padding+rounded, 0+padding) # Top right corner and round the edge cr.line_to(w-padding-rounded, 0+padding) cr.arc(w-padding-rounded, 0+padding+rounded, rounded, math.pi/2, 0) # Bottom right corner and round the edge cr.line_to(w-padding, h-padding-rounded) cr.arc(w-padding-rounded, h-padding-rounded, rounded, 0, math.pi/2) # Bottom left corner and round the edge. cr.line_to(0+padding+rounded, h-padding) cr.arc(0+padding+rounded, h-padding-rounded, rounded, math.pi+math.pi/2, math.pi) # Top left corner and round the edge cr.line_to(0+padding, 0+padding+rounded) cr.arc(0+padding+rounded, 0+padding+rounded, rounded, math.pi/2, 0) # Fill in the shape. cr.fill() # Set the window shape self.window.shape_combine_mask(bitmap, 0, 0) self.window.show() # Reshape the window into a circle def reshapecircle(self, obj, allocation): w,h = allocation.width, allocation.height bitmap = gtk.gdk.Pixmap(None, w, h, 1) cr = bitmap.cairo_create() # Clear the bitmap cr.set_source_rgb(0,0,0) cr.set_operator(cairo.OPERATOR_DEST_OUT) cr.paint() cr.set_operator(cairo.OPERATOR_OVER) # Draw our shape into the bitmap using cairo cr.set_source_rgb(0,0,0) cr.arc(w/2,h/2,min(h,w)/2,0,2*math.pi) cr.fill() # Set the window shape self.window.shape_combine_mask(bitmap, 0, 0) self.window.show() shapedWin = ShapedGUI() shapedWin.window.connect("destroy", lambda w: gtk.main_quit()) gtk.main() signature.asc Description: Esta é uma parte de mensagem assinada digitalmente ___ 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/
[pygtk] User defined interface
Hi First I'm new to Python and PyGTK, but I have used Gtk for some years now. Currently I'm making an application with PyGTK. The application is supposed to show some data that is read from an XML file. Now what I need is to give the user the flexibility that she/he can set up how she/he wants the display widget to look like. My idea is to use a table widget as the base and that the user can put Labels, Pixmaps, and choose where in the table to display the data (and later also be able to edit data). So my question is: Given that the layout is defined in an XML file is it better to: 1. in some way (if possible) to use libglade to read a XML file that doesn't have a main window but only a Table widget as the base? As the layout will change depending on what data to display. 2. make ones own parser to read and generate the display GUI from the XML structure. I'm also thinking that later when I want to add edit capabilities I need to hook callbacks to the different edit widgets and that may be easier without libglade 3. or has somebody already made something like this that is available in as a library or similar? The program will be licensed as GPL or BSD if finished. Thanks in advanced for any hints. Preben ___ 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/