You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
#!/usr/bin/env python3 |
|
# -*- coding: utf-8 -*- |
|
|
|
# Copyright (C) 2018 Andy Stewart |
|
# |
|
# Author: Andy Stewart <lazycat.manatee@gmail.com> |
|
# Maintainer: Andy Stewart <lazycat.manatee@gmail.com> |
|
# |
|
# This program is free software: you can redistribute it and/or modify |
|
# it under the terms of the GNU General Public License as published by |
|
# the Free Software Foundation, either version 3 of the License, or |
|
# any later version. |
|
# |
|
# This program is distributed in the hope that it will be useful, |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
# GNU General Public License for more details. |
|
# |
|
# You should have received a copy of the GNU General Public License |
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
from PyQt5 import QtCore |
|
import functools |
|
import os |
|
|
|
class PostGui(QtCore.QObject): |
|
|
|
through_thread = QtCore.pyqtSignal(object, object) |
|
|
|
def __init__(self, inclass=True): |
|
super(PostGui, self).__init__() |
|
self.through_thread.connect(self.on_signal_received) |
|
self.inclass = inclass |
|
|
|
def __call__(self, func): |
|
self._func = func |
|
|
|
@functools.wraps(func) |
|
def obj_call(*args, **kwargs): |
|
self.emit_signal(args, kwargs) |
|
return obj_call |
|
|
|
def emit_signal(self, args, kwargs): |
|
self.through_thread.emit(args, kwargs) |
|
|
|
def on_signal_received(self, args, kwargs): |
|
if self.inclass: |
|
obj, args = args[0], args[1:] |
|
self._func(obj, *args, **kwargs) |
|
else: |
|
self._func(*args, **kwargs) |
|
|
|
def touch(path): |
|
if not os.path.exists(path): |
|
basedir = os.path.dirname(path) |
|
|
|
if not os.path.exists(basedir): |
|
os.makedirs(basedir) |
|
|
|
with open(path, 'a'): |
|
os.utime(path)
|
|
|