我正在尝试开发一个“multitrack”GUI(类似于multitrack audio editors);但是,我想先在glade
中开发它,并检查溢出的内容(在本例中是多个“tracks”)在scollbar中的行为。然后,在Python中实例化时,我想首先将这些“多个轨迹”中的第一个作为“模板”,然后删除所有这些多个“轨迹”——然后允许用户根据“模板”添加新的轨迹,比如单击“添加”按钮。在
在Gtk调色板中,我觉得handlebox
是作为“track”基础的正确对象(我希望最终绘制这些轨迹)。到目前为止,我所能完成的唯一一件事(考虑到关于glade
UI用法的教程非常少),就是让滚动条在GUI中正常工作——以下是滚动窗口部分的屏幕截图(对应的文件如下所示):
正确的结构似乎是:
scrolled window
viewport
vbox
handlebox
drawingarea
handlebox ...
。。。我所要做的就是将(all)handlebox
的“Height request”设置为150px(我想要一个恒定的高度,并根据窗口调整宽度);并将其Packing/Expand设置为“No”。另外,将scrolledwindow
水平和垂直滚动条策略设置为“总是”—否则滚动条不会显示(另外,我错误地尝试放置一个额外的滚动条来查看它)。最后,要想让滚动条正常工作,就直接点击它的箭头——在Glade中拖动滚动条是不起作用的(至少在我使用的Ubuntu11.04上的glade3 3.8.0上不起作用)。在
到目前为止还不错-至少我可以看到溢出内容在glade
中的行为,但是:
glade
UI结构吗?我看到一个Layout对象,还有一个Frame对象-这些可能更适合这里吗?(试过了,真的搞不懂).glade
文件,如何从handlebox1
中“提取”模板并按需复制它?在还有一个附带的问题-有没有一种方法可以直接从Glade快速“预览”Glade对象(只在“空窗口”中),而不需要编写实例化脚本-也许可以使用一些快捷方式?在
以下是multitrack.glade
(在GtkBuilder中)的代码:
天啊,这真是。。。好吧,为了用编程的方式做一个正确的模板,你需要递归地复制Gtk对象,这些对象不易受deepcopy的影响。。。因此,我编写了一个这样的函数
deep_clone_widget
,包含在下面的源代码中;供参考:当然,没有经过广泛的测试,但似乎对我有用。有趣的是,直到一个人做了一个完整的“深克隆”车把和绘图区,车把不伸展到适合窗口的宽度!在
好在-只需添加到Vbox中,无需管理它;但似乎拖动行为将是一个挑战。。。但我还是想知道这是否是正确的Gtk/gladeui层次结构(以及是否有一个从Glade预览的快捷方式)
下面的代码还将输出起始层次结构:
。。。最后的层次结构:
^{pr2}$。。。希望能确认深层克隆代码没问题。在
下面是代码
multitrack.py
,它使用上面的multitrack.glade
:相关问题 更多 >
编程相关推荐