mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 01:48:11 +08:00
GUI app (experimental) (#730)
* add default config * first pass * flake8 * cleanup * first pass at using qthreads * cleanup * WIP * better error handling * improved UI * bugfix * fix merge bugs * import order * cleanup * make gui requirements optional * pr review requested changes * Update server/gui/main.py Co-Authored-By: csweaver <charlottesweaver@gmail.com> * pr review request * qt child class methods -> camelCase * whitespace
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
# flake8: noqa F403, F405
|
||||
from cefpython3 import cefpython as cef
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtWidgets import *
|
||||
|
||||
from server.gui.utils import WINDOWS, LINUX
|
||||
|
||||
WindowUtils = cef.WindowUtils()
|
||||
|
||||
# OS differences
|
||||
# noinspection PyUnresolvedReferences
|
||||
CefWidgetParent = QWidget
|
||||
if LINUX:
|
||||
# noinspection PyUnresolvedReferences
|
||||
CefWidgetParent = QX11EmbedContainer
|
||||
|
||||
|
||||
class CefWidget(CefWidgetParent):
|
||||
def __init__(self, parent=None):
|
||||
super(CefWidget, self).__init__(parent)
|
||||
self.parent = parent
|
||||
self.browser = None
|
||||
# TODO test without this on linux
|
||||
self.hidden_window = None # Required for PyQt5 on Linux
|
||||
self.show()
|
||||
|
||||
def focusInEvent(self, event):
|
||||
# This event seems to never get called on Linux, as CEF is
|
||||
# stealing all focus due to Issue #284.
|
||||
if self.browser:
|
||||
if WINDOWS:
|
||||
WindowUtils.OnSetFocus(self.getHandle(), 0, 0, 0)
|
||||
self.browser.SetFocus(True)
|
||||
|
||||
def focusOutEvent(self, event):
|
||||
# This event seems to never get called on Linux, as CEF is
|
||||
# stealing all focus due to Issue #284.
|
||||
if self.browser:
|
||||
self.browser.SetFocus(False)
|
||||
|
||||
def embedBrowser(self):
|
||||
if LINUX:
|
||||
self.hidden_window = QWindow()
|
||||
window_info = cef.WindowInfo()
|
||||
rect = [0, 0, self.width(), self.height()]
|
||||
window_info.SetAsChild(self.getHandle(), rect)
|
||||
# TODO better splash
|
||||
self.browser = cef.CreateBrowserSync(window_info)
|
||||
|
||||
def getHandle(self):
|
||||
if self.hidden_window:
|
||||
# PyQt5 on Linux
|
||||
return int(self.hidden_window.winId())
|
||||
else:
|
||||
return int(self.winId())
|
||||
|
||||
def moveEvent(self, _):
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
if self.browser:
|
||||
if WINDOWS:
|
||||
WindowUtils.OnSize(self.getHandle(), 0, 0, 0)
|
||||
elif LINUX:
|
||||
self.browser.SetBounds(self.x, self.y,
|
||||
self.width(), self.height())
|
||||
self.browser.NotifyMoveOrResizeStarted()
|
||||
|
||||
def resizeEvent(self, event):
|
||||
size = event.size()
|
||||
if self.browser:
|
||||
if WINDOWS:
|
||||
WindowUtils.OnSize(self.getHandle(), 0, 0, 0)
|
||||
elif LINUX:
|
||||
self.browser.SetBounds(self.x, self.y,
|
||||
size.width(), size.height())
|
||||
self.browser.NotifyMoveOrResizeStarted()
|
||||
|
||||
|
||||
class CefApplication(QApplication):
|
||||
def __init__(self, args):
|
||||
super(CefApplication, self).__init__(args)
|
||||
if not cef.GetAppSetting("external_message_pump"):
|
||||
self.timer = self.createTimer()
|
||||
|
||||
def createTimer(self):
|
||||
timer = QTimer()
|
||||
timer.timeout.connect(self.onTimer)
|
||||
timer.start(10)
|
||||
return timer
|
||||
|
||||
def onTimer(self):
|
||||
cef.MessageLoopWork()
|
||||
|
||||
def stopTimer(self):
|
||||
# Stop the timer after Qt's message loop has ended
|
||||
self.timer.stop()
|
||||
Reference in New Issue
Block a user