On the attached image on the left window i have ubuntu console with content of the file and on the right window i have content of the same file in my gtk program. The Problem is that I want my gtk program to display file exacly as it is displayed on my ubuntu console.
I already tried displaying it by adding single line to single gtk_label and adding that label to vertical box, but the result was the same.
Question
Is there anyway i can make my gtk program have same sizing/look the same as in ubuntu console? Thanks in advance for your help!
Here is code of my gtk dialog:
void Zarzadzanie::Wykonaj(GtkWidget* widget, GtkWidget* data)
{
string buffer;
string n="";
GtkWidget *dialog, *label, *vbox, *window2,*viewer;
//Creating my dialog
dialog=gtk_dialog_new_with_buttons("Polaczenia sieciowe",GTK_WINDOW(gtk_widget_get_toplevel(data)), GTK_DIALOG_MODAL, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,GTK_STOCK_REFRESH,
GTK_RESPONSE_OK, NULL );
vbox=gtk_vbox_new(0,0); //creating new vbox
window2=gtk_scrolled_window_new(0,0); //creating new scrolled window
gtk_button_set_label(GTK_BUTTON(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),GTK_RESPONSE_CLOSE)),"Zamknij Okno"); //setting label in dialog
gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(window2),400); //setting min height in scrollable window
gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(window2),700); //setting min width in scrollable window
viewer=gtk_text_view_new(); //creating new textview
gtk_text_view_set_editable(GTK_TEXT_VIEW (viewer), FALSE); //setting textview to not editable
gtk_container_add(GTK_CONTAINER(window2), viewer); //adding textview to scrollable window
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),window2,0,0,0); //adding scrollable window to dialog
ifstream plik("Pomniejsze/netstat.txt"); //reading from file
if(plik==NULL) //checking if file is not empty
{
//i will add something later
}
else //if file is not empty
{
while(std::getline(plik, buffer)) //i read from file line by line
{
n+=buffer; //i add to "n" 1 line from file
n+="n"; //i add "new line" to "n"
}
char* z=new char[n.length()+1]; //i create new temporary char*
strcpy(z, n.c_str()); //i copy content of "n" to temporary char*
gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(viewer)),z,-1); //i set text of textview to text from temp char*
g_print(z); //i print out temporary char* which can be seen on attached image on left window
delete [] z; //i delete temporary char*
}
g_signal_connect(dialog, "delete-event",G_CALLBACK(gtk_widget_destroy), NULL); // i add delete event to "x" button
gtk_widget_show_all(dialog); //i show my dialog
gint resp=gtk_dialog_run(GTK_DIALOG(dialog)); //i run my dialog
if(resp==GTK_RESPONSE_CLOSE) //i check if user clicked button
{
gtk_widget_destroy(dialog); //if button is clicked i destroy dialog
}
else if(resp==GTK_RESPONSE_OK)
{
//something will be added later
}
}
}
Aucun commentaire:
Enregistrer un commentaire