progressbar.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # BitBake Graphical GTK User Interface
  2. #
  3. # Copyright (C) 2011 Intel Corporation
  4. #
  5. # Authored by Shane Wang <shane.wang@intel.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. import gtk
  20. from bb.ui.crumbs.hobcolor import HobColors
  21. class HobProgressBar (gtk.ProgressBar):
  22. def __init__(self):
  23. gtk.ProgressBar.__init__(self)
  24. self.set_rcstyle(True)
  25. self.percentage = 0
  26. def set_rcstyle(self, status):
  27. rcstyle = gtk.RcStyle()
  28. rcstyle.fg[2] = gtk.gdk.Color(HobColors.BLACK)
  29. if status == "stop":
  30. rcstyle.bg[3] = gtk.gdk.Color(HobColors.WARNING)
  31. elif status == "fail":
  32. rcstyle.bg[3] = gtk.gdk.Color(HobColors.ERROR)
  33. else:
  34. rcstyle.bg[3] = gtk.gdk.Color(HobColors.RUNNING)
  35. self.modify_style(rcstyle)
  36. def set_title(self, text=None):
  37. if not text:
  38. text = ""
  39. text += " %.0f%%" % self.percentage
  40. self.set_text(text)
  41. def set_stop_title(self, text=None):
  42. if not text:
  43. text = ""
  44. self.set_text(text)
  45. def reset(self):
  46. self.set_fraction(0)
  47. self.set_text("")
  48. self.set_rcstyle(True)
  49. self.percentage = 0
  50. def update(self, fraction):
  51. self.percentage = int(fraction * 100)
  52. self.set_fraction(fraction)