1### Copyright (C) 2012 Kai Willadsen <kai.willadsen@gmail.com> 2 3### This program is free software; you can redistribute it and/or modify 4### it under the terms of the GNU General Public License as published by 5### the Free Software Foundation; either version 2 of the License, or 6### (at your option) any later version. 7 8### This program is distributed in the hope that it will be useful, 9### but WITHOUT ANY WARRANTY; without even the implied warranty of 10### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11### GNU General Public License for more details. 12 13### You should have received a copy of the GNU General Public License 14### along with this program; if not, write to the Free Software 15### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 16### USA. 17 18import gobject 19import gtk 20import pango 21 22 23gtk.rc_parse_string( 24 """ 25 style "meld-statusbar-style" { 26 GtkStatusbar::shadow-type = GTK_SHADOW_NONE 27 } 28 class "MeldStatusBar" style "meld-statusbar-style" 29 30 style "meld-progressbar-style" { 31 GtkProgressBar::yspacing = 0 32 GtkProgressBar::min-horizontal-bar-height = 14 33 } 34 widget "*.MeldStatusBar.*.GtkProgressBar" style "meld-progressbar-style" 35 """) 36 37 38class MeldStatusBar(gtk.Statusbar): 39 __gtype_name__ = "MeldStatusBar" 40 41 def __init__(self): 42 gtk.Statusbar.__init__(self) 43 self.props.spacing = 6 44 45 if hasattr(self, "get_message_area"): 46 # FIXME: added in 2.20, but not in the corresponding pygtk. Use this if available 47 hbox = self.get_message_area() 48 label = hbox.get_children()[0] 49 else: 50 frame = self.get_children()[0] 51 self.set_child_packing(frame, False, False, 0, gtk.PACK_START) 52 child = frame.get_child() 53 # Internal GTK widgetry changed when get_message_area was added. 54 if not isinstance(child, gtk.HBox): 55 hbox = gtk.HBox(False, 4) 56 child.reparent(hbox) 57 frame.add(hbox) 58 hbox.show() 59 label = child 60 else: 61 hbox = child 62 label = hbox.get_children()[0] 63 hbox.props.spacing = 6 64 label.props.ellipsize = pango.ELLIPSIZE_NONE 65 66 self.progress = gtk.ProgressBar() 67 self.progress.props.pulse_step = 0.02 68 self.progress.props.ellipsize = pango.ELLIPSIZE_END 69 self.progress.set_size_request(200, -1) 70 progress_font = self.progress.get_style().font_desc 71 progress_font.set_size(progress_font.get_size() - 2 * pango.SCALE) 72 self.progress.modify_font(progress_font) 73 hbox.pack_start(self.progress, expand=False) 74 self.progress.show() 75 76 hbox.remove(label) 77 hbox.pack_start(label) 78 79 alignment = gtk.Alignment(xalign=1.0) 80 self.info_box = gtk.HBox(False, 6) 81 self.info_box.show() 82 alignment.add(self.info_box) 83 self.pack_start(alignment, expand=True) 84 alignment.show() 85 86 self.timeout_source = None 87 88 def start_pulse(self): 89 self.progress.show() 90 if self.timeout_source is None: 91 def pulse(): 92 self.progress.pulse() 93 return True 94 self.timeout_source = gobject.timeout_add(50, pulse) 95 96 def stop_pulse(self): 97 if self.timeout_source is not None: 98 gobject.source_remove(self.timeout_source) 99 self.timeout_source = None 100 self.progress.set_fraction(0) 101 self.progress.hide() 102 103 def set_task_status(self, status): 104 self.progress.set_text(status) 105 106 def set_info_box(self, widgets): 107 for child in self.info_box.get_children(): 108 self.info_box.remove(child) 109 for widget in widgets: 110 self.info_box.pack_end(widget) 111