Navigation
 
Search
 
Random Image
CBSet_121953855301.jpg
 
Me. Elsewhere.
 
Archives
 
Darcy
 
Things I Like
EFF
 
License
 
GTK Tooltips On Notebook Tab Labels

Here’s a non-obvious (or to me at least) trick to get tooltips onto a Gtk::Notebook tab. It took some searching, but essentially, you just add the Gtk::Label to a Gtk::EventBox and add that to the tab instead. Then you attach the tool tip to the Gtk::EventBox instead of the Gtk::Label.

Here’s an example. I couldn’t get my example to compile, the linker was going crazy, but I’m 99% sure that it’s fine. I’m probably just not seeing one glaring error. Let me know if you find it. The important stuff is all there, even if it won’t build.

main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <gtkmm/main.h>
#include "nbtt.h"
 
using namespace std;
 
int main (int argc, char *argv[]) {
 
  Gtk::Main kit (argc, argv);
  Nbtt notebookWindow;
  Gtk::Main::run(notebookWindow);
 
  return 0;
}

nbtt.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <gtkmm/window.h>
#include "nbtt.h"
 
using namespace std;
 
Nbtt::Nbtt() {
 
  set_title("Notebook Tabs With Labels!");
  set_border_width(10);
  set_default_size(400, 200);
 
  lblTabOne.set_text("Tab 1");
  lblTabTwo.set_text("Tab 2");
  lblTabThree.set_text("Tab 3");
 
  ebTabOne.add(lblTabOne);
  ebTabTwo.add(lblTabTwo);
  ebTabThree.add(lblTabThree);
 
  toolTips.set_tip(ebTabOne,"Tab to page one.");
  toolTips.set_tip(ebTabTwo,"Tab to page two.");
  toolTips.set_tip(ebTabThree,"Tab to page three.");
 
  exNotebook.append_page(pageOne, ebTabOne);
  exNotebook.append_page(pageTwo, "Second");
 
  show_all();
}

nbtt.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef NBTT_H
#define NBTT_H
 
#include <gtkmm/window.h>
#include <gtkmm/notebook.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/label.h>
#include <gtkmm/tooltips.h>
 
using namespace std;
 
class Nbtt;
 
class Nbtt : public Gtk::Window {
 
  public:
    Nbtt();
 
  private:
    Gtk::Notebook exNotebook;
 
    Gtk::EventBox ebTabOne;
    Gtk::EventBox ebTabTwo;
    Gtk::EventBox ebTabThree;
 
    Gtk::Label lblTabOne;
    Gtk::Label lblTabTwo;
    Gtk::Label lblTabThree;
 
    Gtk::Tooltips toolTips;
 
    Gtk::Label pageOne;
    Gtk::Label pageTwo;
    Gtk::Label pageThree;
 
};
 
#endif // NBTT_H

I found this trick in the gnome-list@gnome.org history. The thread starts here if you want to read the exchange.

Posted August 22nd, 2007 - Permalink
Categories: Geek
Tags: , , ,
No Comments »
 
Warped Jane Austen Quote

From the GNU Automake Documentation:

“It is a truth universally acknowledged, that a developer in possession of a new package, must be in want of a build system.”

Awesome.

Posted August 16th, 2007 - Permalink
Categories: Geek
Tags: , ,
No Comments »
 
Mangling An Applications Path

I was looking to get rid of using some environment variables in the app I do at work for several reasons. One, you can’t grab fresh environment variables on the fly (or at least I can’t) so if anything needs to be changed, you have to do a hard kill and restart the program. Two is that requiring some obscure, application specific environment variables seems a little silly to me, it’s excessive and adds bothersome configuration.

What I really needed was a way to open a config file that always resides in the same directory as the application. To do that I had to take the execution path (e.g. argv[0]) and chop it up a bit so that I can always get to that directory. I’m sure there is a better way to do this, and it wouldn’t work if you had the application in your $PATH, because then argv[0] would just be the executable name. Regardless of the caveats, it works nicely for me and makes me feel better about myself now that I can frag the environment variables.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <fstream>
#include <string>
 
using namespace std;
 
int main (int argc, char* argv[]) {
 
  cout << "File: " << argv[0] << endl;
 
  size_t found;
  string str = argv[0];
 
  found=str.rfind("/");
  if (found!=string::npos)
    str.replace(found,str.length(),"/");
 
  cout << "Trimmed: " << str << endl;
  fstream filestr;
 
  str += "test.conf";
  cout << "To Conf: " << str << endl;
 
  filestr.open (str.c_str(), fstream::in);
  string temp;
 
  getline(filestr,temp);
  cout << temp << endl;
 
  filestr.close();
 
  return 0;
}

Posted August 15th, 2007 - Permalink
Categories: Geek
Tags: , ,
No Comments »
 
C++ String Strip Whitespace

I was at work today and had the hardest time trying to find a function that could strip out whitespace from a string. There isn’t one built into C++, and I can’t just add on libraries (e.g. boost) just for this sort of one-time use item. I couldn’t find an easy drop in on the web either, so I wrote my own based on a templating system I had made.

1
2
3
4
5
6
7
8
9
10
11
12
13
string trimstring (string toTrim) {
 
	size_t found;
	found = toTrim.find(" ");
 
	while(toTrim.length() != 0 && found != string::npos) {
		toTrim.erase(found,1);		
		found = toTrim.find(" ");
	}
 
	return toTrim;
 
}

Very brute-force, but easy to understand right?

Posted August 6th, 2007 - Permalink
Categories: Geek
Tags: , , ,
No Comments »
 
Bash Line For Constant Monitoring

I’ve been doing a lot more bash stuff recently for work and with a book I’m reading. One thing I found handy is this one-liner script to do something every N seconds.

while :; do ps aux | grep ssh | grep -v grep; echo "----------[$(date)]------------";sleep 1; done

You can replace the sleep 1 with sleep N for a larger interval, and the ps aux | grep ssh | grep -v grep is just what I wanted done every second. The echo "----------[$(date)]------------" is a nice way to separate and mark the timing.

An example run:

root      3610  0.0  0.0  59516   568 ?        Ss   Jul30   0:00 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid
jmhobbs   3963  0.0  0.0  46636   432 ?        Ss   Jul30   0:00 /usr/bin/ssh-agent /bin/bash /etc/X11/xinit/xinitrc
----------[Wed Aug  1 14:21:07 CDT 2007]------------
root      3610  0.0  0.0  59516   568 ?        Ss   Jul30   0:00 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid
jmhobbs   3963  0.0  0.0  46636   432 ?        Ss   Jul30   0:00 /usr/bin/ssh-agent /bin/bash /etc/X11/xinit/xinitrc
----------[Wed Aug  1 14:21:08 CDT 2007]------------
root      3610  0.0  0.0  59516   568 ?        Ss   Jul30   0:00 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid
jmhobbs   3963  0.0  0.0  46636   432 ?        Ss   Jul30   0:00 /usr/bin/ssh-agent /bin/bash /etc/X11/xinit/xinitrc
jmhobbs   2404  0.0  0.1  49480  1004 ?        Ss   14:21   0:00 /usr/bin/ssh -f -N -i /var/auth/tunnel_grandisland -L 36200:127.0.0.1:3306 -l grandisland statserver
----------[Wed Aug  1 14:21:09 CDT 2007]------------
root      3610  0.0  0.0  59516   568 ?        Ss   Jul30   0:00 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid
jmhobbs   3963  0.0  0.0  46636   432 ?        Ss   Jul30   0:00 /usr/bin/ssh-agent /bin/bash /etc/X11/xinit/xinitrc
----------[Wed Aug  1 14:21:10 CDT 2007]------------
root      3610  0.0  0.0  59516   568 ?        Ss   Jul30   0:00 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid
jmhobbs   3963  0.0  0.0  46636   432 ?        Ss   Jul30   0:00 /usr/bin/ssh-agent /bin/bash /etc/X11/xinit/xinitrc
----------[Wed Aug  1 14:21:11 CDT 2007]------------

Update: (2008-09-23)
Silly me, I just inelegantly rewrote watch

watch -n 1 'ps aux | grep ssh | grep -v grep'

The -n is for specifying seconds between refresh.

Every 1.0s: ps aux | grep ssh | grep -v grep                                                                                           Tue Sep 23 15:22:15 2008
 
root      3510  0.0  0.0   6016   620 ?        Ss   Sep05   0:02 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid
jmhobbs  12606  0.0  0.0   5452   456 ?        Ss   Sep18   0:00 /usr/bin/ssh-agent /bin/bash /etc/X11/xinit/xinitrc

Posted August 1st, 2007 - Permalink
Categories: Geek
Tags: , ,
No Comments »
 
More Posts
 
Copyright © 2006 - 2010 John Hobbs