GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Sep 18, 2014 1:41 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: VTE read output from terminal
PostPosted: Sun Feb 15, 2009 12:37 pm 
Offline

Joined: Sun Feb 15, 2009 12:16 pm
Posts: 1
Hi, I creat a virtual terminal, signals for "contents-changed" and "child-exited". I run command "hcitool" arg: "dev"

I read terminal in signals:
gchar *a[] = {vte_terminal_get_text(VTE_TERMINAL(terminal),NULL,NULL,NULL)};

If command end, *a ist empty :( and "contents-changed" no started.

How read terminal?

concise source code:


[code=]
#include <vte/vte.h>
#include <iostream>
...
using namespace std;
void chang(){
gchar *a[] = {vte_terminal_get_text(VTE_TERMINAL(terminal),NULL,NULL,NULL)};
cout<<*a<<endl
}
void ending(){
gchar *a[] = {vte_terminal_get_text(VTE_TERMINAL(terminal),NULL,NULL,NULL)};
cout<<*a<<endl
}

int main (int argc, char **argv)
{
terminal = vte_terminal_new();
g_signal_connect (G_OBJECT (VTE_TERMINAL(terminal)), "contents-changed", G_CALLBACK (chang),NULL);
g_signal_connect (G_OBJECT (VTE_TERMINAL(terminal)), "child-exited",G_CALLBACK (ending),NULL);
char* args[] = {"/usr/bin/hcitool", "dev",NULL};

int a = vte_terminal_fork_command(VTE_TERMINAL(terminal),args[0], args, NULL,"/home/martingt", fals, false, false);
...
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2009 7:56 pm 
Offline

Joined: Thu Feb 26, 2009 7:46 pm
Posts: 3
I have the same problem. After longtime searching I discovered more low level solution. I think you can read child's output (process which are running in VTE) with GIOChannel and this function:

Code:
static gboolean vte_terminal_io_read(GIOChannel *channel,         GIOCondition condition, VteTerminal *terminal);

For additional info see vte.c from VTE source code.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 7:58 pm 
Offline

Joined: Thu Feb 26, 2009 7:46 pm
Posts: 3
Norbert wrote:
I have the same problem. After longtime searching I discovered more low level solution. I think you can read child's output (process which are running in VTE) with GIOChannel and this function:

Code:
static gboolean vte_terminal_io_read(GIOChannel *channel,         GIOCondition condition, VteTerminal *terminal);

For additional info see vte.c from VTE source code.


My previous post was not correct. The vte_terminal_io_read function is STATIC. It mean that is not present in vte library.
Function that you are going to use (vte_terminal_get_text) works if is_selected=TRUE - if you select text. Therefore empty a variable is normal.

My new solution is:
[code=]
g_io_add_watch(VTE_TERMINAL(terminal)->pvt->pty_channel, G_IO_IN, read_data, VTE_TERMINAL(terminal)); // creating watch for reading data from a VteTerminal's pipe.

// read_data function is
gboolean read_data (GIOChannel *source, GIOCondition condition, gpointer data)
{
char buf[32768];
gsize size;
GIOStatus status;
g_assert(VTE_IS_TERMINAL(data));
status = g_io_channel_read_chars(source, buf, sizeof(buf), &size, NULL);

if (((status == G_IO_STATUS_NORMAL) || (status == G_IO_STATUS_EOF)) && (size > 0))
{
// g_print("read /n%s",buf); // debug
vte_terminal_feed(VTE_TERMINAL(data), buf, size);
return TRUE;
}
return FALSE;
}
[/code]


Top
 Profile  
 
 Post subject: how to dispaly a VTE using glade ang gtk+c
PostPosted: Tue Mar 10, 2009 6:45 am 
Offline
Familiar Face

Joined: Tue Mar 10, 2009 6:30 am
Posts: 9
actually, i am doing the project using glade+gtk+c, but, i have some problem doing it in order, the supervisor need the VTE terminal to be put in the interface for the second version software. I dont know how to make the VTE terminal pop-up in the interface like the popup window....
it means like, i have button for the VTE, and if i click the button, the terminal will show...
anyone can give a help..
thank u so much....


Top
 Profile  
 
 Post subject: Re: how to dispaly a VTE using glade ang gtk+c
PostPosted: Wed Mar 11, 2009 10:47 am 
Offline

Joined: Thu Feb 26, 2009 7:46 pm
Posts: 3
arih wrote:
actually, i am doing the project using glade+gtk+c, but, i have some problem doing it in order, the supervisor need the VTE terminal to be put in the interface for the second version software. I dont know how to make the VTE terminal pop-up in the interface like the popup window....
it means like, i have button for the VTE, and if i click the button, the terminal will show...
anyone can give a help..
thank u so much....


Hello! I think you can do it with my code:
Code:
// vteopener.c by Norbert.
// Compile and run with command:
// gcc vteopener.c -o vteopener `pkg-config --cflags --libs gtk+-2.0 vte` && ./vteopener

#include <gtk/gtk.h>
#include <vte/vte.h>

static void exec_shell_in_vte(GtkWidget *widget)
{
   if (!GTK_WIDGET_REALIZED (widget))
      return;

    vte_terminal_fork_command (VTE_TERMINAL(widget), NULL, NULL, NULL, NULL,  0, 0, 0); // execute a Shell in VTE
}

static void showvte ()
{
  GtkWidget *popup_window; // pointer to VTE pop-up windows
  GtkWidget *vteterminal;  // pointer to VTE widget

    popup_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(popup_window), "VTE Pop-up window");


    vteterminal = vte_terminal_new (); // create VTE widget

    g_signal_connect(vteterminal, "realize",G_CALLBACK(exec_shell_in_vte), popup_window); // creating a signal for execution Shell in VTE after creation of VTE widget

    gtk_container_add(GTK_CONTAINER(popup_window), vteterminal);
    gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_CENTER);
    gtk_widget_realize (vteterminal);
    gtk_widget_show_all(popup_window);
}

