如何处理具有多个窗口的林间空地项目

发布于 2024-07-09 21:02:25 字数 593 浏览 9 评论 0原文

我正在开发一个 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 技术交流群。

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

发布评论

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

评论(4

给我一枪 2024-07-16 21:02:25

在我的项目中,每个林间空地文件总是有一个窗口。 我会为你的项目推荐同样的东西。

以下是两个主要原因:

  • 它会更快并且使用更少的内存,因为每次调用 gtk.glade.XML() 都会解析整个事情。 当然,您可以传入 root 参数来避免为所有窗口创建小部件树,但您仍然必须解析所有 XML,即使您对此不感兴趣。
  • 从概念上讲,如果每个窗口都有一个顶层,则更容易理解。 只需查看文件名,您就可以轻松知道给定对话框/窗口所在的文件名。

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:

  • It will be faster and use less memory, since each call to gtk.glade.XML() parses the whole thing. Sure you can pass in the root argument to avoid creating the widget tree for all windows, but you'd still have to parse all the XML, even if you're not interested in it.
  • Conceptually its easier to understand if have one toplevel per window. You easily know which filename a given dialog/window is in just by looking at the filename.
贱人配狗天长地久 2024-07-16 21:02:25

您是否花了一些时间来看看它是否会产生影响?

问题是,据我了解,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.

酸甜透明夹心 2024-07-16 21:02:25

我对不同的窗口使用不同的林间空地文件。 但我将与窗口关联的对话框保留在同一个林间空地文件中。 正如你所说,命名问题很烦人。

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.

我们的影子 2024-07-16 21:02:25

我有一个林间空地文件,有 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.

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