gtk 下拉菜单控件_如何创建PHP-GTK GTK +菜单/菜单项?

gtk 下拉菜单控件

PHP Programming Language Logo Image

PHP Programming Language Logo Image

In respect to our forum post on how to install PHP-GTK on Ubuntu / Linux, we will have a series of howtos on our blog with respect to PHP-GTK – which is a PHP language binding to the GTK+ widget toolkit. With this in mind, you can create pretty robust desktop applications using PHP-GTK. In this article, we’ll show you how to create menus using PHP-GTK – and because the documentation is somewhat quite bear we thought we’d make an article on various aspects of PHP-GTK you may struggle to understand at first.

关于我们如何在Ubuntu / Linux上安装PHP-GTK的论坛帖子,我们的博客上有一系列关于PHP-GTK的howtos – PHP-GTK是绑定到GTK +小部件工具箱PHP语言。 考虑到这一点,您可以使用PHP-GTK创建非常强大的桌面应用程序。 在本文中,我们将向您展示如何使用PHP-GTK创建菜单-并且由于文档有些空洞,我们认为我们会针对您可能一开始难以理解PHP-GTK的各个方面撰写文章。

PHP-GTK的支持程度如何? (How well supported is PHP-GTK?)

In comparison to PyGTK (a Python GTK+ language binding) and other language bindings you can use, PHP-GTK is not as widely supported as one would hope so if you are considering using PHP-GTK for most robust application development, you’ll unfortunately need to consider using a different language binding, such as Python. Many Linux distributions come bundled with all the packages you need to start developing and running PyGTK applications. However, with PHP-GTK, you need to install the dependencies and then compile and install PHP-GTK. If your primary target market is those that will understand how to execute commands via the Terminal and wouldn’t mind doing so, sure, PHP-GTK is a good option – and especially because on Windows, there are pre-compiled binaries available. All you need to do with the pre-compiled binary is execute your PHP-GTK script against the PHP interpreter executable. On Mac OS X, installation isn’t as easy – it’s essentially as cumbersome as getting PHP-GTK installed on Linux distributions.

与您可以使用的PyGTK(一种Python GTK +语言绑定)和其他语言绑定相比,PHP-GTK的支持不像人们希望的那样广泛,因此,如果您考虑使用PHP-GTK进行最可靠的应用程序开发,那么您将很不幸需要考虑使用其他语言绑定,例如Python。 许多Linux发行版都捆绑了开始开发和运行PyGTK应用程序所需的所有软件包。 但是,对于PHP-GTK,您需要安装依赖项,然后编译并安装PHP-GTK。 如果您的主要目标市场是将了解如何通过终端执行命令并且不介意这样做的用户,那么可以肯定的是,PHP-GTK是一个不错的选择–特别是因为在Windows上,有可用的预编译二进制文件。 您需要对预编译的二进制文件执行的所有操作是针对PHP解释器可执行文件执行PHP-GTK脚本。 在Mac OS X上,安装不是那么容易-它实际上与在Linux发行版上安装PHP-GTK一样麻烦。

如何安装PHP-GTK? (How do I install PHP-GTK?)

For Linux distributions, a link at the top of this article is to a forum post we have on our Web Hosting Forum with a detailed howto on getting PHP-GTK installed on Linux distributions such as Ubuntu. The primary issue at hand here is that you need to install quite a few packages (which are referred to as “dependencies” – because PHP-GTK depend on these packages prior to you being able to compile and install PHP-GTK). Once these dependencies are installed, all you need to install after that is “pecl-cairo” (the Cairo Extension) and then compile and install PHP-GTK. However, on Ubuntu, you may also need to do one more step which is relating to libtool.m4. All with easy to follow instructions in the thread itself.

对于Linux发行版,本文顶部的链接是我们在Web托管论坛上的论坛帖子,其中包含在Linux发行版(如Ubuntu)上安装PHP-GTK的详细方法。 这里面临的主要问题是,您需要安装很多软件包(称为“依赖项”,因为PHP-GTK在能够编译和安装PHP-GTK之前依赖于这些软件包)。 安装完这些依赖​​项之后,您只需安装“ pecl-cairo”(Cairo扩展名),然后编译并安装PHP-GTK。 但是,在Ubuntu上,您可能还需要执行与libtool.m4有关的另一步骤。 所有内容都易于遵循线程本身中的说明。

