Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
928cc842
Commit
928cc842
authored
Apr 20, 2010
by
Luci Stanescu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added (call|run)_in_gui_thread
parent
351a3cf3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
11 deletions
+86
-11
__init__.py
blink/__init__.py
+13
-0
event.py
blink/event.py
+40
-0
resources.py
blink/resources.py
+1
-10
util.py
blink/util.py
+32
-1
No files found.
blink/__init__.py
View file @
928cc842
...
...
@@ -6,6 +6,8 @@ __all__ = ['Blink']
import
sys
from
PyQt4.QtGui
import
QApplication
from
application
import
log
from
application.python.util
import
Null
from
blink.mainwindow
import
MainWindow
from
blink.util
import
QSingleton
...
...
@@ -22,4 +24,15 @@ class Blink(QApplication):
self
.
main_window
.
show
()
self
.
exec_
()
def
customEvent
(
self
,
event
):
handler
=
getattr
(
self
,
'_EH_
%
s'
%
event
.
name
,
Null
)
handler
(
event
)
def
_EH_CallFunctionEvent
(
self
,
event
):
try
:
event
.
function
(
*
event
.
args
,
**
event
.
kw
)
except
:
log
.
error
(
'Exception occured while calling function
%
s in the GUI thread'
%
event
.
function
.
__name__
)
log
.
err
()
blink/event.py
0 → 100644
View file @
928cc842
# Copyright (C) 2010 AG Projects. See LICENSE for details.
#
__all__
=
[
'CallFunctionEvent'
]
from
PyQt4.QtCore
import
QEvent
from
blink.util
import
classproperty
class
EventMeta
(
type
(
QEvent
)):
def
__init__
(
cls
,
name
,
bases
,
dct
):
super
(
EventMeta
,
cls
)
.
__init__
(
name
,
bases
,
dct
)
cls
.
id
=
QEvent
.
registerEventType
()
if
name
!=
'EventBase'
else
None
class
EventBase
(
QEvent
):
__metaclass__
=
EventMeta
def
__new__
(
cls
,
*
args
,
**
kw
):
if
cls
is
EventBase
:
raise
TypeError
(
"EventBase cannot be directly instantiated"
)
return
super
(
EventBase
,
cls
)
.
__new__
(
cls
)
def
__init__
(
self
):
super
(
EventBase
,
self
)
.
__init__
(
self
.
id
)
@
classproperty
def
name
(
cls
):
return
cls
.
__name__
class
CallFunctionEvent
(
EventBase
):
def
__init__
(
self
,
function
,
args
,
kw
):
super
(
CallFunctionEvent
,
self
)
.
__init__
()
self
.
function
=
function
self
.
args
=
args
self
.
kw
=
kw
blink/resources.py
View file @
928cc842
...
...
@@ -8,16 +8,7 @@ __all__ = ['Resources']
import
os
import
sys
# TODO: replace later with classproperty from sipsimple.util
def
classproperty
(
function
):
class
Descriptor
(
object
):
def
__get__
(
self
,
instance
,
owner
):
return
function
(
owner
)
def
__set__
(
self
,
instance
,
value
):
raise
AttributeError
(
"read-only attribute cannot be set"
)
def
__delete__
(
self
,
instance
):
raise
AttributeError
(
"read-only attribute cannot be deleted"
)
return
Descriptor
()
from
blink.util
import
classproperty
class
DirectoryContextManager
(
str
):
...
...
blink/util.py
View file @
928cc842
# Copyright (C) 2010 AG Projects. See LICENSE for details.
#
__all__
=
[
'QSingleton'
]
__all__
=
[
'QSingleton'
,
'classproperty'
,
'call_in_gui_thread'
,
'run_in_gui_thread'
]
from
PyQt4.QtCore
import
QObject
from
application.python.decorator
import
decorator
,
preserve_signature
from
application.python.util
import
Singleton
...
...
@@ -11,3 +12,33 @@ class QSingleton(Singleton, type(QObject)):
"""A metaclass for making Qt objects singletons"""
# TODO: replace later with classproperty from sipsimple.util
def
classproperty
(
function
):
class
Descriptor
(
object
):
def
__get__
(
self
,
instance
,
owner
):
return
function
(
owner
)
def
__set__
(
self
,
instance
,
value
):
raise
AttributeError
(
"read-only attribute cannot be set"
)
def
__delete__
(
self
,
instance
):
raise
AttributeError
(
"read-only attribute cannot be deleted"
)
return
Descriptor
()
def
call_in_gui_thread
(
function
,
*
args
,
**
kw
):
from
blink
import
Blink
from
blink.event
import
CallFunctionEvent
blink
=
Blink
()
blink
.
postEvent
(
blink
,
CallFunctionEvent
(
function
,
args
,
kw
))
@
decorator
def
run_in_gui_thread
(
func
):
@
preserve_signature
(
func
)
def
wrapper
(
*
args
,
**
kw
):
from
blink
import
Blink
from
blink.event
import
CallFunctionEvent
blink
=
Blink
()
blink
.
postEvent
(
blink
,
CallFunctionEvent
(
func
,
args
,
kw
))
return
wrapper
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment