PyGtk: окно переполнения виджета
Моя карта Champlain переполняет мое окно GtkWindow, как показано на прикрепленном скриншоте. Я не смог найти никого с подобной проблемой в Интернете.
Я сделал графический интерфейс в Glade и оставил одну пустую панель, чтобы я мог заполнить ее в коде GtkChamplain.Embed
виджет для отображения карты. Он работал почти нормально, пока я не установил размер запроса Embed
чтобы предотвратить проглатывание карты при изменении размеров окна.
Я не хотел, чтобы это случилось:
Конечно, я могу обойти это, установив ограничение на то, насколько маленькое окно может уменьшаться и насколько может увеличиваться левая сторона панели. Я бы предпочел сделать это соответствующим образом, установив Embed
размер запроса. Кто-нибудь знает, почему это происходит или как сделать это правильно?
Вот мой полный код.
# -*- coding: utf-8 -*-
import gi
gi.require_version('Champlain', '0.12')
gi.require_version('GtkChamplain', '0.12')
gi.require_version('GtkClutter', '1.0')
from gi.repository import GtkClutter, Clutter
GtkClutter.init([]) # Must be initialized before importing those:
from gi.repository import GObject, Gtk, Champlain, GtkChamplain, Pango
class UserInterface:
def __init__(self):
builder = Gtk.Builder()
builder.add_from_file('zahori.glade')
self.client_list = builder.get_object("client-list")
self.main_window = builder.get_object("main-window")
self.main_panel = builder.get_object("main-panel")
self.client_treeview = builder.get_object("client-treeview")
self.main_window = builder.get_object("main-window")
self.status_label = builder.get_object("status-label")
self.map_embed = GtkChamplain.Embed()
self.map_embed.set_size_request(550, 300)
self.main_panel.add(self.map_embed)
self.main_window.connect("destroy", Gtk.main_quit)
self.main_window.show_all()
UserInterface()
Gtk.main()
Ниже вы можете найти мой .glade
файл.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="client-list"/>
<object class="GtkApplicationWindow" id="main-window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Zahori</property>
<property name="default_width">700</property>
<property name="default_height">400</property>
<child>
<object class="GtkBox" id="main-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="main-menu-bar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Archivo</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-open</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-save-as</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Editar</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-cut</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Ver</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Ay_uda</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkToolbar" id="main-toolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkToolButton" id="new-scan-button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">new-scan</property>
<property name="label" translatable="yes">New scan</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-new</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="open-button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">open-file</property>
<property name="label" translatable="yes">Open file</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-open</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="save-button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">save-file</property>
<property name="label" translatable="yes">Save to file</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-save</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkPaned" id="main-panel">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkTreeView" id="client-treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">client-list</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="client-mac">
<property name="resizable">True</property>
<property name="min_width">200</property>
<property name="title" translatable="yes">Device</property>
</object>
</child>
</object>
<packing>
<property name="resize">False</property>
<property name="shrink">False</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="status-bar">
<property name="height_request">20</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="status-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
1 ответ
Я мог бы опубликовать это слишком рано. Я быстро нашел ответ, когда обнаружил child_set_property()
метод GtkContainer
,
Установив...
self.main_panel.add(self.map_embed)
self.main_panel.child_set_property(self.map_embed,"resize",False)
self.main_panel.child_set_property(self.map_embed,"shrink",False)
Мой интерфейс начал вести себя должным образом. Если не требуется иное, я сохраняю здесь свои вопросы и ответы на случай, если кто-то столкнется с подобной проблемой.