PHP-GTK代码。 (PHP-GTK code.)

So let’s take a look at the code – the code is commented to explain each part.

因此,让我们看一下代码-对代码进行注释以解释每个部分。

public function addMenu() { /* create the menu */ // the “File” and “Help” main menus $file = new GtkMenuItem(“File”); $help = new GtkMenuItem(“Help”);

公共功能addMenu(){/ *创建菜单* / //“文件”和“帮助”主菜单$ file = new GtkMenuItem(“ File”); $ help = new GtkMenuItem(“ Help”);

// create the menubar // we append the File, Help to the MenuBar $menubar = new GtkMenuBar(); $menubar->append($file); $menubar->append($help);

//创建菜单栏//我们将文件,帮助附加到菜单栏$ menubar = new GtkMenuBar(); $ menubar-> append($ file); $ menubar-> append($ help);

// append the menu options // this is for the actual menu options

//附加菜单选项//这是实际的菜单选项

// this is for the “File” menu $menu = new GtkMenu();

//这用于“文件”菜单$ menu = new GtkMenu();

// this is for the “Help” menu $menu2 = new GtkMenu();

//这是用于“帮助”菜单$ menu2 = new GtkMenu();

$open = new GtkMenuItem(“Open”); $save = new GtkMenuItem(“Save As…”); $quit = new GtkMenuItem(“Quit”); $about = new GtkMenuItem(“About”);

$ open = new GtkMenuItem(“ Open”); $ save = new GtkMenuItem(“另存为...”); $ quit = new GtkMenuItem(“ Quit”); $ about = new GtkMenuItem(“ About”);

// connect the signals

//连接信号

$quit->connect_simple(‘activate’,array($this,’menuOptionClicked’),”quit”); $open->connect_simple(‘activate’,array($this,’menuOptionClicked’),”open”); $save->connect_simple(‘activate’,array($this,’menuOptionClicked’),”save”);

$ quit-> connect_simple('activate',array($ this,'menuOptionClicked'),“ quit”); $ open-> connect_simple('activate',array($ this,'menuOptionClicked'),“ open”); $ save-> connect_simple('activate',array($ this,'menuOptionClicked'),“ save”);

// we append the menu items to the MenuBar $menu->append($open); $menu->append($this->menuSaveItem); $menu->append($quit);

//我们将菜单项附加到MenuBar $ menu-> append($ open); $ menu-> append($ this-> menuSaveItem); $ menu-> append($ quit);

$menu2->append($about);

$ menu2-> append($ about);

// we set the MenuBar as the submenu for the MenuItem “File” and likewise for “Help” $file->set_submenu($menu); $help->set_submenu($menu2);

//我们将MenuBar设置为MenuItem“文件”的子菜单,同样将其设置为“帮助”的子菜单$ file-> set_submenu($ menu); $ help-> set_submenu($ menu2);

// we the pack the $menubar the MenuBar (which holds File and Help, to the init_vbox) $this->init_vbox->pack_start($menubar,FALSE,FALSE); }

//我们将$ menubar打包在MenuBar(将文件和帮助保存到init_vbox中)中$ this-> init_vbox-> pack_start($ menubar,FALSE,FALSE); }

You can then execute this method where necessary. For example, via the constructor method. Such as:

然后,可以在必要时执行此方法。 例如,通过构造方法。 如:

public function __construct() { $this->addMenu(); // execute the addMenu() method }

公共功能__construct(){$ this-> addMenu(); //执行addMenu()方法}

And that’s it! It’s not as simple as it could be, but once you understand how it works – it’s easy to do again.

就是这样! 它并不像它可能的那么简单,但是一旦您了解了它的工作原理,就很容易再次进行。

翻译自: https://www.eukhost.com/blog/webhosting/how-to-create-php-gtk-gtk-menus-menu-items/

gtk 下拉菜单控件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值