[GTK3] Fix path_combo_chooser warnings

Fixes
 - Please remove the widget from its existing container first
 - object has no attribute 'height'
This commit is contained in:
hugosenari 2018-08-20 05:13:29 -03:00 committed by Calum Lind
parent 14b6ba10cf
commit 2f879c33f3
2 changed files with 30 additions and 25 deletions

View File

@ -867,7 +867,7 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkWindow" id="window1"> <object class="GtkWindow" id="combobox_window">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<placeholder/> <placeholder/>

View File

@ -19,7 +19,7 @@ from gi.repository import Gdk, GObject, Gtk
from gi.repository.GObject import SignalFlags from gi.repository.GObject import SignalFlags
import deluge.component as component import deluge.component as component
from deluge.common import resource_filename from deluge.common import PY2, resource_filename
from deluge.path_chooser_common import get_completion_paths from deluge.path_chooser_common import get_completion_paths
@ -592,20 +592,20 @@ class PathChooserPopup(object):
height_extra = 8 height_extra = 8
buttonbox_width = 0 buttonbox_width = 0
height = self.popup_window.get_preferred_size().height height = self.popup_window.get_preferred_height()[1]
width = self.popup_window.get_preferred_size().width width = self.popup_window.get_preferred_width()[1]
if self.popup_buttonbox: if self.popup_buttonbox:
buttonbox_height = max( buttonbox_height = max(
self.popup_buttonbox.get_preferred_size().height, self.popup_buttonbox.get_preferred_height()[1],
self.popup_buttonbox.get_allocation().height, self.popup_buttonbox.get_allocation().height,
) )
buttonbox_width = max( buttonbox_width = max(
self.popup_buttonbox.get_preferred_size().width, self.popup_buttonbox.get_preferred_width()[1],
self.popup_buttonbox.get_allocation().width, self.popup_buttonbox.get_allocation().width,
) )
treeview_width = self.treeview.get_preferred_size().width treeview_width = self.treeview.get_preferred_width()[1]
# After removing an element from the tree store, self.treeview.get_preferred_size()[0] # After removing an element from the tree store, self.treeview.get_preferred_width()[0]
# returns -1 for some reason, so the requested width cannot be used until the treeview # returns -1 for some reason, so the requested width cannot be used until the treeview
# has been displayed once. # has been displayed once.
if treeview_width != -1: if treeview_width != -1:
@ -619,12 +619,12 @@ class PathChooserPopup(object):
width = self.alignment_widget.get_allocation().width width = self.alignment_widget.get_allocation().width
# 10 is extra spacing # 10 is extra spacing
content_width = self.treeview.get_preferred_size().width + buttonbox_width + 10 content_width = self.treeview.get_preferred_width()[1] + buttonbox_width + 10
# Adjust height according to number of list items # Adjust height according to number of list items
if len(self.tree_store) > 0 and self.max_visible_rows > 0: if len(self.tree_store) > 0 and self.max_visible_rows > 0:
# The height for one row in the list # The height for one row in the list
self.row_height = self.treeview.get_preferred_size().height / len( self.row_height = self.treeview.get_preferred_height()[1] / len(
self.tree_store self.tree_store
) )
# Set height to number of rows # Set height to number of rows
@ -1110,18 +1110,23 @@ GtkGI = get_introspection_module('Gtk')
class PathChooserComboBox(GtkGI.Box, StoredValuesPopup, GObject.GObject): class PathChooserComboBox(GtkGI.Box, StoredValuesPopup, GObject.GObject):
__gsignals__ = { __gsignals__ = {
b'list-value-added': (SignalFlags.RUN_FIRST, None, (object,)), signal
b'list-value-removed': (SignalFlags.RUN_FIRST, None, (object,)), if not PY2
b'list-values-reordered': (SignalFlags.RUN_FIRST, None, (object,)), else signal.encode(): (SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (object,))
b'list-values-changed': (SignalFlags.RUN_FIRST, None, (object,)), for signal in [
b'auto-complete-enabled-toggled': (SignalFlags.RUN_FIRST, None, (object,)), 'text-changed',
b'show-filechooser-toggled': (SignalFlags.RUN_FIRST, None, (object,)), 'accelerator-set',
b'show-path-entry-toggled': (SignalFlags.RUN_FIRST, None, (object,)), 'max-rows-changed',
b'show-folder-name-on-button': (SignalFlags.RUN_FIRST, None, (object,)), 'list-value-added',
b'show-hidden-files-toggled': (SignalFlags.RUN_FIRST, None, (object,)), 'list-value-removed',
b'accelerator-set': (SignalFlags.RUN_FIRST, None, (object,)), 'list-values-changed',
b'max-rows-changed': (SignalFlags.RUN_FIRST, None, (object,)), 'list-values-reordered',
b'text-changed': (SignalFlags.RUN_FIRST, None, (object,)), 'show-path-entry-toggled',
'show-filechooser-toggled',
'show-hidden-files-toggled',
'show-folder-name-on-button',
'auto-complete-enabled-toggled',
]
} }
def __init__( def __init__(
@ -1157,10 +1162,10 @@ class PathChooserComboBox(GtkGI.Box, StoredValuesPopup, GObject.GObject):
self.button_properties = self.builder.get_object('button_properties') self.button_properties = self.builder.get_object('button_properties')
# FIXME: These are commented out but should be fixed. # FIXME: These are commented out but should be fixed.
# self.combobox_window = self.builder.get_object('combobox_window') self.combobox_window = self.builder.get_object('combobox_window')
self.combo_hbox = self.builder.get_object('entry_combobox_hbox') self.combo_hbox = self.builder.get_object('entry_combobox_hbox')
# Change the parent of the hbox from the glade Window to this hbox. # Change the parent of the hbox from the glade Window to this hbox.
# self.combobox_window.remove(self.combo_hbox) self.combobox_window.remove(self.combo_hbox)
self.combobox_window = self.get_window() self.combobox_window = self.get_window()
self.add(self.combo_hbox) self.add(self.combo_hbox)
StoredValuesPopup.__init__( StoredValuesPopup.__init__(
@ -1687,7 +1692,7 @@ if __name__ == '__main__':
w.set_title('ComboEntry example') w.set_title('ComboEntry example')
w.connect('delete-event', Gtk.main_quit) w.connect('delete-event', Gtk.main_quit)
box1 = Gtk.VBox(False, 0) box1 = Gtk.Box(Gtk.Orientation.VERTICAL, 0)
def get_resource2(filename): def get_resource2(filename):
return '%s/glade/%s' % (os.path.abspath(os.path.dirname(sys.argv[0])), filename) return '%s/glade/%s' % (os.path.abspath(os.path.dirname(sys.argv[0])), filename)