Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 499411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:58:57+00:00 2026-05-13T05:58:57+00:00

I have an application wich is minimized to the tray (showing an icon) when

  • 0

I have an application wich is minimized to the tray (showing an icon) when the user close it. What I need to know is how can I call it back with a combination of keys, like Ctrl+Alt+Something. Actually I call it back when I double-click it, but it will be nice to do the same on a keystroke. Here is a portion of the code:

# -*- coding: utf-8 -*-

"""The user interface for our app"""

import os,sys
import ConfigParser

# Import Qt modules
from PyQt4 import QtCore,QtGui

# Import the compiled UI module
from octo import Ui_Form
CFG_PATH = "etc/config.list"   #Config File Path
#config.list vars DEFAULT Values
ClipCount = 8
Static = ""
window = None


# Create a class for our main window
class Main(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)        
        # This is always the same
        self.ui=Ui_Form()
        self.ui.setupUi(self)
        # Window Icon
        icon = QtGui.QIcon("SSaver.ico")    
        self.setWindowIcon(icon)
        self.setWindowTitle("Octopy")     
        # Set the timer =)      
        self.timer = self.startTimer(1000) #self.killTimer(self.timer)
        # Clipboard Counter
        self.counter = 0
        #Last trapped clipboard
        self.LastClip = ""           
        self.tentacles = [""] * 8  

        self.cmd = []
        self.cmd.append(self.ui.cmd_1)
        self.cmd.append(self.ui.cmd_2)
        self.cmd.append(self.ui.cmd_3)
        self.cmd.append(self.ui.cmd_4)
        self.cmd.append(self.ui.cmd_5)
        self.cmd.append(self.ui.cmd_6)                                        
        self.cmd.append(self.ui.cmd_7)
        self.cmd.append(self.ui.cmd_8)                

## Events ##          
    def on_cmd_8_pressed(self): #Clear
        for i in range(0,7):
            self.tentacles[i] = ""            
            self.cmd[i].setText(self.tentacles[i])  


    def on_cmd_1_pressed(self):
        t = self.ui.cmd_1.text()
        self.setClp(t)

    def on_cmd_2_pressed(self):
        t = self.ui.cmd_2.text()
        self.setClp(t)

    def on_cmd_3_pressed(self):
        t = self.ui.cmd_3.text()
        self.setClp(t)

    def on_cmd_4_pressed(self):
        t = self.ui.cmd_4.text()
        self.setClp(t)

    def on_cmd_5_pressed(self):
        t = self.ui.cmd_5.text()
        self.setClp(t)

    def on_cmd_6_pressed(self):
        t = self.ui.cmd_6.text()
        self.setClp(t)

    def on_cmd_7_pressed(self):                        
        t = self.ui.cmd_7.text()
        self.setClp(t)

    def hideEvent(self,event): # Capture close and minimize events
        pass

    def keyPressEvent(self,ev):
        if ev.key() == 16777216:
            self.hide()

    def showEvent(self,ev):
        self.fillClp()       

    def timerEvent(self,ev):
        c = self.getClp()           
        if c:                        
            #print c, self.counter 
            self.tentacles[self.counter] = c
            if self.counter < 7:
                self.counter += 1
            else:
                self.counter = 0

            self.fillClp()

## Functions ##
    def fillClp(self):
        for i in range(0,7):
            self.cmd[i].setText(self.tentacles[i])   

    def getClp(self):
        clp = QtGui.QApplication.clipboard() 
        c = clp.text()                        
        if self.LastClip != c:
            self.LastClip = c
            return c
        else:
            return None

    def setClp(self, t):               
        clp = QtGui.QApplication.clipboard() 
        clp.setText(t)        


class SystemTrayIcon(QtGui.QSystemTrayIcon):
    def __init__(self, icon, parent=None):
        QtGui.QSystemTrayIcon.__init__(self, icon, parent)
        menu = QtGui.QMenu(parent)                
        # Actions
        self.action_quit = QtGui.QAction("Quit", self)
        self.action_about = QtGui.QAction("About Octopy", self)
        # Add actions to menu
        menu.addAction(self.action_about)
        menu.addSeparator()
        menu.addAction(self.action_quit)
        # Connect menu with signals
        self.connect(self.action_about, QtCore.SIGNAL("triggered()"), self.about)       
        self.connect(self.action_quit, QtCore.SIGNAL("triggered()"), self.quit) 
        # Other signals
        traySignal = "activated(QSystemTrayIcon::ActivationReason)"
        QtCore.QObject.connect(self, QtCore.SIGNAL(traySignal), self.icon_activated)
        # Create Menu               
        self.setContextMenu(menu)

    def quit(self):
        w = QtGui.QWidget()
        reply = QtGui.QMessageBox.question(w, 'Confirm Action',"Are you sure to quit?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
        if reply == QtGui.QMessageBox.Yes:           
            QtGui.QApplication.quit()

    def about(self):            
        w = QtGui.QWidget()
        QtGui.QMessageBox.information(w, 'About', "Octopy Multi-Clipboard Manager\n Developed by mRt.")

    def icon_activated(self, reason):
        if reason == QtGui.QSystemTrayIcon.DoubleClick:
            window.show()
        else:
            print "otro"     


def main():
    # Again, this is boilerplate, it's going to be the same on 
    # almost every app you write
    app = QtGui.QApplication(sys.argv)        
    # TrayIcon
    w = QtGui.QWidget()
    icon = QtGui.QIcon("SSaver.ico")          
    trayIcon = SystemTrayIcon(icon, w)
    trayIcon.show()    
    trayIcon.setToolTip("Octopy Multi-Clipboard Manager")    
    # Main Window
    global window    
    window=Main()
    window.show()    
    window.setWindowTitle("Octopy")
    app.setQuitOnLastWindowClosed(0)
    sys.exit(app.exec_())    


def readIni():
    cfg = ConfigParser.ConfigParser()
    cfg.read(CFG_PATH)
    ClipCount = int(cfg.get("Other","ClipCount"))
    Static = cfg.get("Other","Static")
    clip = [""] * int(ClipCount+1)    


if __name__ == "__main__":
    readIni()
    main()

The complete program is hosted on google: http://code.google.com/p/octopys/downloads/list

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:58:58+00:00Added an answer on May 13, 2026 at 5:58 am

    For a keystroke to be handled by your application when it does not have keyboard focus, you need to install a global shortcut. Qt doesn’t support this, but Qxt, a Qt extension library, does. See
    http://doc.libqxt.org/0.5.0/classQxtGlobalShortcut.html. I don’t know if PyQt bindings exist for Qxt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one application in wich I need to make code changes almost all
I have a drive application wich changes the permissions so another user becomes the
I need to code an application wich Front end and Backend have different templates.
I need to check in my portlet wich language does an user have selected
i have a online application for wich i require a sort of dashboard (to
I have application that is up more than 3 days. I can see in
I have an ASP.net MVC2 application. In wich I'm using JQuery to alter all
i have a privacy form, in wich i am selecting what application should be
I have an application wich open a modal form with the ShowDialog method. Once
I have an application wich has Oauth access using Twitter as provider. I also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.