0

I'm very new to linux and I don't know very much. I was creating my own application with Quickly, and I wanted to have a button which launches the Hardware Information application "Hardinfo". I'm very new and I literally don't know anything, any help would be very much appreciated. Thanks in advance!

Update: I'm not looking for a keyboard shortcut, by button I meant a gtk-button inside glade. How to I set it so that when clicked it would take me to the application "hardinfo". If this isn't possible, then how can I set the button to emulate a keyboard shortcut once clicked, inside glade, Thankssssss!

Update 2: What I'm looking for is a step by step process of how to do this from someone who knows glade and quickly completely, because I have no idea how the codes work and where I'm supposed to put them :/

1
  • if you are looking for keyboard shortcut to launch a program see this
    – Bibi424
    May 1, 2014 at 16:17

3 Answers 3

0

OK, how about a clear and concise (working) example:

  1. quickly create ubuntu-application test
  2. cd test
  3. quickly design
  4. Add a button somewhere with Glade (by default it is called "button1")
  5. Save and close Glade
  6. quickly edit and go to TestWindow.py
  7. Add the following at the top of the file:

    from multiprocessing import Process
    import subprocess
    
  8. Add the following to the end of the file and make sure it is indented properly (pro tip: select the block of text in Gedit and hit tab to indent the whole block):

    def on_button1_clicked(self, widget, data=None):
        p = Process(target=self.launch_hardinfo)
        p.start()
    
    def launch_hardinfo(self):
        subprocess.call(["hardinfo"])
    

    These two functions work together. Process.start() calls TestWindow.launch_hardinfo (that's the target= parameter to the Process constructor) in a new thread so that subprocess.call() doesn't block the application.

  9. Save TestWindow.py

  10. quickly run and and click the button.

I had a little issue because I was trying to assign signals in Glade, but you don't even need to do that. The Quickly library actually allows you to do stuff like on_button1_click() which means "when the control called button1 is clicked." Simple as that! Hopefully this should get you started.

See also: Creating Ubuntu Application with Quickly

1
  • I still don't know how to go about doing this :/
    – user276752
    May 1, 2014 at 17:03
0

Had to boot up Ubuntu in a VM for this one, I don't use Unity ;)

You can set up custom keybinds by opening the launcher (top left-hand button) and going to "Keyboard." From there you can go to the "Shortcuts" tab and create a custom shortcut. Name it whatever you wish, but make the command "hardinfo" (no quotes). After that's completed, click the right-hand side of the line that was just added to set your keystroke.

5
  • Nooo I'm not looking for a keyboard shortcut, by button I meant a gtk-button inside glade. How do I set it so that when clicked it would take me to the application "hardinfo". Thank you!!!
    – user276752
    May 1, 2014 at 16:35
  • Oh, wow >.<. I must have totally missed the "creating my own application" part. Let me see if I can find your answer.
    – Chuck R
    May 1, 2014 at 16:44
  • I'm not familiar with Quickly. What language does it use? C? Python?
    – Chuck R
    May 1, 2014 at 16:50
  • Quickly uses Python
    – user276752
    May 1, 2014 at 16:52
  • OK, give me a minute and I'll have your answer up.
    – Chuck R
    May 1, 2014 at 16:54
0

You want something like this. I can't do this in Python, only in Perl, but it will look similar in Python.

sub startapp {
    system "/usr/bin/name_of_application &";
}

$button = Gtk2::Button->new("Start application");
$button->signal_connect(clicked => \&startapp, $window);
$button->show;
4
  • What should I do with that? haha sorry I dont know anything about coding :')
    – user276752
    May 1, 2014 at 16:57
  • Is it not preferred to use the os.system() call as noted here. That was also going to by my re-done answer to the question, but after seeing the info on the Python documentation, I changed it.
    – Chuck R
    May 1, 2014 at 17:03
  • @Githlar I know, or rather, what you say rings a bell. However, the system call, with its limitations and probably security issues, has served me pretty well over the years. I wouldn't try this in a professional environment though.
    – Jos
    May 1, 2014 at 17:17
  • I hear you. It's a standard call. The same could be said about Python threading ;) But in a system where the the program is usually in a waiting state such as this one, no harm done.
    – Chuck R
    May 1, 2014 at 18:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .