Advertisement
Guest User

mRt

a guest
Dec 13th, 2009
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.73 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. """The user interface for our app"""
  4.  
  5. import os,sys
  6. import ConfigParser
  7.  
  8. # Import Qt modules
  9. from PyQt4 import QtCore,QtGui
  10.  
  11. # Import the compiled UI module
  12. from octo import Ui_Form
  13. CFG_PATH = "etc/config.list"   #Config File Path
  14. #config.list vars DEFAULT Values
  15. ClipCount = 8
  16. Static = ""
  17. window = None
  18.  
  19.  
  20. # Create a class for our main window
  21. class Main(QtGui.QWidget):
  22.     def __init__(self):
  23.         QtGui.QWidget.__init__(self)        
  24.         # This is always the same
  25.         self.ui=Ui_Form()
  26.         self.ui.setupUi(self)
  27.         # Window Icon
  28.         icon = QtGui.QIcon("SSaver.ico")    
  29.         self.setWindowIcon(icon)
  30.         self.setWindowTitle("Octopy")    
  31.         # Set the timer =)      
  32.         self.timer = self.startTimer(1000) #self.killTimer(self.timer)
  33.         # Clipboard Counter
  34.         self.counter = 0
  35.         #Last trapped clipboard
  36.         self.LastClip = ""           
  37.         self.tentacles = [""] * 8  
  38.        
  39.         self.cmd = []
  40.         self.cmd.append(self.ui.cmd_1)
  41.         self.cmd.append(self.ui.cmd_2)
  42.         self.cmd.append(self.ui.cmd_3)
  43.         self.cmd.append(self.ui.cmd_4)
  44.         self.cmd.append(self.ui.cmd_5)
  45.         self.cmd.append(self.ui.cmd_6)                                        
  46.         self.cmd.append(self.ui.cmd_7)
  47.         self.cmd.append(self.ui.cmd_8)                
  48.        
  49. ## Events ##          
  50.     def on_cmd_8_pressed(self): #Clear
  51.         for i in range(0,7):
  52.             self.tentacles[i] = ""            
  53.             self.cmd[i].setText(self.tentacles[i])  
  54.            
  55.            
  56.     def on_cmd_1_pressed(self):
  57.         t = self.ui.cmd_1.text()
  58.         self.setClp(t)
  59.        
  60.     def on_cmd_2_pressed(self):
  61.         t = self.ui.cmd_2.text()
  62.         self.setClp(t)
  63.        
  64.     def on_cmd_3_pressed(self):
  65.         t = self.ui.cmd_3.text()
  66.         self.setClp(t)
  67.        
  68.     def on_cmd_4_pressed(self):
  69.         t = self.ui.cmd_4.text()
  70.         self.setClp(t)
  71.        
  72.     def on_cmd_5_pressed(self):
  73.         t = self.ui.cmd_5.text()
  74.         self.setClp(t)
  75.        
  76.     def on_cmd_6_pressed(self):
  77.         t = self.ui.cmd_6.text()
  78.         self.setClp(t)
  79.        
  80.     def on_cmd_7_pressed(self):                        
  81.         t = self.ui.cmd_7.text()
  82.         self.setClp(t)
  83.                  
  84.     def hideEvent(self,event): # Capture close and minimize events
  85.         pass
  86.                
  87.     def showEvent(self,ev):
  88.         self.fillClp()      
  89.        
  90.     def timerEvent(self,ev):
  91.         c = self.getClp()          
  92.         if c:                        
  93.             #print c, self.counter
  94.             self.tentacles[self.counter] = c
  95.             if self.counter < 7:
  96.                 self.counter += 1
  97.             else:
  98.                 self.counter = 0
  99.            
  100.             self.fillClp()
  101.  
  102. ## Functions ##
  103.     def fillClp(self):
  104.         for i in range(0,7):
  105.             self.cmd[i].setText(self.tentacles[i])  
  106.  
  107.     def getClp(self):
  108.         clp = QtGui.QApplication.clipboard()
  109.         c = clp.text()                        
  110.         if self.LastClip != c:
  111.             self.LastClip = c
  112.             return c
  113.         else:
  114.             return None
  115.    
  116.     def setClp(self, t):              
  117.         clp = QtGui.QApplication.clipboard()
  118.         clp.setText(t)        
  119.              
  120.              
  121. class SystemTrayIcon(QtGui.QSystemTrayIcon):
  122.     def __init__(self, icon, parent=None):
  123.         QtGui.QSystemTrayIcon.__init__(self, icon, parent)
  124.         menu = QtGui.QMenu(parent)                
  125.         # Actions
  126.         self.action_quit = QtGui.QAction("Quit", self)
  127.         self.action_about = QtGui.QAction("About Octopy", self)
  128.         # Add actions to menu
  129.         menu.addAction(self.action_about)
  130.         menu.addSeparator()
  131.         menu.addAction(self.action_quit)
  132.         # Connect menu with signals
  133.         self.connect(self.action_about, QtCore.SIGNAL("triggered()"), self.about)      
  134.         self.connect(self.action_quit, QtCore.SIGNAL("triggered()"), self.quit)
  135.         # Other signals
  136.         traySignal = "activated(QSystemTrayIcon::ActivationReason)"
  137.         QtCore.QObject.connect(self, QtCore.SIGNAL(traySignal), self.icon_activated)
  138.         # Create Menu              
  139.         self.setContextMenu(menu)
  140.                
  141.     def quit(self):
  142.         w = QtGui.QWidget()
  143.         reply = QtGui.QMessageBox.question(w, 'Confirm Action',"Are you sure to quit?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
  144.         if reply == QtGui.QMessageBox.Yes:          
  145.             QtGui.QApplication.quit()
  146.  
  147.     def about(self):            
  148.         w = QtGui.QWidget()
  149.         QtGui.QMessageBox.information(w, 'About', "Octopy Multi-Clipboard Manager\n Developed by mRt.")
  150.                
  151.     def icon_activated(self, reason):
  152.         if reason == QtGui.QSystemTrayIcon.DoubleClick:
  153.             window.show()
  154.  
  155.  
  156. def main():
  157.     # Again, this is boilerplate, it's going to be the same on
  158.     # almost every app you write
  159.     app = QtGui.QApplication(sys.argv)        
  160.     # TrayIcon
  161.     w = QtGui.QWidget()
  162.     icon = QtGui.QIcon("SSaver.ico")          
  163.     trayIcon = SystemTrayIcon(icon, w)
  164.     trayIcon.show()    
  165.     trayIcon.setToolTip("Octopy Multi-Clipboard Manager")    
  166.     # Main Window
  167.     global window    
  168.     window=Main()
  169.     window.show()    
  170.     window.setWindowTitle("Octopy")
  171.     app.setQuitOnLastWindowClosed(0)
  172.     sys.exit(app.exec_())    
  173.        
  174.        
  175. def readIni():
  176.     cfg = ConfigParser.ConfigParser()
  177.     cfg.read(CFG_PATH)
  178.     ClipCount = int(cfg.get("Other","ClipCount"))
  179.     Static = cfg.get("Other","Static")
  180.     clip = [""] * int(ClipCount+1)    
  181.    
  182.    
  183. if __name__ == "__main__":
  184.     readIni()
  185.     main()
  186.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement