2

I am using Ubuntu 14.10.

I am trying to create a GtkDialog for data entry. The dialog has a ListBox object with ListBoxRows containing mainly Gtk.Entry objects.

This all works fine until I add a ScrolledWindow with an embedded TextView object, which turns the background color of the surrounding areas (ListBox and ListBoxRows) to black:

Screenshot of window with black background

Here's a small sample to show the problem:

from gi.repository import Gtk

class MyDialog(Gtk.Dialog):
  def __init__(self,parent):
    Gtk.Dialog.__init__(self, "Sample", parent,
      Gtk.DialogFlags.MODAL, buttons=(
      Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
      Gtk.STOCK_OK, Gtk.ResponseType.OK
      ))    
    self.controls=[]

    mainbox=self.get_content_area()
    listbox = Gtk.ListBox()
    listbox.set_selection_mode(Gtk.SelectionMode.NONE)
    mainbox.pack_start(listbox, True, True, 0)

    row = Gtk.ListBoxRow()
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
    row.add(hbox)
    label = Gtk.Label("Label1", xalign=0)
    self.controls.append(Gtk.Entry())
    hbox.pack_start(label,False,True,0)
    hbox.pack_start(self.controls[0],True,True,0)
    listbox.add(row)

    row = Gtk.ListBoxRow()
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
    row.add(hbox)
    label = Gtk.Label("Label2", xalign=0)
    self.controls.append(Gtk.Entry())
    hbox.pack_start(label,False,True,0)
    hbox.pack_start(self.controls[1],True,True,0)
    listbox.add(row)

    row = Gtk.ListBoxRow()
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
    row.add(hbox)
    label = Gtk.Label("Label3", xalign=0)
    scrollwindow = Gtk.ScrolledWindow()
    scrollwindow.set_hexpand(True)
    scrollwindow.set_vexpand(True)
    self.controls.append(Gtk.TextView())
    self.textbuffer = self.controls[2].get_buffer()
    self.textbuffer.set_text("Sample text")
    scrollwindow.add(self.controls[2])
    hbox.pack_start(label,False,True,0)
    hbox.pack_start(scrollwindow,False,True,0)
    listbox.add(row)

    row = Gtk.ListBoxRow()
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
    row.add(hbox)
    label = Gtk.Label("Label4", xalign=0)
    self.controls.append(Gtk.Entry())
    hbox.pack_start(label,False,True,0)
    hbox.pack_start(self.controls[3],True,True,0)
    listbox.add(row)

    self.show_all()

class MyWindow(Gtk.Window):

  def __init__(self):
    Gtk.Window.__init__(self,title="Test")
    dialog= MyDialog(self)
    response = dialog.run()
    exit()


if __name__ == '__main__':
  win = MyWindow()
  Gtk.main()

To reproduce the problem, you have to enter a full line of text in the TextView area. With little/no text, it starts out normal, but as entering text, the background of the listbox changes to black.

Any ideas on what is causing this or how to work around it?

Jim
  • 21
  • 2
  • Just added a small sample, and it appears as if the TextView having a certain amount of text in it has something to do with the problem. I've also tried setting the background color to white and it didn't help. – Jim Dec 21 '14 at 22:42
  • I'm not able to reproduce the problem. Have you tried on another computer? – Veedrac Dec 22 '14 at 23:53
  • Veedrac, what are you running in your environment? Ubuntu, or something else? Also, I should add that I'm using python3. Haven't tried 2, yet. – Jim Dec 23 '14 at 23:32
  • Python 3.4 / Arch Linux / i3 – Veedrac Dec 23 '14 at 23:46
  • Did you ever solve this? I am having a similar issue adding labels to a GtkListBox but this only happens with Humanity theme. – alexmurray Jun 01 '15 at 02:06
  • I ended up solving this using the same approach the California developers used: https://git.gnome.org/browse/california/commit/?id=3442b3 - ie. override the background color of the GtkListBox with the background color of the toplevel window (but in my case I did this only when the current theme was Ambiance or Radiance). – alexmurray Jun 02 '15 at 23:34

0 Answers0