<i id='tmRLU'><tr id='tmRLU'><dt id='tmRLU'><q id='tmRLU'><span id='tmRLU'><b id='tmRLU'><form id='tmRLU'><ins id='tmRLU'></ins><ul id='tmRLU'></ul><sub id='tmRLU'></sub></form><legend id='tmRLU'></legend><bdo id='tmRLU'><pre id='tmRLU'><center id='tmRLU'></center></pre></bdo></b><th id='tmRLU'></th></span></q></dt></tr></i><div id='tmRLU'><tfoot id='tmRLU'></tfoot><dl id='tmRLU'><fieldset id='tmRLU'></fieldset></dl></div>

<legend id='tmRLU'><style id='tmRLU'><dir id='tmRLU'><q id='tmRLU'></q></dir></style></legend>

<tfoot id='tmRLU'></tfoot>

<small id='tmRLU'></small><noframes id='tmRLU'>

      <bdo id='tmRLU'></bdo><ul id='tmRLU'></ul>
      1. 如何在VScode和PyCharm这样的PyGtk应用中实现Linux终端?

        时间:2024-08-21

          <tbody id='V1Uh0'></tbody>

          <legend id='V1Uh0'><style id='V1Uh0'><dir id='V1Uh0'><q id='V1Uh0'></q></dir></style></legend>
          <i id='V1Uh0'><tr id='V1Uh0'><dt id='V1Uh0'><q id='V1Uh0'><span id='V1Uh0'><b id='V1Uh0'><form id='V1Uh0'><ins id='V1Uh0'></ins><ul id='V1Uh0'></ul><sub id='V1Uh0'></sub></form><legend id='V1Uh0'></legend><bdo id='V1Uh0'><pre id='V1Uh0'><center id='V1Uh0'></center></pre></bdo></b><th id='V1Uh0'></th></span></q></dt></tr></i><div id='V1Uh0'><tfoot id='V1Uh0'></tfoot><dl id='V1Uh0'><fieldset id='V1Uh0'></fieldset></dl></div>
        1. <tfoot id='V1Uh0'></tfoot>

            • <bdo id='V1Uh0'></bdo><ul id='V1Uh0'></ul>
              1. <small id='V1Uh0'></small><noframes id='V1Uh0'>

                  本文介绍了如何在VScode和PyCharm这样的PyGtk应用中实现Linux终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  问题陈述:在GUI中嵌入用于Linux的终端仿真程序,并通过GUI组件向其提供自定义命令。

                  使用:

                  Python 3

                  GTK+3

                  Vte.get_Minor_Version():58

                  Vte.get_MAJOR_VERSION():0

                  Vte.get_MACRO_VERSION():2

                  我一直在尝试在PyGtk应用程序(如PyCharm和VScode中的应用程序)中嵌入终端仿真器,并通过GTK GUI向其提供系统命令。我曾尝试VTE在按下按钮时使用Terminal.feed_Child()方法向其馈送命令,但无法正常工作。我尝试了以下示例:

                  from gi.repository import Gtk,GObject, Vte
                  #GObject is not required. I just import it everywhere just in case.
                  #Gtk, Vte, and GLib are required.
                  from gi.repository import GLib
                  import os
                  #os.environ['HOME'] helps to keep from hard coding the home string.
                  #os is not required unless you want that functionality.
                  
                  class TheWindow(Gtk.Window):
                  
                      def __init__(self):
                          Gtk.Window.__init__(self, title="inherited cell renderer")
                          self.set_default_size(600, 300)
                          global terminal
                          terminal     = Vte.Terminal()
                          terminal.spawn_sync(
                                  Vte.PtyFlags.DEFAULT, #default is fine
                                  os.environ['HOME'], #where to start the command?
                                  ["/bin/sh"], #where is the emulator?
                                  [], #it's ok to leave this list empty
                                  GLib.SpawnFlags.DO_NOT_REAP_CHILD,
                                  None, #at least None is required
                                  None,
                                  )
                          #Set up a button to click and run a demo command
                          self.button = Gtk.Button("Do The Command")
                          #To get the command to automatically run
                          #a newline(
                  ) character is used at the end of the
                          #command string.
                  
                          self.command = "echo "Sending this command to a virtual terminal."
                  "
                          command = Gtk.Label("The command: "+self.command)
                          self.button.connect("clicked", self.InputToTerm)
                          #end demo command code
                  
                          #set up the interface
                          box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
                          box.pack_start(self.button, False, True, 0)
                          box.pack_start(command, False, True, 1)
                          #a scroll window is required for the terminal
                          scroller = Gtk.ScrolledWindow()
                          scroller.set_hexpand(True)
                          scroller.set_vexpand(True)
                          scroller.add(terminal)
                          box.pack_start(scroller, False, True, 2)
                          self.add(box)
                  
                      def InputToTerm(self, clicker):
                          #get the command when the button is clicked
                          length = len(self.command)
                          #A length is not required but is the easiest mechanism.
                          #Otherwise the command must be null terminated.
                          #Feed the command to the terminal.
                          # terminal.feed_child(self.command, length )
                          # terminal.feed_child(self.command)
                          # command = "hello"
                          terminal.feed_child(self.command)
                          print(Vte.get_minor_version())
                          os.system("suhelp")
                  
                  
                  win = TheWindow()
                  win.connect("delete-event", Gtk.main_quit)
                  win.show_all()
                  Gtk.main()```
                  
                  this results in following error:
                  ```File "......", line 59, in InputToTerm
                      terminal.feed_child(self.command)
                  TypeError: Item 0: Must be number, not str
                  

                  有人能帮我解决这个问题吗?

                  是否有其他方法可以解决问题陈述?

                  Python

                  Vte.Terminal.feed_child()在推荐答案中生成它的方式似乎有一个错误。如果将说明参数为intNone的Python documentation与C documentation进行比较,则可以看到差异。

                  我建议使用feed_child_binary()bytes对象解决此问题,并将错误报告给PyGObject。

                  这篇关于如何在VScode和PyCharm这样的PyGtk应用中实现Linux终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何重载自定义类的`Float()`? 下一篇:在GTK主循环中运行的Asyncio调用

                  相关文章

                    <small id='7SLY9'></small><noframes id='7SLY9'>

                    <i id='7SLY9'><tr id='7SLY9'><dt id='7SLY9'><q id='7SLY9'><span id='7SLY9'><b id='7SLY9'><form id='7SLY9'><ins id='7SLY9'></ins><ul id='7SLY9'></ul><sub id='7SLY9'></sub></form><legend id='7SLY9'></legend><bdo id='7SLY9'><pre id='7SLY9'><center id='7SLY9'></center></pre></bdo></b><th id='7SLY9'></th></span></q></dt></tr></i><div id='7SLY9'><tfoot id='7SLY9'></tfoot><dl id='7SLY9'><fieldset id='7SLY9'></fieldset></dl></div>
                      <bdo id='7SLY9'></bdo><ul id='7SLY9'></ul>
                    <tfoot id='7SLY9'></tfoot>
                      <legend id='7SLY9'><style id='7SLY9'><dir id='7SLY9'><q id='7SLY9'></q></dir></style></legend>