int main (int argc, char *argv[])
{
  GtkWidget *button = NULL; // pointer to Execution button
  GtkWidget *win = NULL;    // pointer to Window with Execution button

  /* Initialize GTK+ */
  gtk_init (&argc, &argv);

  /* Create the main window */
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (win), 100);
  gtk_window_set_title (GTK_WINDOW (win), "VTE opener");
  gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
  gtk_widget_realize (win);
  g_signal_connect (win, "destroy", gtk_main_quit, NULL);

  /* Create a button */
  button = gtk_button_new_from_stock (GTK_STOCK_EXECUTE);
    g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (showvte), NULL); // creating a signal for opening VTE pop-up window
  gtk_container_add (GTK_CONTAINER (win), button);

  /* Enter the main loop */
  gtk_widget_show_all (win);
  gtk_main ();
  return 0;
}


Think more abstactly. It is does not matter which window you open - VTE or other window. It is simply opening one window from another:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 4:31 am 
Offline
Familiar Face

Joined: Tue Mar 10, 2009 6:30 am
Posts: 9
tq norbert...
i willl try it...
because i already do some code but when i am compiling the code, there have some error, like undefined references... and ld exit 1 something like that, so now, a im trying to configure why there is an error...
but i will try to compile your code...
thanks 4 helping.....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 7:34 am 
Offline
Familiar Face

Joined: Tue Mar 10, 2009 6:30 am
Posts: 9
tq norbert i already run the code, it works...
:D


Top
 Profile  
 
 Post subject: Re: VTE read output from terminal
PostPosted: Sat Dec 10, 2011 4:39 pm 
Offline

Joined: Fri Dec 09, 2011 10:21 pm
Posts: 2
Location: Italy
Hi to all forum ,

On first sorry for my english .

I try to compile the Norbet example but I have follow error : vte_terminal_fork_command' is deprecated (declared at /usr/include/vte-0.0/vte/vtedeprecated.h:82).

Can you help me ?

Many thanks.


Top
 Profile  
 
 Post subject: Re: VTE read output from terminal
PostPosted: Sat Dec 10, 2011 7:16 pm 
Offline

Joined: Fri Dec 09, 2011 10:21 pm
Posts: 2
Location: Italy
I reply on myself ,

new vte_terminal_fork_command = vte_terminal_fork_command_full .


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group