简体   繁体   English

GTK可以与像图书馆这样的readline一起使用吗?

[英]Can GTK work with a readline like library?

Is it possible for a graphical GTK program, to also have a "command line interface" like those provided by GNU readline , editline or linenoise ? 图形GTK程序是否也可能具有“命令行界面”,如GNU readlineeditlinelinenoise提供的那些?

How to deal with blocking gtk_main() calls, and blocking loop steps from those libraries? 如何处理阻止gtk_main()调用以及阻止来自这些库的循环步骤?

It is definitely possible to integrate a library such as GNU readline with a graphical program. 绝对有可能将诸如GNU readline之类的库与图形程序集成在一起。 The simplest option is to spawn a thread dedicated for readline, and communicate with the GUI thread using g_idle_add (which is thread-safe). 最简单的选择是生成专用于readline的线程,并使用g_idle_add (这是线程安全的)与GUI线程进行通信。

If you don't want to use threads, you can use the GIO machinery ( g_io_channel_unix_new() and g_io_add_watch() ) to instruct the GTK main loop notify you of pending input, and invoke readline using the altnernate interface designed for use as event loop callback. 如果您不想使用线程,则可以使用GIO机制( g_io_channel_unix_new()g_io_add_watch() )来指示GTK主循环将待处理的输入通知您,并使用用于事件循环的备用接口调用readline。打回来。 Python's readline support and PyGTK make use of these features to enable the following, all in one thread: Python的readline支持和PyGTK利用这些功能在一个线程中启用以下功能:

>>> import gtk
>>> w = gtk.Window()
>>> w.add(gtk.Label("foo"))
>>> w.show_all()       # at this point, a window with label is shown

A different question, however, is whether you want your program to sport a command-line interface based on terminal emulation in the 21st century. 但是,另一个问题是,是否要让您的程序运行基于21世纪终端仿真的命令行界面。 In GTK you have a multiline editing facility that far exceeds readline(), it's called a GtkTextView . 在GTK中,您拥有的多行编辑工具远远超过了readline(),它称为GtkTextView It is quite straightforward (and, I might add, fun) to use it to build a command-line-like facility which has no problems with copy-paste, multiline editing, Unicode, colors, proportional fonts, embedded images, or with working on Windows — and which doesn't rely on arcane terminal codes to boot. 使用它来构建类似命令行的工具非常简单(我可能会添加一点乐趣),该工具在复制粘贴,多行编辑,Unicode,颜色,比例字体,嵌入式图像或工作方面都没有问题。在Windows上-并且不依赖奥术终端代码来启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM