1. Henning Schröder
  2. pyqtwidgets

Commits

Henning Schröder  committed b336cf2

pep8

  • Participants
  • Parent commits feed439
  • Branches default

Comments (0)

Files changed (39)

File qtwidgets/application.py

View file
  • Ignore whitespace
 
     timeout = 1000
 
-
     class Error(Exception):
         pass
 
-
     def __init__(self, channel=None, parent=None):
         QObject.__init__(self, parent)
-        self.socket_filename = os.path.expanduser("~/.ipc_%s" % self.generate_unique_id(channel))
+        self.socket_filename = os.path.expanduser(
+            "~/.ipc_%s" % self.generate_unique_id(channel))
         print self.socket_filename
         self.shared_mem = QSharedMemory()
         self.shared_mem.setKey(self.socket_filename)
             self.is_running = True
         else:
             self.is_running = False
-            
 
     def generate_unique_id(self, channel=None):
         if channel is None:
             channel = os.path.basename(sys.argv[0])
 
         return "%s@%s" % (
-           channel,
-           os.environ.get("DISPLAY", "-1")
-           )
-
+            channel,
+            os.environ.get("DISPLAY", "-1")
+        )
 
 
 class IpcServer(IpcBase):
 
-
     def __init__(self, channel):
         IpcBase.__init__(self, channel)
         if self.is_running:
             return
         self.server = QLocalServer(self)
         self.connect(self.server, SIGNAL("newConnection()"),
-               self.receive_message)
+                     self.receive_message)
         if os.path.exists(self.socket_filename):
             os.remove(self.socket_filename)
         self.server.listen(self.socket_filename)
         atexit.register(self.cleanup)
 
-
     def cleanup(self):
         os.remove(self.socket_filename)
 
-            
     def receive_message(self):
         socket = self.server.nextPendingConnection()
         if not socket.waitForReadyRead(self.timeout):
         byte_array = socket.readAll()
         self.handle_new_message(pickle.loads(str(byte_array)))
 
-
     def handle_new_message(self, message):
         raise NotImplementedError, self.handle_new_message
 
 
-
 class IpcClient(IpcBase):
 
-
     def __init__(self, channel):
         IpcBase.__init__(self, channel)
         if not self.is_running:
-            raise self.Error("Client cannot connect to IPC server. Not running.")
-
+            raise self.Error(
+                "Client cannot connect to IPC server. Not running.")
 
     def send_message(self, message):
         if not self.is_running:
-            raise self.Error("Client cannot connect to IPC server. Not running.")
+            raise self.Error(
+                "Client cannot connect to IPC server. Not running.")
         socket = QLocalSocket(self)
         socket.connectToServer(self.socket_filename, QIODevice.WriteOnly)
         if not socket.waitForConnected(self.timeout):
         socket.disconnectFromServer()
 
 
-
-
-
-
 class Application(QApplication):
 
-    
     def __init__(self, argv=None, application_id=None):
         if argv is None:
             argv = sys.argv
             self.send_message = ipc.send_message
         except IpcClient.Error:
             ipc = self.ipc_server = IpcServer(application_id)
-            ipc.handle_new_message = self.handle_new_message 
+            ipc.handle_new_message = self.handle_new_message
         self.is_running = ipc.is_running
 
-
     def handle_new_message(self, message):
         print "Received:", message
 
-    
-           
+
 if __name__ == "__main__":
     app = Application()
     if app.is_running:

File qtwidgets/daemon.py

View file
  • Ignore whitespace
 # -*- coding: utf-8 -*-
 import sys
 import os
-from signal import SIGTERM 
+from signal import SIGTERM
 import time
 import atexit
 import socket
 import tempfile
 
 
-
 def default_pidfile():
     prog = sys.argv[0] ?
     app_name = os.path.basename(os.path.splitext(prog))[0]
 
 class FileLock(object):
 
-
     def __init__(self, filename):
         self.filename = filename
         self.fd = None
         self.pid = os.getpid()
 
-
     def acquire(self):
         try:
-            self.fd = os.open(self.filename, os.O_CREAT|os.O_EXCL|os.O_RDWR)
+            self.fd = os.open(
+                self.filename, os.O_CREAT | os.O_EXCL | os.O_RDWR)
             os.write(self.fd, self.get_write_data())
-            return 1    
+            return 1
         except OSError:
             self.fd = None
             return 0
 
-
     def get_write_data(self):
         return "%d" % self.pid
 
-        
     def release(self):
         if not self.fd:
             return 0
         except OSError:
             return 0
 
-
     def __del__(self):
         self.release()
 
 
-
-
 class Daemon(object):
 
