Skip to content

Commit

Permalink
Make ImageBrowser scrollable
Browse files Browse the repository at this point in the history
The dialog used to expand offscreen as images were added
  • Loading branch information
cydanil committed Jun 27, 2021
1 parent e33dd20 commit 40a888a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/gourmet/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,21 @@ def __init__(self, parent: Gtk.Window, uris: List[str]):

self.image: Optional[Image.Image] = None
self.liststore = Gtk.ListStore(GdkPixbuf.Pixbuf)

iconview = Gtk.IconView.new()
iconview.set_model(self.liststore)
iconview.set_pixbuf_column(0)
iconview.connect('selection-changed', self.on_selection)

scrollable = Gtk.ScrolledWindow()
scrollable.set_vexpand(True)
scrollable.add(iconview)

box = self.get_content_area()
box.pack_end(scrollable, True, True, 0)
self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK)
self.show_all()

self._stop_retrieval = Event()
self._image_retrieve_task = Thread(target=self._load_uris, args=[uris])
Expand All @@ -151,14 +163,6 @@ def _load_uris(self, uris: List[str]):
pixbuf = bytes_to_pixbuf(image_to_bytes(image))
self.liststore.append([pixbuf])

iconview.connect('selection-changed', self.on_selection)

box = self.get_content_area()
box.pack_end(iconview, True, True, 0)
self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK)
self.show_all()

def on_selection(self, iconview: Gtk.IconView):
item = iconview.get_selected_items()
if item:
Expand Down

0 comments on commit 40a888a

Please sign in to comment.