PyGTK:在 gtk.Notebook 中的选项卡之前打包小部件

发布于 2024-08-20 15:26:50 字数 270 浏览 5 评论 0原文

基本上,我想要做的就是在 gtk.Notebook 中的选项卡之前放置一些按钮。我尝试制作自己的笔记本类型小部件,它运行良好,但需要做更多的工作才能使其像我想要的那样灵活,而且效率也不高。

这是我想要实现的目标的模型: http://imagebin.ca/view /84SC0d.html

任何想法将不胜感激,谢谢。

本.

Basically, what I want to do is put some buttons before the tabs in a gtk.Notebook. I tried making my own notebook type widget and it worked well, but it would have required lots more work to make it as flexible as I would like, also it wasn't as efficient.

Here is a mock-up of what I'm trying to achieve: http://imagebin.ca/view/84SC0d.html

Any ideas would be much appreciated, thanks.

Ben.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

享受孤独 2024-08-27 15:26:50

您可能有兴趣知道 GTK 2.20 中已添加此功能,请参阅以下公告中的“GtkNotebook 中的更改”: http://mail.gnome.org/archives/gtk-devel-list/2010 年 3 月/msg00132.html

You might be interested to know that this functionality has been added in GTK 2.20, see "Changes in GtkNotebook" in the following announcement: http://mail.gnome.org/archives/gtk-devel-list/2010-March/msg00132.html

从此见与不见 2024-08-27 15:26:50

这是一个 hack,但您可以将小部件放在单独的选项卡上,然后通过为笔记本注册以下切换页面事件来防止单击该选项卡:

def onTabsSwitchPage(self, notebook, page_notUsableInPython, pageNumber):
    # Don't allow to switch to the dummy tab containing widgets
    if pageNumber == <put correct tab number here>:
        notebook.stop_emission("switch-page")

请注意,这对于所有 GTK 主题来说看起来并不好,但它作品...

It's a hack, but you can put your widgets on a separate tab, and then prevent the tab from being clicked by registering the following switch-page event for the notebook:

def onTabsSwitchPage(self, notebook, page_notUsableInPython, pageNumber):
    # Don't allow to switch to the dummy tab containing widgets
    if pageNumber == <put correct tab number here>:
        notebook.stop_emission("switch-page")

Note that this doesn't look good with all GTK themes, but it works...

调妓 2024-08-27 15:26:50

我认为如果不制作自己的笔记本小部件就没有任何方法可以做到这一点。有一些技巧。其中一篇是由 AndiDog 发布的。另一种方法是完全隐藏选项卡(notebook.set_show_tabs(False)),并在小部件上方创建一个带有按钮的工具栏,按钮位于左侧,为笔记本中切换的每个选项卡加上一个按钮到该页面。

您可以从 gtk.Notebook 继承,重写一些方法,例如 expose_eventsize_request,而不是从头开始制作自己的笔记本类型小部件。和 size_allocate,以处理两种类型的容器子项:页面和按钮。我不知道如何在 PyGTK 中执行此操作,仅在 C 中执行此操作。

您还可以考虑选项卡空间中的按钮是否确实是您想要的。如果用户将笔记本大小调整得足够小以致某些选项卡消失怎么办?上一个选项卡/下一个选项卡箭头去哪里了?按钮会发生什么情况?

I don't think there's any way to do it without making your own notebook widget. There are a couple of hacks. One was posted by AndiDog. Another is to hide the tabs altogether (notebook.set_show_tabs(False)) and make a toolbar with buttons above the widget, with your buttons on the left, plus one button for each tab in the notebook that switches to that page.

Instead of making your own notebook-type widget from scratch, you could inherit from gtk.Notebook, overriding some of the methods like expose_event, size_request, and size_allocate, in order to deal with two types of container children: pages and buttons. I don't know how to do this in PyGTK though, only in C.

You might also consider whether the buttons in the tab space are really what you want. What if the user resizes your notebook small enough that some of the tabs disappear? Where do the previous tab/next tab arrows go? What happens to the buttons?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文