ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash variables are loosely typed, sorta like javascript. GTK3 (well, c) uses actual types like int, char[]. Now suppose I'm writing a program where I want to display the computer's IP address in a GTK_LABEL, but actually the address comes out of something like
An ip4 IP can be at most 20 chars long but can I use char[21]? How do I get from dig's output to GTK3's input? I can't use system(). Is there a more practical way to read the IP?
I'm just barely learning GTK, I don't know about such things yet.
This program:
Code:
#include <stdio.h>
FILE *p; // pipe
int main(void) {
p = popen("$(dig +short myip.opendns.com @resolver1.opendns.com)","r");
if (p) printf("Not null\n");
pclose(p);
return 0;
}
Returns:
Code:
./pas
Not null
sh: 1: 172.58.160.58: not found
So the IP gets dumped out on a command line and sh doesn't know why. I guess it's a start.
I want to set up a Raspberry Pi with an 8 inch touch screen display (no mouse or keyboard) as an ad blocking wifi AP fed from a CAT5 internet connection. Right now I have something similar fed by this Pi, which is fed by Easytether and a USB cable from a cell phone. So I want useful stuff on the touchscreen I can read and tap on. I was trying to use Whiptail but I don't think that's going to cut it.
I'm newish to GTK but I like GTK3. I've done some xlib stuff, and bunches of Borland Delphi in another life. Making a fake GTK form here. I can turn off blocking with symlink games with the hosts file. So there's my real IP at top, beginnings of a button (1 of 2), and 2 labels for (fake) uptime and data age.
I've used Glade, or tried to. I've been trying since GTK 1 and 2, maybe 20 years, it just never clicked before. Now I can pull out my checklist or an old program I wrote and actually make stuff happen. I do xlib that way now too, there's a set of steps which have to be in the right order with none forgotten. https://sourceforge.net/projects/epidemicsim/
I'd like to see somebody write an unglade which could remove glade's tokens and replace them with straight GTK code so it would compile without libglade. Glade is "cheating" in my book. I haven't tried GTK4 yet.
Semi-related question: I make my 2 pushbuttons for blocking on and off with gtk_button_new_with_label(). I use signal_connect_swapped and write callbacks which I can trigger when they're clicked. But I want to change some colors on the faces of the buttons to show the state of the blocking. I can send markup to them except I need a handle or pointer or something that refers to the labels in the buttons.
Just tried
Code:
onLabel = btn_on->get_child();
but ‘GtkWidget’ {aka ‘struct _GtkWidget’} has no member named ‘get_child’
Hmm, it's not so much changing the label I want as having a cursor, something that indicates which item is selected. I don't see a reasonable way to change the markup, I was going to change the text color on the selected item. I suppose I could add an * or something to the selected one and take it away again. (Blocking on/Blocking off buttons). I'm looking at Devhelp for info. Maybe there's a way to change the markup but it belongs to the label that's on the button, I don't see anything under gtk_button that looks right.
Which sort of works, except the way I'm getting a handle/pointer/whatever for the labels on the buttons is by doing gtk_container_get_children. This is clumsy if there's more than one child, you'd really want more like list1->data[0] which doesn't work. Get_children returns a glist but how do you move around the list? I was using list1, markup1, etc. expecting a list for each button.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.