Commits

Josh VanderLinden committed ba852ee

Finally making clip2zeus compatible with KDE

Comments (0)

Files changed (6)

+syntax: glob
+*.pyc
+*.swp

clip2zeus/__init__.py

 APP_TITLE = 'Clip2Zeus'
 __author__ = 'Josh VanderLinden'
-__version__ = '1.4a'
+__version__ = '1.5a'
 

clip2zeus/common.py

 from datetime import datetime, timedelta
 from threading import Thread, Event
-import re
 
 try:
     # Python 2.6+
 
 import socket
 import sys
-import time
 import traceback
 import urllib
 import urllib2
         """Creates the container for common functionality"""
 
         logger.debug('Welcome to %s v%s' % (APP_TITLE, __version__))
+        logger.debug('** Using class %s **' % (self.__class__.__name__,))
 
         try:
             self.port = int(port)
             return osx.Clip2ZeusOSX
         elif platform in ('linux', 'linux2'):
             import linux
-            return linux.Clip2ZeusLinux
+            return linux.determine_wm()
         else:
             raise UnsupportedPlatformError('%s is not currently supported!' % platform)
 

clip2zeus/linux.py

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-import pygtk
-pygtk.require('2.0')
-import gtk
-import time
+import os
 
-from clip2zeus.common import Clip2ZeusApp
+def determine_wm():
+    if 'kde' in os.environ.get('DESKTOP_SESSION', '').lower():
+        from linux_kde import Clip2ZeusKDE
+        return Clip2ZeusKDE
+    else:
+        from linux_gtk import Clip2ZeusGTK
+        return Clip2ZeusGTK
 
-class Clip2ZeusLinux(Clip2ZeusApp):
-
-    def check_clipboard(self):
-        """Checks the system clipboard for data"""
-
-        clipboard = gtk.clipboard_get()
-        return clipboard.wait_for_text()
-
-    def update_clipboard(self, text):
-        """Updates the system clipboard with the specified text"""
-
-        clipboard = gtk.clipboard_get()
-        clipboard.set_text(text)
-        clipboard.store()
-
-if __name__ == '__main__':
-    Clip2ZeusLinux()
-

clip2zeus/linux_gtk.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+from clip2zeus.common import Clip2ZeusApp
+
+class Clip2ZeusGTK(Clip2ZeusApp):
+
+    def check_clipboard(self):
+        """Checks the system clipboard for data"""
+
+        clipboard = gtk.clipboard_get()
+        return clipboard.wait_for_text()
+
+    def update_clipboard(self, text):
+        """Updates the system clipboard with the specified text"""
+
+        clipboard = gtk.clipboard_get()
+        clipboard.set_text(text)
+        clipboard.store()
+
+if __name__ == '__main__':
+    Clip2ZeusGTK().start()
+

clip2zeus/linux_kde.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import gobject
+gobject.threads_init()
+from dbus import glib
+glib.init_threads()
+import dbus
+
+from clip2zeus.common import Clip2ZeusApp
+
+class Clip2ZeusKDE(Clip2ZeusApp):
+
+    @property
+    def clipboard(self):
+        if not hasattr(self, '_clipboard'):
+            bus = dbus.SessionBus()
+            self._clipboard = bus.get_object('org.kde.klipper', '/klipper')
+
+        return self._clipboard
+
+    def check_clipboard(self):
+        """Checks the system clipboard for data"""
+
+        return str(self.clipboard.getClipboardContents())
+
+    def update_clipboard(self, text):
+        """Updates the system clipboard with the specified text"""
+
+        self.clipboard.setClipboardContents(text)
+
+if __name__ == '__main__':
+    Clip2ZeusKDE().start()
+