Re: [pygtk] Re: LCD-style display widget
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 jefke(at)free.fr # 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, 0: #303030 } if brightness not in
Re: [pygtk] gtk.ListStore columns in a gtk.ComboBox (added full code listing)
Hi, Having recently had my own struggle with ComboBoxen (more specifically ComboBoxEntry's), I can sum up my experience with the following statement: (Py)Gtk wants ComboBoxes' models to have a str column first! I've tried using a ListStore(gobject.TYPE_PYOBJECT) (for my own models) with custom cell renderers specified (using set_cell_data_func()) and lost hours trying to get it to work. In the end, I ended up adding a str column as the _first_ column and copying a string representation of my objects to that column. This, in the end, does what I want: it saves a reference to one of my models in the ListStore. Moral of the story: adding a str column as the first column solved all my problems. If you want, you can check how I handle ComboBoxEntries: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/spelt/spelt/gui/edit_area.py In the first paragraph, I said (PyGtk), because I'm not sure if this is because of PyGtk or the C Gtk lib itself. The weird thing is that I'm using a ListStore(gobject.TYPE_PYOBJECT) with a TreeView and it works just great (in PyGtk and Gtk#)! P. S. I'm not sure why, but I don't seem to receive any responses from Mr. Kintanar. :/ Isaac Alston wrote: 2008/6/22 Bertrand Son Kintanar [EMAIL PROTECTED]: [...snip - code sample] notice the if statement highlighted. this will show the column if we set the flag to visible otherwise it will not show the column Yes, I think this might work, although I am dubious about: self.inputTreeView.append_column(column) because I don't think ComboBox has that method. However, this seems to be a lot of work... I was under the impression that gtk.ListStore was the model in a sort of mvc system in which the view is independent from the model which should easily allow different views. In this instance, it doesn't appear to be the case, which is annoying. I will sleep on this :-) . Thanks for your efforts, begin:vcard fn:Walter Leibbrandt n:Leibbrandt;Walter org:Translate.org.za adr:;;;Pretoria;Gauteng;;South Africa email;internet:[EMAIL PROTECTED] title:Developer tel;work:(012) 460 1095 x-mozilla-html:FALSE url:http://translate.org.za version:2.1 end:vcard ___ 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] Scrolling gtk.Viewport to a specific location
Mitko Haralanov schrieb: I have a gtk.ScrolledWindow, which has a gtk.VBox added with a gtk.Viewport. What I would like to do is be able to scroll the gtk.ScrolledWindow to a specific location (one of the gtk.VBox children). I know how to do the actual scrolling (using the h/vadjustments) but how do I determine how much to scroll it by so the correct child is in view? Thanks for the help? Does this help you: http://faq.pygtk.org/index.py?req=showfile=faq10.010.htp 10.10. http://faq.pygtk.org/index.py?req=showfile=faq10.010.htp How do I adjust a ScrolledWindow to adjust to a given child widget? One common request is to get a ScrolledWindow to adjust to display one of the widgets it contains -- frequently you'd like to adjust the scrollbar to display the widget that receives focus. This is possible by using the set_value method of the ScrolledWindow's adjustment object in conjunction with the child widget's `focus_in_event' signal. An (untested) example follows: def focus_in(widget, event, adj): alloc = widget.get_allocation() if alloc.y adj.value or alloc.y adj.value + adj.page_size: adj.set_value(min(alloc.y, adj.upper-adj.page_size)) scrolled_window = gtk.ScrolledWindow() adj = scrolled_window.get_vadjustment() # ... create child widget child.connect('focus_in_event', focus_in, adj) This should make the scrollbar adjust automatically whenever child receives focus. -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de ___ 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] gobject.child_watch_add on Windows?
Hi all, I couldn't persuade gobject.child_watch_add to work on Windows. I'm passing it a process ID as received from subprocess.Popen but it seems to want one of those process handle things. Is this function only meant to work with processes created via gobject.spawn_async? Problem with process handles is that I don't know how to terminate processes from the command line using them, whereas doing it with an actual process ID is fairly easy. Any help appreciated. Geoff Bache ___ 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] gtk.ListStore columns in a gtk.ComboBox
On Sun, Jun 22, 2008 at 4:09 PM, Isaac Alston [EMAIL PROTECTED] wrote: I am making a search function where users can select two fields which they'd like to search on in a database. I'm having trouble displaying a single column from a gtk.ListStore with multiple columns in a gtk.ComboBox correctly. I have two columns in my ListStore: 'id' and 'field'. 'field' holds text like 'Artist' and 'Name'. I have an id so I can compare their selection easily - I do not want to compare names like 'Artist' and 'Name' in the code, especially as they will be i18ned too. I've tried getting the ComboBox to display only the second column with add_attribute, but it seems to add the 'id' column by default and displays both the id and field side-by-side. How do I stop this so that it only shows the 'field' column? I think the combo box you get from the widget tree already has a cell renderer text that renders the first column in the list store. If so, you could just change the column that the renderer will render: combo.set_attribute(combo.get_cells()[0], text, 1) -- mvh Björn ___ 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] Error message
On Fri, Jun 20, 2008 at 10:35 AM, Frédéric [EMAIL PROTECTED] wrote: /usr/local/lib/python2.4/site-packages/papywizard/view/configDialog.py:74: GtkWarning: gtk_tree_row_reference_new: assertion `GTK_IS_TREE_MODEL (model)' failed self.wTree = gtk.glade.XML(gladeFile) /usr/local/lib/python2.4/site-packages/papywizard/view/configDialog.py:74: GtkWarning: gtk_cell_view_set_displayed_row: assertion `GTK_IS_TREE_MODEL (cell_view-priv-model)' failed self.wTree = gtk.glade.XML(gladeFile) Any idea of the problem(s)? The error messages suggest that you are calling the method gtk.CellView.set_displayed_row on a cell view that does not have a model attached to it. I an send the .glade file if needed... Please do. -- mvh Björn ___ 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] right-click events
Hi, is there any way to only capture right-mouse-button clicks? All I can seem to find is double- and triple-clicking. I know Tkinter can capture right-button clicks, so I was hoping GTK could as well. ___ 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/