def configure( self, widget, event, *args ): """Track changes in width, height """ #only do this if we have been realized if not self.flags() & gtk.REALIZED: return # create a memory pixmap to render into a_win = self._area.get_window() self._pixmap = gtk.create_pixmap( a_win, event.width, event.height ) style = self.get_style() if self.title_font is None: try: self.title_font = gtk.load_font( self.title_font_spec ) except: self.title_font = style.font self.title_height = self.title_font.ascent if self.cell_font is None: try: self.cell_font = gtk.load_font( self.cell_font_spec ) except: self.cell_font = style.font self.row_height = self.cell_font.ascent self.bCalcAdjustments=gtk.TRUE
def configure(self, widget, event, *args): """Track changes in width, height """ #only do this if we have been realized if not self.flags() & gtk.REALIZED: return # create a memory pixmap to render into a_win = self._area.get_window() self._pixmap = gtk.create_pixmap(a_win, event.width, event.height) style = self.get_style() if self.title_font is None: try: self.title_font = gtk.load_font(self.title_font_spec) except: self.title_font = style.font self.title_height = self.title_font.ascent if self.cell_font is None: try: self.cell_font = gtk.load_font(self.cell_font_spec) except: self.cell_font = style.font self.row_height = self.cell_font.ascent self.bCalcAdjustments = gtk.TRUE
def expose_event(self, *args): #get the window and graphic context resize = FALSE if self.gdk_font is None: resize = TRUE if self.font is None: self.gdk_font = self.get_style().font else: self.gdk_font = gtk.load_font(self.font) w = self.gdk_font.width(self.text) h = self.gdk_font.height(self.text) if resize: self.set_usize(w + 6, h + 6) self.queue_draw() win = self.get_window() #self.draw_rectangle(self.get_style().black_gc, gtk.FALSE, 0, 0, win.width-1, win.height-1) self.draw_rectangle(self.get_style().white_gc, gtk.TRUE, 0, 0, win.width - 1, win.height - 1) self.draw_string(self.gdk_font, self.get_style().black_gc, 3, h + 3, self.text) return gtk.FALSE
def load_font(self): """ load the real GDK font associated with this font spec so we can do calculations on it. """ if self.gdk_font is not None: return self.gdk_font = gtk.load_font(str(self))
def load_font( self ): """ load the real GDK font associated with this font spec so we can do calculations on it. """ if self.gdk_font is not None: return self.gdk_font = gtk.load_font(str(self))
def draw(self, color): global pixmap global pixmapGC global drawingArea x = self.loc.x * WINDOW_WIDTH y = self.loc.y * WINDOW_HEIGHT pixmapGC.foreground = color pixmapGC.line_width = 2 gtk.draw_rectangle(pixmap, pixmapGC, gtk.FALSE, x-3, y-3, 6, 6) pixmapGC.foreground = whiteColor gtk.draw_string(pixmap, gtk.load_font("fixed"), pixmapGC, x+3, y-5, str(self.id)) drawingArea.queue_draw()
def __init__(self, reader, msg): self.message = msg msg = self.message.getheaders()+"\n\n"+\ self.message.getbody() sqmail.gui.viewer.Viewer.__init__(self, reader, ["*", "", msg], "headerspane") font = gtk.load_font(sqmail.preferences.get_textmessagefont()) # Ensure the text box is 80 columns wide. width = gtk.gdk_char_width(font, "m")*82 # The text box is guaranteed to be empty. self.viewer_widget.messagetext.freeze() self.viewer_widget.messagetext.set_usize(width, 0) self.viewer_widget.messagetext.insert(font, None, None, msg) self.viewer_widget.messagetext.thaw()
def draw(self, color): if (self.loc == None): print 'Cannot draw '+self.tostring() return global pixmap global pixmapGC global drawingArea x = (self.getlocation().x / SCALING) * WINDOW_WIDTH y = (self.getlocation().y / SCALING) * WINDOW_HEIGHT pixmapGC.foreground = color pixmapGC.line_width = 2 gtk.draw_rectangle(pixmap, pixmapGC, gtk.FALSE, x-3, y-3, 6, 6) pixmapGC.foreground = whiteColor gtk.draw_string(pixmap, gtk.load_font("fixed"), pixmapGC, x+3, y-5, str(self.id)) drawingArea.queue_draw()
def __init__(self, reader, a): sqmail.gui.viewer.Viewer.__init__(self, reader, a, "textmessage") font = gtk.load_font(sqmail.preferences.get_textmessagefont()) # Ensure the text box is 80 columns wide. width = gtk.gdk_char_width(font, "m")*82 # The text box is guaranteed to be empty. self.viewer_widget.messagetext.freeze() self.viewer_widget.messagetext.set_usize(width, 0) if (self.attachment[1] == "text/quoted-printable"): infp = cStringIO.StringIO(self.attachment[2]) outfp = cStringIO.StringIO() quopri.decode(infp, outfp) body = outfp.getvalue() else: body = self.attachment[2] self.viewer_widget.messagetext.insert(font, None, None, body) self.viewer_widget.messagetext.thaw()
def __init__(self, text='Sample', font=None): """ """ gtk.GtkDrawingArea.__init__(self) self.size(10, 10) self.connect('expose-event', self.expose_event) self.connect('configure-event', self.configure_event) self.connect('realize', self.realize_event) self.connect('unrealize', self.unrealize_event) self.text = text self.font = font if font is not None: self.gdk_font = gtk.load_font(font) else: self.gdk_font = None self.set_events(gtk.GDK.BUTTON_PRESS_MASK)
def style_vfolder(self, vf, style): if vf.getunread(): fg = sqmail.preferences.get_vfolderunreadfg() bg = sqmail.preferences.get_vfolderunreadbg() font = sqmail.preferences.get_vfolderunreadfont() else: fg = sqmail.preferences.get_vfolderfg() bg = sqmail.preferences.get_vfolderbg() font = sqmail.preferences.get_vfolderfont() try: style.font = gtk.load_font(font) except RuntimeError: print "Couldn't load", font colormap = self.widget.folderlist.get_colormap() fg = colormap.alloc(fg[0], fg[1], fg[2]) bg = colormap.alloc(bg[0], bg[1], bg[2]) style.fg[gtk.STATE_NORMAL] = fg style.base[gtk.STATE_NORMAL] = bg return (fg, bg)
def main(): try: opts, args = getopt.getopt(sys.argv[1:], "vhm", ["version", "help", "disable-menu"]) except getopt.GetoptError: usage() for o, a in opts: if o in ("-v", "--version"): print(version) sys.exit() if o in ("-h", "--help"): usage() if o in ("-m", "--disable-menu"): gui["disable_menu"] = 1 global hive hive = hiveconf.open_hive("/usr/local/etc/clarence.hconf") gui["fixed_font"] = gtk.load_font(hive.get_string("/fixed_font", default_fixed_font)) create_main_window() gtk.mainloop() pcalc_write_config()
def expose_event(self, *args): #get the window and graphic context resize = FALSE if self.gdk_font is None: resize = TRUE if self.font is None: self.gdk_font = self.get_style().font else: self.gdk_font = gtk.load_font(self.font) w = self.gdk_font.width(self.text) h = self.gdk_font.height(self.text) if resize: self.set_usize(w + 6, h + 6) self.queue_draw() win = self.get_window() #self.draw_rectangle(self.get_style().black_gc, gtk.FALSE, 0, 0, win.width-1, win.height-1) self.draw_rectangle(self.get_style().white_gc, gtk.TRUE, 0, 0, win.width-1, win.height-1) self.draw_string(self.gdk_font, self.get_style().black_gc, 3, h+3, self.text) return gtk.FALSE
def main(): try: opts, args = getopt.getopt(sys.argv[1:], "vhm", ["version", "help", "disable-menu"]) except getopt.GetoptError: usage() for o, a in opts: if o in ("-v", "--version"): print(version) sys.exit() if o in ("-h", "--help"): usage() if o in ("-m", "--disable-menu"): gui["disable_menu"] = 1 global hive hive = hiveconf.open_hive("/usr/local/etc/clarence.hconf") gui["fixed_font"] = gtk.load_font( hive.get_string("/fixed_font", default_fixed_font)) create_main_window() gtk.mainloop() pcalc_write_config()
# This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import gtk import string import traceback # Font caching normalFont = gtk.load_font( "-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-iso8859-1") boldFont = gtk.load_font( "-adobe-courier-bold-r-normal-*-*-120-*-*-m-*-iso8859-1") from twisted import copyright from twisted.internet import tcp, ingtkernet ingtkernet.install() from twisted.spread import pb from twisted.spread.ui import gtkutil def gtktextget(text): return text.get_chars(0, text.get_length()) def dontgo(*ev):
def __init__(self, reader, message, addrlist): self.reader = reader self.message = message composewin = reader.readglade("composewin", self) self.widget = sqmail.gui.utils.WidgetStore(composewin) self.font = gtk.load_font(sqmail.preferences.get_composefont()) # Ensure the text box is 80 columns wide. width = gtk.gdk_char_width(self.font, "m")*82 # Set up the header fields. if addrlist: self.widget.tofield.set_text(sqmail.gui.utils.render_addrlist(addrlist)) self.widget.fromfield.set_text(sqmail.preferences.get_fromaddress()) if message: i = self.message.getsubject() if (i[:3] == "Re:") or (i[:3] == "re:"): self.widget.subjectfield.set_text(i) else: self.widget.subjectfield.set_text("Re: "+i) # Set up the sign button. self.signaturespopup = gtk.GtkMenu() signatures = os.listdir(os.path.expanduser("~")) signatures.sort() for i in signatures: if (i[0:10] == ".signature"): w = gtk.GtkMenuItem(i) w.show() w.connect("activate", sqmail.gui.utils.Callback(self)["on_sign_with"]) w.set_data("file", i) self.signaturespopup.append(w) # Set up the quote button. if message: self.quotepopup = gtk.GtkMenu() attachments = message.mimeflatten() for i in attachments: if (i[1] in sqmail.gui.textviewer.displayable): w = gtk.GtkMenuItem(i[1]+": "+i[0]) w.show() w.connect("activate", sqmail.gui.utils.Callback(self)["on_quote_with"]) w.set_data("msg", i[2]) self.quotepopup.append(w) else: self.widget.quotebutton.set_sensitive(0) self.widget.textbox.freeze() self.widget.textbox.set_usize(width, 0) # These two lines set the font. *shrug* self.widget.textbox.insert(self.font, None, None, "\n") self.widget.textbox.delete_text(0, 1) # We want word wrapping. self.widget.textbox.set_word_wrap(1) self.widget.textbox.thaw()
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import gtk import string import traceback # Font caching normalFont = gtk.load_font("-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-iso8859-1") boldFont = gtk.load_font("-adobe-courier-bold-r-normal-*-*-120-*-*-m-*-iso8859-1") from twisted import copyright from twisted.internet import tcp, ingtkernet ingtkernet.install() from twisted.spread import pb from twisted.spread.ui import gtkutil def gtktextget(text): return text.get_chars(0,text.get_length()) def dontgo(*ev): return gtk.TRUE class ResponseWindow(gtk.GtkWindow): def __init__(self,question,default,callback):
def __init__(self): gtkextra.Sheet.__init__(self, 1000, 26, "Example 1") colormap = self.get_colormap() self.set_background(colormap.alloc_color("light yellow")) self.set_grid(colormap.alloc_color("light blue")) for column in xrange(self.get_columns_count()): name = chr(ord("A") + column) self.column_button_add_label(column, name) self.set_column_title(column, name) self.row_button_add_label(0, "This is\na multiline\nlabel") self.row_button_justify(0, gtk.JUSTIFY_RIGHT) range = gtkextra.SheetRange(1, 1, 2, 3) self.clip_range(range) # As long as a GdkFont object is used a reference to it must be kept. self.font1 = gtk.load_font(self.xfont1) if not self.font1: print "Couldn't load", self.xfont1 else: self.range_set_font(range, self.font1) self.range_set_foreground(range, colormap.alloc_color("red")) self.set_cell(1, 2, gtk.JUSTIFY_CENTER, "Welcome to") range.row0 = 2 self.font2 = load_font(self.xfont2) if not self.font2: print "Couldn't load", self.xfont2 else: self.range_set_font(range, self.font2) self.range_set_foreground(range, colormap.alloc_color("blue")) self.set_cell(2, 2, gtk.JUSTIFY_CENTER, "GtkSheet") range = GtkSheetRange(3, 0, 3, 4) self.range_set_background(range, colormap.alloc_color("dark gray")) self.range_set_foreground(range, colormap.alloc_color("green")) self.set_cell(3, 2, gtk.JUSTIFY_CENTER, "a Matrix widget for Gtk+") (pixmap, mask) = create_pixmap_from_xpm_d(colormap, None, pixmaps.bullet_xpm) row = 4 for line in self.text: if line[0] != "(": bullet = GtkPixmap(pixmap, mask) self.attach(bullet, row, 0, .5, .5) self.set_cell(row, 1, gtk.JUSTIFY_LEFT, line) row = row + 1 (pixmap, mask) = create_pixmap_from_xpm_d(colormap, None, pixmaps.smile_xpm) smile = GtkPixmap(pixmap, mask) self.button_attach(smile, -1, 5, .5, .5) self.connect("key_press_event", self.clipboard_handler) self.connect("resize_range", self.resize_handler) self.connect("move_range", self.move_handler) self.connect("traverse", self.alarm_traverse) self.curve = GtkCurve() self.curve.set_range(0, 200, 0, 200) show_button = GtkButton("Show me a plot") show_button.set_size_request(100, 60) self.attach(show_button, 12, 2, .5, .5) show_button.connect("clicked", self.show_child)
def __init__(self, reader, message, addrlist): self.reader = reader self.message = message composewin = reader.readglade("composewin", self) self.widget = sqmail.gui.utils.WidgetStore(composewin) self.font = gtk.load_font(sqmail.preferences.get_composefont()) # Ensure the text box is 80 columns wide. width = gtk.gdk_char_width(self.font, "m") * 82 # Set up the header fields. if addrlist: self.widget.tofield.set_text( sqmail.gui.utils.render_addrlist(addrlist)) self.widget.fromfield.set_text(sqmail.preferences.get_fromaddress()) if message: i = self.message.getsubject() if (i[:3] == "Re:") or (i[:3] == "re:"): self.widget.subjectfield.set_text(i) else: self.widget.subjectfield.set_text("Re: " + i) # Set up the sign button. self.signaturespopup = gtk.GtkMenu() signatures = os.listdir(os.path.expanduser("~")) signatures.sort() for i in signatures: if (i[0:10] == ".signature"): w = gtk.GtkMenuItem(i) w.show() w.connect("activate", sqmail.gui.utils.Callback(self)["on_sign_with"]) w.set_data("file", i) self.signaturespopup.append(w) # Set up the quote button. if message: self.quotepopup = gtk.GtkMenu() attachments = message.mimeflatten() for i in attachments: if (i[1] in sqmail.gui.textviewer.displayable): w = gtk.GtkMenuItem(i[1] + ": " + i[0]) w.show() w.connect("activate", sqmail.gui.utils.Callback(self)["on_quote_with"]) w.set_data("msg", i[2]) self.quotepopup.append(w) else: self.widget.quotebutton.set_sensitive(0) self.widget.textbox.freeze() self.widget.textbox.set_usize(width, 0) # These two lines set the font. *shrug* self.widget.textbox.insert(self.font, None, None, "\n") self.widget.textbox.delete_text(0, 1) # We want word wrapping. self.widget.textbox.set_word_wrap(1) self.widget.textbox.thaw()
def set_font(self, name): self.font = gtk.load_font(name) return self.font