-
     def __init__(self, pidfile=None, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
         if pidfile is None:
-            prog = __main__.__file__ # sys.argv[0] ?
+            prog = __main__.__file__  # sys.argv[0] ?
             app_name = os.path.basename(os.path.splitext(prog))[0]
             pidfile = os.path.expanduser("~/.%s.pid" % app_name)
         self.stdin = stdin
         self.stdout = stdout
         self.stderr = stderr
         self.pidfile = os.path.abspath(os.path.expanduser(pidfile))
-        
 
     def daemonize(self):
         """
         Programming in the UNIX Environment" for details (ISBN 0201563177)
         http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
         """
-        try: 
-            pid = os.fork() 
+        try:
+            pid = os.fork()
             if pid > 0:
                 # exit first parent
-                sys.exit(0) 
-        except OSError, e: 
-            sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
+                sys.exit(0)
+        except OSError, e:
+            sys.stderr.write(
+                "fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
             sys.exit(1)
-    
+
         # decouple from parent environment
-        os.chdir("/") 
-        os.setsid() 
-        os.umask(0) 
-    
+        os.chdir("/")
+        os.setsid()
+        os.umask(0)
+
         # do second fork
-        try: 
-            pid = os.fork() 
+        try:
+            pid = os.fork()
             if pid > 0:
                 # exit from second parent
-                sys.exit(0) 
-        except OSError, e: 
-            sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
-            sys.exit(1) 
-    
+                sys.exit(0)
+        except OSError, e:
+            sys.stderr.write(
+                "fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
+            sys.exit(1)
+
         # redirect standard file descriptors
         sys.stdout.flush()
         sys.stderr.flush()
         os.dup2(si.fileno(), sys.stdin.fileno())
         os.dup2(so.fileno(), sys.stdout.fileno())
         os.dup2(se.fileno(), sys.stderr.fileno())
-    
+
         # write pidfile
         self.lock = FileLock(self.pidfile)
         self.lock.acquire()
         atexit.register(self.lock.release)
 
-
-
     def check(self):
         self.lock = FileLock(self.pidfile)
         if self.lock.acquire():
         else:
             return False
 
-
     def getpid(self):
         try:
-            pf = file(self.pidfile,'r')
+            pf = file(self.pidfile, 'r')
             pid = int(pf.read().strip())
             pf.close()
         except IOError:
             pid = None
         return pid
 
-
     def start(self):
         # Check for a pidfile to see if the daemon already runs
         if self.check():
         self.daemonize()
         self.run()
 
-
     def stop(self):
         # Get the pid from the pidfile
         try:
-            pf = file(self.pidfile,'r')
+            pf = file(self.pidfile, 'r')
             pid = int(pf.read().strip())
             pf.close()
         except IOError:
             pid = None
-    
+
         if not pid:
             message = "pidfile %s does not exist. Daemon not running?\n"
             sys.stderr.write(message % self.pidfile)
-            return # not an error in a restart
+            return  # not an error in a restart
 
-        # Try killing the daemon process    
+        # Try killing the daemon process
         try:
             while 1:
                 os.kill(pid, SIGTERM)
                 print str(err)
                 sys.exit(1)
 
-
     def restart(self):
         self.stop()
         self.start()
 
-        
     def run(self):
         raise NotImplementedError, self.run
-
-
-    
-

File qtwidgets/dockwidget.py

View file
  • Ignore whitespace
     return dockwidget.features() & feature == feature
 
 
-
 class DockWidgetTitleBarButton(QAbstractButton):
 
-
     def __init__(self, titlebar):
         QAbstractButton.__init__(self, titlebar)
         self.setFocusPolicy(Qt.NoFocus)
 
-
     def sizeHint(self):
         self.ensurePolished()
-        margin = self.style().pixelMetric(QStyle.PM_DockWidgetTitleBarButtonMargin, None, self)
+        margin = self.style().pixelMetric(
+            QStyle.PM_DockWidgetTitleBarButtonMargin, None, self)
         if self.icon().isNull():
             return QSize(margin, margin)
-        iconSize = self.style().pixelMetric(QStyle.PM_SmallIconSize, None, self)
+        iconSize = self.style().pixelMetric(
+            QStyle.PM_SmallIconSize, None, self)
         pm = self.icon().pixmap(iconSize)
         return QSize(pm.width() + margin, pm.height() + margin)
 
-
     def enterEvent(self, event):
         if self.isEnabled():
             self.update()
         QAbstractButton.enterEvent(self, event)
 
-
     def leaveEvent(self, event):
         if self.isEnabled():
             self.update()
         QAbstractButton.leaveEvent(self, event)
 
-
-
     def paintEvent(self, event):
         p = QPainter(self)
         r = self.rect()
         self.style().drawComplexControl(QStyle.CC_ToolButton, opt, p, self)
 
 
-
-
 class DockWidgetTitleBar(QWidget):
     # XXX: support QDockWidget.DockWidgetVerticalTitleBar feature
 
-    
     def __init__(self, dockWidget):
         QWidget.__init__(self, dockWidget)
 
         import dockwidget_icons
 
-
         self.openIcon = QIcon(":arrow-down.png")
         self.closeIcon = QIcon(":arrow-right.png")
         self.pinIcon = QIcon(":pin.png")
         self.pinButton.setIcon(self.pinIcon)
         self.pinButton.setCheckable(True)
         self.pinButton.setChecked(True)
-        self.connect(self.pinButton, SIGNAL("clicked(bool)"), self.togglePinned)
+        self.connect(self.pinButton, SIGNAL(
+            "clicked(bool)"), self.togglePinned)
         self.pinButton.setVisible(True)
         #self.connect(dockWidget, SIGNAL("featuresChanged(QDockWidget.DockWidgetFeatures)"), self.featuresChanged)
         dockWidget.featuresChanged.connect(self.featuresChanged)
         self.featuresChanged(0)
 
-
     def minimumSizeHint(self):
         return self.sizeHint()
 
-
     def sizeHint(self):
         q = self.parentWidget()
         mw = q.style().pixelMetric(QStyle.PM_DockWidgetTitleMargin, None, q)
         pinSize = QSize(0, 0)
         if self.pinButton:
             pinSize = self.pinButton.sizeHint()
-        buttonHeight = max(max(closeSize.height(), floatSize.height()), 
-                            hideSize.height(), pinSize.height()) + 2
-        buttonWidth = closeSize.width() + floatSize.width() + hideSize.width() + pinSize.width()
+        buttonHeight = max(max(closeSize.height(), floatSize.height()),
+                           hideSize.height(), pinSize.height()) + 2
+        buttonWidth = closeSize.width() + floatSize.width(
+        ) + hideSize.width() + pinSize.width()
         titleFontMetrics = q.fontMetrics()
         fontHeight = titleFontMetrics.lineSpacing() + 2 * mw
         height = max(buttonHeight, fontHeight)
             width, height = height, width
         return QSize(width, height)
 
-
     def paintEvent(self, event):
         p = QStylePainter(self)
         q = self.parentWidget()
         if hasFeature(q, QDockWidget.DockWidgetVerticalTitleBar):
             fw = 1 or q.isFloating() and q.style().pixelMetric(
                 QStyle.PM_DockWidgetFrameWidth, None, q) or 0
-            mw = q.style().pixelMetric(QStyle.PM_DockWidgetTitleMargin, None, q)
+            mw = q.style().pixelMetric(
+                QStyle.PM_DockWidgetTitleMargin, None, q)
             titleOpt = QStyleOptionDockWidgetV2()
             titleOpt.initFrom(q)
             titleOpt.verticalTitleBar = True
             titleOpt.rect = QRect(
-                QPoint(fw, fw + mw + \
-                       self.collapseButton.size().height() + self.pinButton.size().height()),
+                QPoint(fw, fw + mw +
+                       self.collapseButton.size(
+                       ).height() + self.pinButton.size().height()),
                 QSize(
-                   self.geometry().width() - (fw * 2),
-                   self.geometry().height() - (fw * 2) - \
-                   mw - self.collapseButton.size().height() - self.pinButton.size().height()))
+                    self.geometry().width() - (fw * 2),
+                    self.geometry().height() - (fw * 2) -
+                    mw - self.collapseButton.size().height() - self.pinButton.size().height()))
             titleOpt.title = q.windowTitle()
             titleOpt.closable = hasFeature(q, QDockWidget.DockWidgetClosable)
             titleOpt.floatable = hasFeature(q, QDockWidget.DockWidgetFloatable)
         else:
             fw = q.isFloating() and q.style().pixelMetric(
                 QStyle.PM_DockWidgetFrameWidth, None, q) or 0
-            mw = q.style().pixelMetric(QStyle.PM_DockWidgetTitleMargin, None, q)
+            mw = q.style().pixelMetric(
+                QStyle.PM_DockWidgetTitleMargin, None, q)
             titleOpt = QStyleOptionDockWidgetV2()
             titleOpt.initFrom(q)
             titleOpt.rect = QRect(
-                QPoint(fw + mw + \
-                       self.collapseButton.size().width() + self.pinButton.size().width(), fw),
+                QPoint(fw + mw +
+                       self.collapseButton.size(
+                       ).width() + self.pinButton.size().width(), fw),
                 QSize(
-                   self.geometry().width() - (fw * 2) - \
-                   mw - self.collapseButton.size().width() - self.pinButton.size().width(),
-                   self.geometry().height() - (fw * 2)))
+                    self.geometry().width() - (fw * 2) -
+                    mw -
+                    self.collapseButton.size().width(
+                    ) - self.pinButton.size().width(),
+                    self.geometry().height() - (fw * 2)))
             titleOpt.title = q.windowTitle()
             titleOpt.closable = hasFeature(q, QDockWidget.DockWidgetClosable)
             titleOpt.floatable = hasFeature(q, QDockWidget.DockWidgetFloatable)
             p.drawControl(QStyle.CE_DockWidgetTitle, titleOpt)
 
-
     def resizeEvent(self, event):
         q = self.parentWidget()
         if hasFeature(q, QDockWidget.DockWidgetVerticalTitleBar):
             opt.initFrom(q)
             opt.verticalTitleBar = True
             opt.rect = QRect(
-                QPoint(fh, 40), #self.geometry().height() - (fh * 3)),
+                QPoint(fh, 40),  # self.geometry().height() - (fh * 3)),
                 QSize(
-                  self.geometry().width() - (fh * 2),
-                  fh * 2))
+                    self.geometry().width() - (fh * 2),
+                    fh * 2))
             opt.title = q.windowTitle()
             opt.closable = hasFeature(q, QDockWidget.DockWidgetClosable)
             opt.floatable = hasFeature(q, QDockWidget.DockWidgetFloatable)
                 size = self.floatButton.size()
             collapseRect = QRect(QPoint(top, fh), size)
             self.collapseButton.setGeometry(collapseRect)
-            pinRect = QRect(QPoint(top, fh+collapseRect.height()+1), size)
+            pinRect = QRect(QPoint(top, fh + collapseRect.height() + 1), size)
             self.pinButton.setGeometry(pinRect)
         else:
             fw = q.isFloating() and q.style().pixelMetric(
             opt.rect = QRect(
                 QPoint(fw, fw),
                 QSize(
-                  self.geometry().width() - (fw * 2),
-                  self.geometry().height() - (fw * 2)))
+                    self.geometry().width() - (fw * 2),
+                    self.geometry().height() - (fw * 2)))
             opt.title = q.windowTitle()
             opt.closable = hasFeature(q, QDockWidget.DockWidgetClosable)
             opt.floatable = hasFeature(q, QDockWidget.DockWidgetFloatable)
             pinRect = QRect(QPoint(fw + collapseRect.width() + 1, top), size)
             self.pinButton.setGeometry(pinRect)
 
-
     def setCollapsed(self, collapsed):
         q = self.parentWidget()
         if q and q.widget() and q.widget().isHidden() != collapsed:
             self.toggleCollapsed()
 
-
     def toggleFloating(self):
         q = self.parentWidget()
         q.setFloating(not q.isFloating())
 
-
     def toggleCollapsed(self):
         q = self.parentWidget()
         if not q:
         q.toggleCollapsed()
         self.setCollapsedIcon(q.isCollapsed())
 
-
     def setCollapsedIcon(self, flag):
         self.collapseButton.setIcon(flag and self.openIcon or self.closeIcon)
 
-
     def togglePinned(self, checked):
         self.parent().setPinned(checked)
 
-
     def featuresChanged(self, features):
         q = self.parentWidget()
-        self.closeButton.setVisible(hasFeature(q, QDockWidget.DockWidgetClosable))
-        self.floatButton.setVisible(hasFeature(q, QDockWidget.DockWidgetFloatable))
+        self.closeButton.setVisible(
+            hasFeature(q, QDockWidget.DockWidgetClosable))
+        self.floatButton.setVisible(
+            hasFeature(q, QDockWidget.DockWidgetFloatable))
         # self.resizeEvent(None)
 
 
-
 class DockMainWidgetWrapper(QWidget):
 
-
     def __init__(self, dockwidget):
         QWidget.__init__(self, dockwidget)
         self.widget = None
         self.hlayout.setContentsMargins(0, 0, 0, 0)
         self.setLayout(self.hlayout)
 
-
     def setWidget(self, widget):
         self.widget = widget
         self.widget_height = widget.height
         self.layout().addWidget(widget)
 
-
     def isCollapsed(self):
         return self.widget.isVisible()
- 
 
     def setCollapsed(self, flag):
         if not flag:
             self.layout().removeWidget(self.widget)
             self.widget.hide()
             if hasFeature(self.parent(), QDockWidget.DockWidgetVerticalTitleBar):
-                self.parent().setMaximumWidth(self.parent().width() - self.width())
+                self.parent().setMaximumWidth(
+                    self.parent().width() - self.width())
             else:
-                self.parent().setMaximumHeight(self.parent().height() - self.height())
+                self.parent().setMaximumHeight(
+                    self.parent().height() - self.height())
         else:
             self.setFixedSize(self.old_size)
             self.parent().setMinimumSize(QSize(1, 1))
             self.widget.show()
             self.layout().addWidget(self.widget)
             self.setMinimumSize(QSize(1, 1))
-            self.setMaximumSize(QSize(32768, 32768)) 
-
+            self.setMaximumSize(QSize(32768, 32768))
 
 
 class DockWidget(QDockWidget):
 
-
     def __init__(self, *args):
         QDockWidget.__init__(self, *args)
         self.titleBar = DockWidgetTitleBar(self)
         self.pinned = True
         self.shot = False
 
-
     def enterEvent(self, event):
         self.entered = True
         if not self.shot and not self.isPinned() and not self.isFloating():
             QTimer.singleShot(500, self.autoshow)
         return QDockWidget.enterEvent(self, event)
 
-
     def leaveEvent(self, event):
         self.entered = False
         if not self.shot and not self.isPinned() and not self.isFloating():
             QTimer.singleShot(1000, self.autohide)
         return QDockWidget.leaveEvent(self, event)
 
-    
     def autohide(self):
         self.shot = False
-        if not self.entered: 
+        if not self.entered:
             self.setCollapsed(False)
 
-
     def autoshow(self):
         self.shot = False
         if self.entered:
             self.setCollapsed(True)
 
-
     def isPinned(self):
         return self.pinned
 
-
     def setPinned(self, flag):
         self.pinned = flag
 
-
     def setWidget(self, widget):
         self.mainWidget = DockMainWidgetWrapper(self)
         self.mainWidget.setWidget(widget)
         QDockWidget.setWidget(self, self.mainWidget)
-    
 
     def setCollapsed(self, flag):
         self.mainWidget.setCollapsed(flag)
         self.titleBarWidget().setCollapsedIcon(flag)
 
-
     def isCollapsed(self):
         return self.mainWidget.isCollapsed()
 
-
     def toggleCollapsed(self):
         self.setCollapsed(not self.isCollapsed())
-

File qtwidgets/dockwidget_icons.py

View file
  • Ignore whitespace
 \x00\x00\x00\x36\x00\x00\x00\x00\x00\x01\x00\x00\x04\x81\
 "
 
+
 def qInitResources():
-    QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+    QtCore.qRegisterResourceData(
+        0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+
 
 def qCleanupResources():
-    QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+    QtCore.qUnregisterResourceData(
+        0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
 
 qInitResources()

File qtwidgets/downloadialog.py

View file
  • Ignore whitespace
 from PyQt4.QtNetwork import *
 
 
-
 class DownloadDialog(QProgressDialog):
 
-
     def __init__(self, parent=None):
-        QProgressDialog.__init__(self, 
-                                 "Download", 
-                                 "Cancel", 
+        QProgressDialog.__init__(self,
+                                 "Download",
+                                 "Cancel",
                                  0,
                                  100,
                                  parent)
         self.setWindowModality(Qt.WindowModal)
         self.http = QHttp()
-        self.connect(self.http, 
+        self.connect(self.http,
                      SIGNAL("dataReadProgress(int,int)"),
                      self.onDataRead)
         self.connect(self.http,
                      self.onDone)
         self.connect(self, SIGNAL("canceled()"), self.http.abort)
 
-    
     def onDataRead(self, done, total):
         if total == 0:
             self.setValue(50)
         else:
             self.setValue(done / total)
 
-    
     def onDone(self, error):
         if error:
             self.error = self.http.errorString()
         self.setValue(100)
-        #self.close()
-
+        # self.close()
 
     def download(self, url, label=None):
         self.error = None
         qApp.processEvents()
         self.http.get(url.path())
 
-
-
     @classmethod
     def get(cls, url, label=None):
         dlg = cls()
 
 def download(url, label=None):
     return DownloadDialog.get(url, label)
-
-
-    

File qtwidgets/eclipsedocks.py

View file
  • Ignore whitespace
 
 class TitleTab(QTabBar):
 
-
     def __init__(self, parent):
         QTabBar.__init__(self, parent)
         font = self.font()
         pt = font.pointSize() * 0.75
         font.setPointSize(pt)
         self.setFont(font)
-        #self.setShape(QTabBar.TriangularNorth)
+        # self.setShape(QTabBar.TriangularNorth)
         self.setProperty("documentMode", QVariant(True))
         self.setProperty("tabsClosable", QVariant(True))
         #self.setProperty("movable", QVariant(True))
 
-
     def mousePressEvent(self, event):
         QTabBar.mousePressEvent(self, event)
         if not (event.buttons() & Qt.LeftButton):
         self.detached = False
         self.parent().mousePressEvent(event)
 
-
     def mouseReleaseEvent(self, event):
         QTabBar.mouseReleaseEvent(self, event)
         self.parent().mouseReleaseEvent(event)
 
-
     def mouseMoveEvent(self, event):
         QTabBar.mouseMoveEvent(self, event)
         if not (event.buttons() & Qt.LeftButton):
             self.parent().mouseMoveEvent(event)
 
 
-
 class TitleButton(QToolButton):
 
-
     def __init__(self, parent, icon_name, callback):
         QToolButton.__init__(self, parent)
         self.setFixedSize(16, 16)
         self.connect(self, SIGNAL("clicked()"), callback)
 
 
-
 class TitleBarWidget(QWidget):
 
-
     def __init__(self, parent):
         QWidget.__init__(self, parent)
 
         import eclipsedocks_icons
 
-
         self.setObjectName("titlebar")
         self._hblayout = QHBoxLayout(self)
         self._tab = TitleTab(self)
         self.layout().setMargin(1)
         self.layout().setSpacing(0)
         self.layout().addWidget(self._tab)
-        #self.layout().addStretch()
+        # self.layout().addStretch()
         self.layout().addWidget(self._pinButton)
         self.layout().addWidget(self._minimizeButton)
         self.layout().addWidget(self._maximizeButton)
 
-
     def paintEvent(self, event):
         painter = QPainter(self)
         painter.fillRect(event.rect(), QBrush(QColor("#1010ff")))
         QWidget.paintEvent(self, event)
 
-        
 
 class DockWidgetContainer(QDockWidget):
 
-
     def __init__(self, parent=None):
         QDockWidget.__init__(self, parent)
-        self.setContentsMargins(0,0,0,0)
+        self.setContentsMargins(0, 0, 0, 0)
         self.layout().setMargin(0)
         self.layout().setSpacing(0)
         self._orig_title_bar = self.titleBarWidget()
             self, SIGNAL("dockLocationChanged(Qt::DockWidgetArea)"),
             self.on_area_changed)
 
-            
-    def close_tab(self, idx):        
+    def close_tab(self, idx):
         widget = self._widgets[idx]
         self._stack.removeWidget(widget)
         self._tab.removeTab(idx)
         if not self._widgets:
             self.parent().removeDockWidget(self)
 
-
     def minimumSizeHint(self):
         return self._title_bar.sizeHint()
 
-
     def on_tab_changed(self, idx):
         self._stack.setCurrentIndex(idx)
-        #self.setWindowTitle(self._widgets[idx].windowTitle())
-
+        # self.setWindowTitle(self._widgets[idx].windowTitle())
 
     def add_widget(self, widget):
         widget.setParent(self._stack)
         self._tab.addTab(widget.windowTitle())
         widget.show()
 
-
     def detach(self):
         sel = self._tab.currentIndex()
         count = self._tab.count()
         if count == 1:
             return
-        
+
         dock = self.__class__(self.parent())
         self.parent().addDockWidget(self.area, dock)
         dock.show()
 
-
         for i in range(count - 1, -1, -1):
             if i == sel:
                 continue
             dock.add_widget(widget)
         self._docks.append(dock)
 
-
     def on_area_changed(self, area):
         self.area = area
 
-
     def test_tabify(self, flag):
         tabbed_docks = self.parent().tabifiedDockWidgets(self)
         if not len(tabbed_docks):
                 self.add_widget(widget)
             self.parent().removeDockWidget(dock)
 
-
     def toggle_autohide(self):
         state = self.sender().isChecked()
         self.pinned = state
 
-
     def toggle_minimize(self):
         state = self.sender().isChecked()
         self.setCollapsed(not state)
 
-
     def setCollapsed(self, state):
         self._stack.setVisible(state)
 
-
     def toggle_maximize(self):
         state = self.sender().isChecked()
         if state:
         else:
             self._stack.resize(self._stack.sizeHint())
 
-
     def enterEvent(self, event):
         self.entered = True
         if not self.shot and not self.pinned and not self.isFloating():
             QTimer.singleShot(500, self.autoshow)
         return QDockWidget.enterEvent(self, event)
 
-
     def leaveEvent(self, event):
         self.entered = False
         if not self.shot and not self.pinned and not self.isFloating():
             QTimer.singleShot(1000, self.autohide)
         return QDockWidget.leaveEvent(self, event)
 
-
     def autohide(self):
         self.shot = False
         if not self.entered:
             self.setCollapsed(False)
 
-
     def autoshow(self):
         self.shot = False
         if self.entered:
             self.setCollapsed(True)
 
 
-
-
-
-
-
 if __name__ == "__main__":
     import sys
     app = QApplication(sys.argv + ["-style", "plastique"])
     dock3.setWindowTitle(dock3.text())
     dock_container2.add_widget(dock3)
     win.addDockWidget(Qt.RightDockWidgetArea, dock_container2)
-    
+
     win.show()
     app.exec_()

File qtwidgets/eclipsedocks_icons.py

View file
  • Ignore whitespace
 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
 "
 
+
 def qInitResources():
-    QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+    QtCore.qRegisterResourceData(
+        0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+
 
 def qCleanupResources():
-    QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+    QtCore.qUnregisterResourceData(
+        0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
 
 qInitResources()

File qtwidgets/fader.py

View file
  • Ignore whitespace
         self.setAttribute(Qt.WA_DeleteOnClose)
         self.resize(parent.size())
 
-
     def start(self):
         self.currentAlpha = 255
         self.timer.start(33)
         self.show()
 
-
     def paintEvent(self, event):
         painter = QPainter(self)
-        
+
         semiTransparentColor = self.startColor
         semiTransparentColor.setAlpha(self.currentAlpha)
         painter.fillRect(self.rect(), semiTransparentColor)
             self.close()
 
 
-
 # From http://www.diotavelli.net/PyQtWiki/Fading%20Between%20Widgets
 class SwitchFader(QWidget):
 
         self.timeline.valueChanged.connect(self.animate)
         self.timeline.finished.connect(self.close)
         self.timeline.setDuration(333)
-        self.timeline.start()        
+        self.timeline.start()
         self.resize(new_widget.size())
         self.show()
 
-
-    def paintEvent(self, event):    
+    def paintEvent(self, event):
         painter = QPainter()
         painter.begin(self)
         painter.setOpacity(self.pixmap_opacity)
         painter.drawPixmap(0, 0, self.old_pixmap)
         painter.end()
-    
 
-    def animate(self, value):    
+    def animate(self, value):
         self.pixmap_opacity = 1.0 - value
         self.repaint()
-

File qtwidgets/fileedit.py

View file
  • Ignore whitespace
 from PyQt4.QtGui import QApplication, QWidget, QHBoxLayout, QLineEdit, QToolButton, QIcon, QFileDialog
 
 
+class FilenameEdit(QWidget):
 
+    filename_changed = pyqtSignal()
 
-class FilenameEdit(QWidget):
-	
-	filename_changed = pyqtSignal()
+    EDIT_EXISTING_FILENAME = object()
+    EDIT_NEW_FILENAME = object()
+    EDIT_EXISTING_DIRECTORY = object()
 
-	EDIT_EXISTING_FILENAME = object()
-	EDIT_NEW_FILENAME = object()
-	EDIT_EXISTING_DIRECTORY = object()
-	
-	
-	DEFAULT_CAPTION = {
-  	   EDIT_EXISTING_FILENAME: "Open File",
-	   EDIT_NEW_FILENAME: "Create File",
-	   EDIT_EXISTING_DIRECTORY: "Open Directory",
-	}
-	DEFAULT_PATTERN = {
-  	   EDIT_EXISTING_FILENAME: "All files (*)",
-  	   EDIT_NEW_FILENAME: "All files (*)",
-	   EDIT_EXISTING_DIRECTORY: ""
-	}
+    DEFAULT_CAPTION = {
+        EDIT_EXISTING_FILENAME: "Open File",
+        EDIT_NEW_FILENAME: "Create File",
+        EDIT_EXISTING_DIRECTORY: "Open Directory",
+    }
+    DEFAULT_PATTERN = {
+        EDIT_EXISTING_FILENAME: "All files (*)",
+        EDIT_NEW_FILENAME: "All files (*)",
+        EDIT_EXISTING_DIRECTORY: ""
+    }
 
-	
-	def __init__(self, parent=None, filename=None, caption=None, pattern=None, kind=None, **kwargs):
-		QWidget.__init__(self, parent, **kwargs)
-		if kind is None:
-			kind = self.EDIT_EXISTING_FILENAME
-		if caption is None:
-			caption = self.DEFAULT_CAPTION[kind]
-		self._caption = caption
-		if pattern is None:
-			pattern = self.DEFAULT_PATTERN[kind]
-		self._kind = kind
-		self._pattern = pattern
-		self._layout = QHBoxLayout(self)
-		self._lineedit = QLineEdit(self)
-		self._button = QToolButton(self)
-		if kind is self.EDIT_EXISTING_DIRECTORY:
-			icon = QIcon.fromTheme("document-open-folder")
-		else:
-			icon = QIcon.fromTheme("document-open")
-		self._button.setIcon(icon)
-		self._button.clicked.connect(self._on_button_clicked)
-		self.layout().setContentsMargins(0, 0, 0, 0)
-		self.layout().addWidget(self._lineedit)
-		self.layout().addWidget(self._button)
-		self.set_filename(filename or "")
-			
-		
-	def _on_button_clicked(self):
-		filename = unicode(self._lineedit.text())
-		if self._kind is self.EDIT_EXISTING_DIRECTORY:
-			path = filename
-			if not path:
-				path = os.getcwd()
-			filename = QFileDialog.getExistingDirectory(self, self._caption, path)
-		else:
-			if not filename:
-				path = os.getcwd()
-			else:
-				path = os.path.dirname(filename)
-			if self._kind is self.EDIT_NEW_FILENAME:
-				filename = QFileDialog.getSaveFileName(self, self._caption, path, self._pattern)
-			else:
-				assert self._kind is self.EDIT_EXISTING_FILENAME
-				filename = QFileDialog.getOpenFileName(self, self._caption, path, self._pattern)
+    def __init__(self, parent=None, filename=None, caption=None, pattern=None, kind=None, **kwargs):
+        QWidget.__init__(self, parent, **kwargs)
+        if kind is None:
+            kind = self.EDIT_EXISTING_FILENAME
+        if caption is None:
+            caption = self.DEFAULT_CAPTION[kind]
+        self._caption = caption
+        if pattern is None:
+            pattern = self.DEFAULT_PATTERN[kind]
+        self._kind = kind
+        self._pattern = pattern
+        self._layout = QHBoxLayout(self)
+        self._lineedit = QLineEdit(self)
+        self._button = QToolButton(self)
+        if kind is self.EDIT_EXISTING_DIRECTORY:
+            icon = QIcon.fromTheme("document-open-folder")
+        else:
+            icon = QIcon.fromTheme("document-open")
+        self._button.setIcon(icon)
+        self._button.clicked.connect(self._on_button_clicked)
+        self.layout().setContentsMargins(0, 0, 0, 0)
+        self.layout().addWidget(self._lineedit)
+        self.layout().addWidget(self._button)
+        self.set_filename(filename or "")
 
-		if filename:
-			self.set_filename(filename)
+    def _on_button_clicked(self):
+        filename = unicode(self._lineedit.text())
+        if self._kind is self.EDIT_EXISTING_DIRECTORY:
+            path = filename
+            if not path:
+                path = os.getcwd()
+            filename = QFileDialog.getExistingDirectory(
+                self, self._caption, path)
+        else:
+            if not filename:
+                path = os.getcwd()
+            else:
+                path = os.path.dirname(filename)
+            if self._kind is self.EDIT_NEW_FILENAME:
+                filename = QFileDialog.getSaveFileName(
+                    self, self._caption, path, self._pattern)
+            else:
+                assert self._kind is self.EDIT_EXISTING_FILENAME
+                filename = QFileDialog.getOpenFileName(
+                    self, self._caption, path, self._pattern)
 
+        if filename:
+            self.set_filename(filename)
 
-	def filename(self):
-		return unicode(self._lineedit.text()) or None
-	
-	
-	def set_filename(self, value):
-		self._lineedit.setText(value)
-		self.filename_changed.emit()
+    def filename(self):
+        return unicode(self._lineedit.text()) or None
+
+    def set_filename(self, value):
+        self._lineedit.setText(value)
+        self.filename_changed.emit()
 
 
 class FileOpenEdit(FilenameEdit):
-	
-	def __init__(self, parent=None, filename=None, caption=None, pattern=None, **kwargs):
-		FilenameEdit.__init__(self, parent, filename, caption, pattern, self.EDIT_EXISTING_FILENAME, **kwargs)
 
-		
+    def __init__(self, parent=None, filename=None, caption=None, pattern=None, **kwargs):
+        FilenameEdit.__init__(
+            self, parent, filename, caption, pattern, self.EDIT_EXISTING_FILENAME, **kwargs)
+
+
 class DirectoryEdit(FilenameEdit):
-	
-	def __init__(self, parent=None, filename=None, caption=None, **kwargs):
-		FilenameEdit.__init__(self, parent, filename, caption, None, self.EDIT_EXISTING_DIRECTORY, **kwargs)
 
-		
-	def set_directory(self, path):
-		self.set_filename(path)
-		
-		
-	def directory(self):
-		return self.filename()
+    def __init__(self, parent=None, filename=None, caption=None, **kwargs):
+        FilenameEdit.__init__(
+            self, parent, filename, caption, None, self.EDIT_EXISTING_DIRECTORY, **kwargs)
 
-		
+    def set_directory(self, path):
+        self.set_filename(path)
+
+    def directory(self):
+        return self.filename()
+
+
 if __name__ == "__main__":
-	app = QApplication([])
-	win = DirectoryEdit(None, "/etc/")
-	win.resize(400, 200)
-	win.show()
-	app.exec_()
-	print win.filename()
+    app = QApplication([])
+    win = DirectoryEdit(None, "/etc/")
+    win.resize(400, 200)
+    win.show()
+    app.exec_()
+    print win.filename()

File qtwidgets/findwidget.py

View file
  • Ignore whitespace
         self.setChecked(checked)
 
 
-
 class FindButton(QToolButton):
 
-
     def __init__(self, parent, label, icon, callback):
         QToolButton.__init__(self, parent)
         self.setAutoRaise(True)
         if icon:
             self.setIcon(QIcon(QPixmap(icon)))
-            self.setIconSize(QSize(16,16))
+            self.setIconSize(QSize(16, 16))
         if label:
             self.setText(label)
             self.setToolTip(label)
             self.set_label_visible(True)
         self.connect(self, SIGNAL("clicked()"), callback)
 
-
     def set_label_visible(self, flag=True):
         if flag:
             self.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
             self.setToolButtonStyle(Qt.ToolButtonIconOnly)
 
 
-
 class FindDirection(object):
     Forward = 1
     Backward = 2
 
 class FindWidget(QWidget):
 
-
     def __init__(self, parent, textedit=None,
                  direction=FindDirection.Forward, use_menu=False):
         QWidget.__init__(self, parent)
-        self.setContentsMargins(1,1,1,1)
+        self.setContentsMargins(1, 1, 1, 1)
         # Import on first use
         import qtwidgets.findwidget_icons
         from qtwidgets.flowlayout import FlowLayout
         self.layout().addWidget(self.close_button)
 
         self.spacer = QWidget(self)
-        self.spacer.setFixedSize(QSize(8,8))
+        self.spacer.setFixedSize(QSize(8, 8))
         self.layout().addWidget(self.spacer)
-        
+
         self.find_label = QLabel(i18n("&Find:"), self)
         self.layout().addWidget(self.find_label)
 
 
         else:
             self.text = QLineEdit(self)
-    
+
         self.text_pal = QPalette(self.text.palette())
         self.connect(self.text,
                      SIGNAL("textChanged(const QString&)"), self.search_inc)
             self, i18n("For&ward"), ":go-next.png", self.search_forward)
         self.layout().addWidget(self.forward_button)
 
-
         if use_menu:
             self.menu = QMenu("Options")
             self.inc = CheckAction(self.menu, i18n("&Incremental"), True)
         self.buttons = [self.close_button, self.forward_button,
                         self.backward_button]
 
-
     def search_inc(self, text):
 
         if not self.inc.isChecked():
             return
-    
+
         cursor = self.textedit.textCursor()
         if cursor.hasSelection():
             cursor.setPosition(
             self.textedit.setTextCursor(cursor)
         self.search_next()
 
-
     def search_forward(self):
         self.direction = FindDirection.Forward
         return self.search_next()
 
-
     def search_backward(self):
         self.direction = FindDirection.Backward
         return self.search_next()
 
-
     def search_next(self, *args):
         # XXX: look into qt/tools/assistant/tabbedbrowser.cpp:find
         options = QTextDocument.FindFlags()
         self.update()
         return result
 
-
     def resizeEvent(self, event):
         width = self.width()
         delta = event.size().width() - event.oldSize().width()
         return QWidget.resizeEvent(self, event)
 
 
-
-
 class ReplaceWidget(FindWidget):
 
     def __init__(self, parent, textedit=None,
         FindWidget.__init__(self, parent, textedit, direction, use_menu)
 
         self.spacer2 = QWidget(self)
-        self.spacer2.setFixedSize(QSize(24,8))
+        self.spacer2.setFixedSize(QSize(24, 8))
         self.layout().addWidget(self.spacer2)
-        
+
         self.replace_label = QLabel(i18n("&Replace with:"), self)
         self.layout().addWidget(self.replace_label)
         self.new_text = QLineEdit(self)
-        self.connect(self.new_text, SIGNAL("returnPressed()"), self.replace_next)
+        self.connect(self.new_text, SIGNAL(
+            "returnPressed()"), self.replace_next)
         self.layout().addWidget(self.new_text)
         self.replace_label.setBuddy(self.new_text)
 
             self.replace_backward_button, self.replace_forward_button,
             self.replace_all_button])
 
-
     def replace_backward(self):
         self.direction = FindDirection.Backward
         self.replace_next()
 
-
     def replace_forward(self):
         self.direction = FindDirection.Forward
         self.replace_next()
 
-
     def replace_all(self):
         # XXX start at top?
         while True:
             if not self.replace_next():
                 break
 
-
     def replace_next(self):
         cursor = self.textedit.textCursor()
         if cursor.hasSelection():
             cursor.setPosition(
                 cursor.selectionStart(), QTextCursor.MoveAnchor)
             self.textedit.setTextCursor(cursor)
-        
+
         result = self.search_next()
         if result:
             cursor = self.textedit.textCursor()

File qtwidgets/findwidget_icons.py

View file
  • Ignore whitespace
 \x00\x00\x00\x26\x00\x00\x00\x00\x00\x01\x00\x00\x08\x29\
 "
 
+
 def qInitResources():
-    QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+    QtCore.qRegisterResourceData(
+        0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+
 
 def qCleanupResources():
-    QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+    QtCore.qUnregisterResourceData(
+        0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
 
 qInitResources()

File qtwidgets/flowlayout.py

View file
  • Ignore whitespace
 from PyQt4.QtGui import *
 
 
+# Qt example layout
+class FlowLayout(QLayout):
 
-# Qt example layout
-    
-class FlowLayout(QLayout):
     def __init__(self, parent=None, margin=0, spacing=-1):
         QLayout.__init__(self, parent)
         if parent is not None:
         self.setSpacing(spacing)
         self.itemList = []
 
-
     def calc_full_width(self):
         w = 0
         for item in self.itemList:
             w += item.sizeHint().width()
         return w
 
-
-
     def addItem(self, item):
         self.itemList.append(item)
 
-
     def count(self):
         return len(self.itemList)
 
-
     def itemAt(self, index):
         if index >= 0 and index < len(self.itemList):
             return self.itemList[index]
 
-
     def takeAt(self, index):
         if index >= 0 and index < len(self.itemList):
             return self.itemList.pop(index)
 
-
     def expandingDirections(self):
         return Qt.Orientations(Qt.Orientation(0))
 
-
     def hasHeightForWidth(self):
         return True
 
-
     def heightForWidth(self, width):
         height = self.doLayout(QRect(0, 0, width, 0), True)
         return height
 
-
     def setGeometry(self, rect):
         QLayout.setGeometry(self, rect)
         self.doLayout(rect, False)
 
-
     def sizeHint(self):
         return self.minimumSize()
 
-
     def minimumSize(self):
         size = QSize()
         for item in self.itemList:
         size += QSize(2 * self.margin(), 2 * self.margin())
         return size
 
-
     def doLayout(self, rect, testOnly):
         x = rect.x()
         y = rect.y()
             x = nextX
             lineHeight = max(lineHeight, item.sizeHint().height())
         return y + lineHeight - rect.y()
-
-
-
-
-
-

File qtwidgets/freedesktop.py

View file
  • Ignore whitespace
     except ImportError:
         ElementTree = None
 
-        
+
 __all__ = [
-   "Fallback", "Kde", "Gnome", "DesktopEnvironment", "detect_environment", "find_icon",
+    "Fallback", "Kde", "Gnome", "DesktopEnvironment", "detect_environment", "find_icon",
 ]
 
 _exists = {}
 
+
 def path_exists(name):
     try:
         flag = _exists[name]
 
 
 class DesktopEnvironment(object):
-    
+
     def __new__(cls, *args):
         # Singleton
         if not '_instance' in cls.__dict__:
             cls._instance[(args,)] = instance
         return instance
 
-
     def __init__(self, application_name=None):
         main_filename = abs_path(__main__.__file__)
         application_prefix = dir_name(main_filename)
 
         self.icon_theme_search_path = [
             "/usr/share/icons",
-            "/usr/local/share/icons",        
+            "/usr/local/share/icons",
             expand_user(path_join("~", ".local", "share", "icons")),
         ]
-            
+
         self.icon_search_path = [
-            path_join(application_prefix, "share", "apps", self.application_name, "icons"),
+            path_join(application_prefix, "share",
+                      "apps", self.application_name, "icons"),
             path_join(application_prefix, "icons"),
             path_join(application_prefix, "share", "icons"),
-            expand_user(path_join("~", ".local", "share", "apps", self.application_name, "icons")),
+            expand_user(
+                path_join(
+                    "~", ".local", "share", "apps", self.application_name, "icons")),
             expand_user(path_join("~", "." + self.application_name, "icons")),
-            expand_user(path_join("~", "." + self.application_name, "share", "icons")),
-            expand_user(path_join(os.sep, "usr", "local", "share", "apps", self.application_name, "icons")),
+            expand_user(
+                path_join("~", "." + self.application_name, "share", "icons")),
+            expand_user(
+                path_join(
+                    os.sep, "usr", "local", "share", "apps", self.application_name, "icons")),
         ]
         self.icons = []
         self.init()
 
-
         # Find theme
         found = []
         current_icon_theme = self.current_icon_theme()
             found.append(path)
         self.icon_search_path = found
 
-        
     def read_icon_theme(self, theme_name):
         for path in self.icon_theme_search_path:
             theme_path = path_join(path, theme_name)
                 inherits = None
             return theme_path, inherits
 
-
     def init(self):
         pass
 
-    
     def find(self, name, size=None):
         if not name.endswith(".png"):
             name += ".png"
             if path_exists(filename):
                 return filename
 
-
     def find_action(self, name, size="32x32"):
         return self.find(path_join("actions", name), size)
 
 
-        
 class Kde(DesktopEnvironment):
 
-
     def init(self):
         self.ini_files = {}
         self.default_icon_theme = "default.kde"
             self.icon_theme_search_path.insert(
                 0, os.path.join(self.kdehome, "share", "icons"))
         else:
-            self.icon_theme_search_path.insert(0, os.path.expanduser("~/.kde4/share/icons"))
-            self.icon_theme_search_path.insert(0, os.path.expanduser("~/.kde3/share/icons"))
-            self.icon_theme_search_path.insert(0, os.path.expanduser("~/.kde/share/icons"))
-
+            self.icon_theme_search_path.insert(
+                0, os.path.expanduser("~/.kde4/share/icons"))
+            self.icon_theme_search_path.insert(
+                0, os.path.expanduser("~/.kde3/share/icons"))
+            self.icon_theme_search_path.insert(
+                0, os.path.expanduser("~/.kde/share/icons"))
 
     def kdeini(self, name, section, key, default=None):
         filename = os.path.join(
         except Exception:
             return default
 
-    
     def kdeglobals(self, section, key, default=None):
         return self.kdeini("kdeglobals", section, key, default)
 
-
     def current_icon_theme(self):
         return self.kdeglobals("Icons", "Theme", self.default_icon_theme)
 
 
-
 class Gnome(DesktopEnvironment):
 
-    
     def init(self):
         self.etrees = {}
         self.default_icon_theme = "gnome"
 
-
     def gconf(self, name, key, default=None):
         filename = expand_user(
             "~/.gconf/desktop/gnome/%s/%%gconf.xml" % name)
                 pass
         return default
 
-
     def current_icon_theme(self):
         return self.gconf("interface", "icon_theme", self.default_icon_theme)
 
 
-
-
 class Fallback(DesktopEnvironment):
 
-
     def current_icon_theme(self):
         return ""
 
 
-
-
-
 def detect_environment():
     if get_env("KDE_FULL_SESSION", None):
         env = Kde()
     elif get_env("DESKTOP_SESSION") == "gnome" and \
-        get_env("GNOME_DESKTOP_SESSION_ID"):
+            get_env("GNOME_DESKTOP_SESSION_ID"):
         env = Gnome()
     else:
         env = Fallback()
     return env
 
 
-
-find_icon = detect_environment().find
+find_icon = detect_environment().find

File qtwidgets/graphicseditor.py

View file
  • Ignore whitespace
 from PyQt4.QtGui import *
 
 
-
 class GraphicsView(QGraphicsView):
 
-
     def __init__(self, parent=None):
         QGraphicsView.__init__(self, parent)
-        self.setDragMode(QGraphicsView.ScrollHandDrag) #QGraphicsView.RubberBandDrag)
+        #QGraphicsView.RubberBandDrag)
+        self.setDragMode(QGraphicsView.ScrollHandDrag)
         self.setCacheMode(QGraphicsView.CacheBackground)
         self.setInteractive(True)
         self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
         self.setResizeAnchor(QGraphicsView.AnchorViewCenter)
-        self.setAlignment(Qt.AlignLeft|Qt.AlignTop)
+        self.setAlignment(Qt.AlignLeft | Qt.AlignTop)
         self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
         self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
 
         self.setRenderHint(QPainter.Antialiasing)
         self.setRenderHint(QPainter.TextAntialiasing)
 
-
     def wheelEvent(self, event):
         factor = 1.41 ** (-event.delta() / 240.0)
         self.scale(factor, factor)
 
-
     def center(self):
-        self.centerOn(self.width() /2, self.height() /2)
-
+        self.centerOn(self.width() / 2, self.height() / 2)
 
     def zoo_in(self):
         self.scale(1.25, 1.25)
 
-
     def zoom_out(self):
         self.scale(0.8, 0.8)
 
-
     def zoom(self, factor):
         self.resetMatrix()
         self.scale(factor, factor)
 
-
     def zoom_factor(self):
         return self.matrix().m11()
 
 
-
 class GraphicsScene(QGraphicsScene):
 
-
     def __init__(self, parent=None):
         QGraphicsScene.__init__(self, parent)
 
-
     def delete_selected(self):
         for item in self.scene.selectedItems():
             self.scene.removeItem(item)
 
-
     def bring_to_front(self):
         if scene.selectedItems().isEmpty():
             return
         zValue = 0
         for item in overlapItems:
             if (item.zValue() >= zValue and
-                isinstance(item, DiagramItem)):
+                    isinstance(item, DiagramItem)):
                     zValue = item.zValue() + 0.1
         selectedItem.setZValue(zValue)
 
-
     def send_to_back(self):
         if scene.selectedItems().isEmpty():
             return
         zValue = 0
         for item in overlapItems:
             if (item.zValue() <= zValue and
-                isinstance(item, DiagramItem)):
+                    isinstance(item, DiagramItem)):
                     zValue = item.zValue() - 0.1
         selectedItem.setZValue(zValue)
 
 
-
-
 class Editor(QWidget):
 
     def __init__(self, parent, width, height):
         self.scene.setSceneRect(0, 0, self.width(), self.height())
         self.view.setScene(self.scene)
 
-        self.but = QLabel("test") #QPushButton("Click me")
+        self.but = QLabel("test")  # QPushButton("Click me")
         item = self.scene.addWidget(self.but)
         item.setFlag(QGraphicsItem.ItemIsMovable)
         self.view.ensureVisible(item)
 
-
-
     def resizeEvent(self, event):
         self.view.center()
         return QWidget.resizeEvent(self, event)
-                         
 
 
 if __name__ == "__main__":

File qtwidgets/lineedit.py

View file
  • Ignore whitespace
 from PyQt4.QtGui import *
 
 
-
 class LineEditButton(QToolButton):
 
     def __init__(self, parent, iconname):
         QToolButton.__init__(self, parent)
         pixmap = QPixmap(iconname)
         self.setIcon(QIcon(pixmap))
-        self.setIconSize(QSize(16,16)) #pixmap.size()
+        self.setIconSize(QSize(16, 16))  # pixmap.size()
         self.setCursor(Qt.ArrowCursor)
         self.setPopupMode(QToolButton.InstantPopup)
         self.setStyleSheet(
             "QToolButton { border: none; padding: 0px; }")
 
 
-
 class LineEditSide:
     Left = 1
     Right = 2
 
 class LineEdit(QLineEdit):
 
-
     def __init__(self, parent=None, inactive=""):
         QLineEdit.__init__(self, parent)
 
         import qtwidgets.lineedit_icons
 
-
         self.left = QWidget(self)
         self.left_layout = QHBoxLayout(self.left)
         self.left_layout.setContentsMargins(0, 0, 0, 0)
         self.right_layout.setContentsMargins(0, 0, 0, 0)
         self.inactive_text = inactive
 
-
     def add_widget(self, widget, side):
         if side == LineEditSide.Left:
             layout = self.left_layout
             layout.insertWidget(1, widget)
         self.update_geometry()
 
-
     def remove_widget(self, widget):
         self.left_layout.removeWidget(widget)
         self.right_layout.removeWidget(widget)
-        
 
     def update_geometry(self):
         frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
             "QLineEdit { padding-left: %spx; padding-right: %spx; } " % (
                 self.left.sizeHint().width() + frameWidth + 1,
                 self.right.sizeHint().width() + frameWidth + 1)
-            )
+        )
         msz = self.minimumSizeHint()
         self.setMinimumSize(
             max(msz.width(),
-                 self.right.sizeHint().height() + frameWidth * 2 + 2),
+                self.right.sizeHint(
+                ).height() + frameWidth * 2 + 2),
             max(msz.height(),
-                  self.right.sizeHint().height() + frameWidth * 2 + 2))
-
+                self.right.sizeHint().height() + frameWidth * 2 + 2))
 
     def resizeEvent(self, event):
         frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
         left_hint = self.left.sizeHint()
         right_hint = self.right.sizeHint()
         self.left.move(frameWidth + 1,
-                        (rect.bottom() + 1 - left_hint.height()) / 2)
+                      (rect.bottom() + 1 - left_hint.height()) / 2)
         self.right.move(rect.right() - frameWidth - right_hint.width(),
                         (rect.bottom() + 1 - right_hint.height()) / 2)
 
-
     def add_clear_button(self):
         self.clear_button = LineEditButton(self, ":edit-clear.png")
         self.add_widget(self.clear_button, LineEditSide.Right)
-        #self.clear_button.hide()
+        # self.clear_button.hide()
         self.connect(self.clear_button, SIGNAL("clicked()"), self.clear)
         self.connect(self, SIGNAL("textChanged(const QString&)"),
                      self.update_clear_button)
 
-
     def update_clear_button(self, text):
         self.clear_button.setVisible(not text.isEmpty())
 
-
     def textMargin(self, side):
         if side == LineEditSide.Left:
             spacing = self.left_layout.spacing()
         else:
             spacing = self.right_layout.spacing()
             w = self.right.sizeHint().width()
-        return w + spacing*2
-
+        return w + spacing * 2
 
     def paintEvent(self, event):
         QLineEdit.paintEvent(self, event)
            self.inactive_text and \
            not self.hasFocus():
 
-             panel = QStyleOptionFrameV2()
-             self.initStyleOption(panel)
-             textRect = self.style().subElementRect(
-                 QStyle.SE_LineEditContents, panel, self)
-             horizontalMargin = 2;
-             textRect.adjust(horizontalMargin, 0, 0, 0)
+            panel = QStyleOptionFrameV2()
+            self.initStyleOption(panel)
+            textRect = self.style().subElementRect(
+                QStyle.SE_LineEditContents, panel, self)
+            horizontalMargin = 2
+            textRect.adjust(horizontalMargin, 0, 0, 0)
 
-             #if QT_VERSION >= 0x040500
-             left = self.textMargin(LineEditSide.Left)
-             right = self.textMargin(LineEditSide.Right)
-             textRect.adjust(left, 0, -right, 0);
-             #endif
-             
-             painter = QPainter(self)
-             painter.setPen(
-                 self.palette().brush(
-                     QPalette.Disabled, QPalette.Text).color())
-             painter.drawText(
-                 textRect, Qt.AlignLeft | Qt.AlignVCenter, self.inactive_text)
+            # if QT_VERSION >= 0x040500
+            left = self.textMargin(LineEditSide.Left)
+            right = self.textMargin(LineEditSide.Right)
+            textRect.adjust(left, 0, -right, 0)
+            # endif
+
+            painter = QPainter(self)
+            painter.setPen(
+                self.palette().brush(
+                    QPalette.Disabled, QPalette.Text).color())
+            painter.drawText(
+                textRect, Qt.AlignLeft | Qt.AlignVCenter, self.inactive_text)

File qtwidgets/lineedit_icons.py

View file
  • Ignore whitespace
 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
 "
 
+
 def qInitResources():
-    QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+    QtCore.qRegisterResourceData(
+        0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+
 
 def qCleanupResources():
-    QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+    QtCore.qUnregisterResourceData(
+        0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
 
 qInitResources()

File qtwidgets/olmapwidget/__init__.py

View file
  • Ignore whitespace
 import sys
 import os
 
-#sys.path.remove("/usr/lib/python2.7/site-packages")