[PATCH 3/6] Port to Gtk3 and the new design

Vratislav Podzimek vpodzime at redhat.com
Wed Jul 11 12:30:59 UTC 2012


On Wed, 2012-07-11 at 08:18 -0400, Martin Gracik wrote:
> the whole set looks fine to me, I just have one comment below
> 
> ----- Original Message -----
> > ---
> >  meh/__init__.py           |    3 +-
> >  meh/handler.py            |    5 +-
> >  meh/ui/gui.py             |  119 +++++++++------------
> >  meh/ui/text.py            |    2 +-
> >  po/python-meh.pot         |   59 ++++++++----
> >  setup.py                  |    2 +-
> >  ui/detailed-dialog.glade  |  171 -------------------------------
> >  ui/exception-dialog.glade |  248
> >  +++++++++++++++++++++++++++++++++++++++++++++
> >  8 files changed, 346 insertions(+), 263 deletions(-)
> >  delete mode 100644 ui/detailed-dialog.glade
> >  create mode 100644 ui/exception-dialog.glade
> > 
> > diff --git a/meh/__init__.py b/meh/__init__.py
> > index 2732e66..69352f8 100644
> > --- a/meh/__init__.py
> > +++ b/meh/__init__.py
> > @@ -25,7 +25,8 @@
> >  # exception is hit.
> >  MAIN_RESPONSE_DEBUG = 0
> >  MAIN_RESPONSE_SAVE = 1
> > -MAIN_RESPONSE_OK = 2
> > +MAIN_RESPONSE_QUIT = 2
> > +MAIN_RESPONSE_NONE = 3
> >  
> >  # And these constants represent the return values of buttons on the
> >  exception
> >  # saving dialog.
> > diff --git a/meh/handler.py b/meh/handler.py
> > index 143c1b9..75dca12 100644
> > --- a/meh/handler.py
> > +++ b/meh/handler.py
> > @@ -80,7 +80,7 @@ class ExceptionHandler(object):
> >             a subclass.
> >          """
> >  
> > -        responseHash = {MAIN_RESPONSE_OK: self.runQuit,
> > +        responseHash = {MAIN_RESPONSE_QUIT: self.runQuit,
> >                          MAIN_RESPONSE_DEBUG: self.runDebug,
> >                          MAIN_RESPONSE_SAVE: self.runSave}
> >  
> > @@ -107,8 +107,7 @@ class ExceptionHandler(object):
> >              if not win:
> >                  self.runQuit((ty, value, tb))
> >  
> > -            win.run()
> > -            rc = win.getrc()
> > +            rc = win.run()
> >  
> >              try:
> >                  responseHash[rc]((ty, value, tb))
> > diff --git a/meh/ui/gui.py b/meh/ui/gui.py
> > index ec05739..2b6ff15 100644
> > --- a/meh/ui/gui.py
> > +++ b/meh/ui/gui.py
> > @@ -18,15 +18,14 @@
> >  #
> >  from meh import *
> >  from meh.ui import *
> > -import gtk
> > -import gtk.glade
> >  import os
> >  import report
> > +from gi.repository import Gtk
> >  
> >  import gettext
> >  _ = lambda x: gettext.ldgettext("python-meh", x)
> >  
> > -def findGladeFile(file):
> > +def find_glade_file(file):
> >      path = os.environ.get("GLADEPATH",
> >      "./:ui/:/tmp/updates/:/tmp/updates/ui/:/usr/share/python-meh/")
> >      for d in path.split(":"):
> >          fn = d + file
> > @@ -34,14 +33,6 @@ def findGladeFile(file):
> >              return fn
> >      raise RuntimeError, "Unable to find glade file %s" % file
> >  
> > -def findPixmap(file):
> > -    path = os.environ.get("PIXMAPPATH",
> > "./:pixmaps/:/tmp/updates/:/tmp/updates/pixmaps/:/usr/share/python-meh/")
> > -    for d in path.split(":"):
> > -        fn = d + file
> > -        if os.access(fn, os.R_OK):
> > -            return fn
> > -    return None
> > -
> >  class GraphicalIntf(AbstractIntf):
> >      def __init__(self, *args, **kwargs):
> >          AbstractIntf.__init__(self, *args, **kwargs)
> > @@ -83,74 +74,66 @@ class
> > MainExceptionWindow(AbstractMainExceptionWindow):
> >          AbstractMainExceptionWindow.__init__(self, shortTraceback,
> >          longTracebackFile,
> >                                               *args, **kwargs)
> >  
> > -        xml = gtk.glade.XML(findGladeFile("detailed-dialog.glade"),
> > domain="python-meh")
> > -        self.dialog = xml.get_widget("detailedDialog")
> > -        self.mainVBox = xml.get_widget("mainVBox")
> > -        self.hbox = xml.get_widget("hbox1")
> > -        self.info = xml.get_widget("info")
> > -        self.detailedExpander = xml.get_widget("detailedExpander")
> > -        self.detailedView = xml.get_widget("detailedView")
> > -
> > -        # Set the custom icon.
> > -        img = gtk.Image()
> > -        img.set_from_file(findPixmap("exception.png"))
> > -        self.hbox.pack_start(img)
> > -        self.hbox.reorder_child(img, 0)
> > -
> > -        # Set the buttons.
> > -        for (button, response) in [(_("Debu_g"),
> > MAIN_RESPONSE_DEBUG),
> > -                                   ("gtk-save", MAIN_RESPONSE_SAVE),
> > -                                   (_("_Exit"), MAIN_RESPONSE_OK)]:
> > -            self.dialog.add_button(button, response)
> > -
> > -        self.dialog.set_default_response(MAIN_RESPONSE_OK)
> > -
> > -        self.info.set_text(_("An unhandled exception has occurred.
> >  This "
> > -                             "is most likely a bug.  Please save a
> > copy "
> > -                             "of the detailed exception and file a
> > bug "
> > -                             "report."))
> > -
> > -        if longTracebackFile:
> > -            f = open(longTracebackFile)
> > -
> > -            textbuf = gtk.TextBuffer()
> > -            i = textbuf.get_start_iter()
> > +        builder = Gtk.Builder()
> > +        glade_file = find_glade_file("exception-dialog.glade")
> > +        builder.add_from_file(glade_file)
> > +        builder.connect_signals(self)
> >  
> > -            while True:
> > -                # Wish readline would give StopIteration at the end
> > of a file.
> > -                line = f.readline()
> > -                if line == "":
> > -                    break
> > +        self._main_window = builder.get_object("exceptionWindow")
> >  
> > -                if __builtins__.get("type")(line) != unicode:
> > -                    try:
> > -                        line = unicode(line, encoding='utf-8')
> > -                    except UnicodeDecodeError:
> > -                        pass
> > +        self._traceback_buffer =
> > builder.get_object("tracebackBuffer")
> >  
> > -                textbuf.insert(i, line)
> > +        if longTracebackFile:
> > +            with open(longTracebackFile) as fobj:
> > +                long_traceback = ""
> > +                for line in fobj:
> > +                    long_traceback += line
> 
> you could use
> 
> long_traceback = ''.join(fobj)
Nice tip, thanks! However, since the PATCH 6/6 completely removes this
block, I will leave it like that for this time.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list