如何处理具有多个窗口的林间空地项目
我正在开发一个 PyGTK/glade 应用程序,目前有 16 个窗口/对话框,大小约为 130KB,最终将有大约 25 个窗口/对话框,大小约为 200KB。 目前,我将所有窗口存储在一个整体林间空地文件中。 当我运行一个窗口时,我这样称呼它......
self.wTree = gtk.glade.XML("interface.glade", "WindowXYZ")
我想知道将每个窗口分成它自己的林间空地文件是否是一个更好的主意。 我不是使用一个包含 25 个窗口/对话框的空地文件,而是使用 25 个空地文件,每个文件包含一个窗口/对话框,并这样称呼它:
self.wTree = gtk.glade.XML("windowxyz.glade")
你们认为最好的方法是什么? 一种方法是否比另一种方法更耗费资源? 访问单个林间空地文件的好处之一是命名小部件会更容易。 例如,我将所有“确定”按钮命名为“windowxyz_ok”,但我可以将其更改为简单的“确定”。 让事情变得更简单。 缺点是对不同窗口进行更改可能不太方便。
我对任何和所有的争论都持开放态度。 谢谢!
I'm working on a PyGTK/glade application that currently has 16 windows/dialogs and is about 130KB, and will eventually have around 25 windows/dialogs and be around 200KB. Currently, I'm storing all the windows in one monolithic glade file. When I run a window I call it like...
self.wTree = gtk.glade.XML("interface.glade", "WindowXYZ")
I wonder if it would be a better idea to split each window into it's own glade file. Instead of one glade file with 25 windows/dialogs I'd have 25 glade files with one window/dialog each and call it like so:
self.wTree = gtk.glade.XML("windowxyz.glade")
What do you guys think is the best way to do this? Is one method more resource intensive than another? One thing that would be nice about going to individual glade files is that naming widgets would be easier. For example, I name all my OK buttons "windowxyz_ok", but I could change it to simply "ok" instead. Makes things simpler. The downside is that it may be a bit less convenient to make changes to different windows.
I'm open to any and all arguments. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在我的项目中,每个林间空地文件总是有一个窗口。 我会为你的项目推荐同样的东西。
以下是两个主要原因:
In my projects, I always have one window per glade file. I'd recommend the same for your project.
The following are the two main reasons:
您是否花了一些时间来看看它是否会产生影响?
问题是,据我了解,Glade 在解析 XML 文件时总是创建所有小部件,因此如果您打开 XML 文件并且只读取单个小部件,则会浪费大量资源。
另一个问题是,如果您想要该小部件的另一个实例,则需要重新读取该文件。
我之前的做法是将所有仅创建一次的小部件(例如“关于”窗口、主窗口等)放入一个空地文件中,并为需要多次创建的小部件单独的空地文件。
Did you take some timings to find out whether it makes a difference?
The problem is that, as far as I understand it, Glade always creates all widgets when it parses an XML file, so if you open the XML file and only read a single widget, you are wasting a lot of resources.
The other problem is that you need to re-read the file if you want to have another instance of that widget.
The way I did it before was to put all widgets that were created only once (like the about window, the main window etc) into one glade file, and separate glade files for widgets that needed to be created several times.
我对不同的窗口使用不同的林间空地文件。 但我将与窗口关联的对话框保留在同一个林间空地文件中。 正如你所说,命名问题很烦人。
I use different glade files for different windows. But I keep dialog associated with a window in the same glade file. As you said, the naming problem is annoying.
我有一个林间空地文件,有 2 个窗口。 它的大小约为 450kb,并且我没有看到将 libglademm 与 GTKmm 结合使用有任何减慢情况。
I have one glade file with 2 windows. It's about 450kb in size and I have not seen any slowdowns using libglademm with GTKmm.