Commit 58d5bb4c authored by Tijmen de Mes's avatar Tijmen de Mes

Added unique name generator function

parent 9bbf5467
...@@ -5,20 +5,31 @@ from application.python.decorator import decorator, preserve_signature ...@@ -5,20 +5,31 @@ from application.python.decorator import decorator, preserve_signature
from application.python.descriptor import classproperty from application.python.descriptor import classproperty
from application.python.types import Singleton from application.python.types import Singleton
from functools import partial from functools import partial
from itertools import count
from threading import Event from threading import Event
from sys import exc_info from sys import exc_info
from blink.event import CallFunctionEvent from blink.event import CallFunctionEvent
__all__ = ['QSingleton', 'call_in_gui_thread', 'call_later', 'run_in_gui_thread', 'translate'] __all__ = ['QSingleton', 'UniqueFilenameGenerator', 'call_in_gui_thread', 'call_later', 'run_in_gui_thread', 'translate']
translate = QCoreApplication.translate translate = QCoreApplication.translate
class QSingleton(Singleton, type(QObject)): class QSingleton(Singleton, type(QObject)):
"""A metaclass for making Qt objects singletons""" """A metaclass for making Qt objects singletons"""
class UniqueFilenameGenerator(object):
@classmethod
def generate(cls, name):
yield name
prefix, extension = os.path.splitext(name)
for x in count(1):
yield "%s-%d%s" % (prefix, x, extension)
def call_later(interval, function, *args, **kw): def call_later(interval, function, *args, **kw):
QTimer.singleShot(int(interval*1000), lambda: function(*args, **kw)) QTimer.singleShot(int(interval*1000), lambda: function(*args, **kw))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment