prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Have logger scroll automatically only when at the bottom
  Currently the logger scrolls whenever it outputs which makes scrolling up useless unless the game is stopped. This behavior is annoying.
  
  </issue>
  <code>
  [start of lutris/gui/logwindow.py]
  1 from gi.repository import Gtk
  2 from lutris.gui.widgets.dialogs import Dialog
  3 
  4 
  5 class LogTextView(Gtk.TextView):
  6     def __init__(self, buffer):
  7         super(LogTextView, self).__init__()
  8 
  9         self.set_buffer(buffer)
  10         self.set_editable(False)
  11         self.set_monospace(True)
  12         self.set_left_margin(10)
  13         self.set_wrap_mode(Gtk.WrapMode.CHAR)
  14         self.get_style_context().add_class('lutris-logview')
  15         self.connect("size-allocate", self.autoscroll)
  16 
  17     def autoscroll(self, *args):
  18         adj = self.get_vadjustment()
  19         adj.set_value(adj.get_upper() - adj.get_page_size())
  20 
  21 
  22 class LogWindow(Dialog):
  23     def __init__(self, title, buffer, parent):
  24         super(LogWindow, self).__init__(title, parent, 0,
  25                                         ('_OK', Gtk.ResponseType.OK))
  26         self.set_size_request(640, 480)
  27         self.grid = Gtk.Grid()
  28         self.buffer = buffer
  29         self.logtextview = LogTextView(self.buffer)
  30 
  31         scrolledwindow = Gtk.ScrolledWindow(hexpand=True, vexpand=True,
  32                                             child=self.logtextview)
  33         self.vbox.add(scrolledwindow)
  34         self.show_all()
  35
  [end of lutris/gui/logwindow.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/lutris/gui/logwindow.py b/lutris/gui/logwindow.py
  --- a/lutris/gui/logwindow.py
  +++ b/lutris/gui/logwindow.py
  @@ -10,13 +10,16 @@
           self.set_editable(False)
           self.set_monospace(True)
           self.set_left_margin(10)
  +        self.scroll_max = 0
           self.set_wrap_mode(Gtk.WrapMode.CHAR)
           self.get_style_context().add_class('lutris-logview')
           self.connect("size-allocate", self.autoscroll)
   
       def autoscroll(self, *args):
           adj = self.get_vadjustment()
  -        adj.set_value(adj.get_upper() - adj.get_page_size())
  +        if adj.get_value() == self.scroll_max or self.scroll_max == 0:
  +            adj.set_value(adj.get_upper() - adj.get_page_size())
  +        self.scroll_max = adj.get_upper() - adj.get_page_size()
   
   
   class LogWindow(Dialog):
  
verification_info: {"golden_diff": "diff --git a/lutris/gui/logwindow.py b/lutris/gui/logwindow.py\n--- a/lutris/gui/logwindow.py\n+++ b/lutris/gui/logwindow.py\n@@ -10,13 +10,16 @@\n         self.set_editable(False)\n         self.set_monospace(True)\n         self.set_left_margin(10)\n+        self.scroll_max = 0\n         self.set_wrap_mode(Gtk.WrapMode.CHAR)\n         self.get_style_context().add_class('lutris-logview')\n         self.connect(\"size-allocate\", self.autoscroll)\n \n     def autoscroll(self, *args):\n         adj = self.get_vadjustment()\n-        adj.set_value(adj.get_upper() - adj.get_page_size())\n+        if adj.get_value() == self.scroll_max or self.scroll_max == 0:\n+            adj.set_value(adj.get_upper() - adj.get_page_size())\n+        self.scroll_max = adj.get_upper() - adj.get_page_size()\n \n \n class LogWindow(Dialog):\n", "issue": "Have logger scroll automatically only when at the bottom\nCurrently the logger scrolls whenever it outputs which makes scrolling up useless unless the game is stopped. This behavior is annoying.\n", "before_files": [{"content": "from gi.repository import Gtk\nfrom lutris.gui.widgets.dialogs import Dialog\n\n\nclass LogTextView(Gtk.TextView):\n    def __init__(self, buffer):\n        super(LogTextView, self).__init__()\n\n        self.set_buffer(buffer)\n        self.set_editable(False)\n        self.set_monospace(True)\n        self.set_left_margin(10)\n        self.set_wrap_mode(Gtk.WrapMode.CHAR)\n        self.get_style_context().add_class('lutris-logview')\n        self.connect(\"size-allocate\", self.autoscroll)\n\n    def autoscroll(self, *args):\n        adj = self.get_vadjustment()\n        adj.set_value(adj.get_upper() - adj.get_page_size())\n\n\nclass LogWindow(Dialog):\n    def __init__(self, title, buffer, parent):\n        super(LogWindow, self).__init__(title, parent, 0,\n                                        ('_OK', Gtk.ResponseType.OK))\n        self.set_size_request(640, 480)\n        self.grid = Gtk.Grid()\n        self.buffer = buffer\n        self.logtextview = LogTextView(self.buffer)\n\n        scrolledwindow = Gtk.ScrolledWindow(hexpand=True, vexpand=True,\n                                            child=self.logtextview)\n        self.vbox.add(scrolledwindow)\n        self.show_all()\n", "path": "lutris/gui/logwindow.py"}]}