Skip to content

Commit

Permalink
#271 moved web-based GUI infrastructure to soma-base
Browse files Browse the repository at this point in the history
  • Loading branch information
sapetnioc committed Sep 22, 2023
1 parent 171a140 commit 0666ff6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 586 deletions.
2 changes: 1 addition & 1 deletion capsul/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def dashboard(self):


def engine(self, engine_label):
engine = self.handler.capsul.engine(engine_label)
engine = self.handler.jinja_kwargs['capsul'].engine(engine_label)
if engine:
return self._result('engine.html', engine=engine)

Expand Down
45 changes: 32 additions & 13 deletions capsul/ui/__main__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
# -*- coding: utf-8 -*-
import sys
from soma.qt_gui.qt_backend import Qt

from capsul.web import CapsulBrowserWindow
from ..api import Capsul
from . import CapsulRoutes, CapsulBackend

# Parameters common to Qt and Web server handlers
handler_kwargs = dict(
routes=CapsulRoutes(),
backend=CapsulBackend(),
static='capsul.ui',
templates='capsul.ui',
capsul=Capsul(),
title='Capsul'
)

# import http, http.server
# from capsul.web import CapsulHTTPHandler
def web_server_gui():
import http, http.server
from soma.web import SomaHTTPHandler

# class Handler(CapsulHTTPHandler, base_url='http://localhost:8080'):
# pass
# httpd = http.server.HTTPServer(('', 8080), Handler)
# httpd.serve_forever()
class Handler(SomaHTTPHandler, base_url='http://localhost:8080', **handler_kwargs):
pass
httpd = http.server.HTTPServer(('', 8080), Handler)
httpd.serve_forever()

def qt_web_gui():
import sys
from soma.qt_gui.qt_backend import Qt
from soma.web import SomaBrowserWindow

app = Qt.QApplication(sys.argv)
w = SomaBrowserWindow(
starting_url='soma://dashboard',
window_title='Capsul dashboard',
**handler_kwargs
)
w.showMaximized()
app.exec_()

app = Qt.QApplication(sys.argv)
w = CapsulBrowserWindow()
w.show()
app.exec_()
qt_web_gui()
2 changes: 1 addition & 1 deletion capsul/ui/templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'layout.html' %}
{%block body %}
{% block body %}
<h1>Capsul engines</h1>

<table>
Expand Down
27 changes: 0 additions & 27 deletions capsul/ui/templates/html_backend.js

This file was deleted.

26 changes: 3 additions & 23 deletions capsul/ui/templates/layout.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{title or 'Capsul'}}</title>
{% extends 'soma_layout.html' %}
{%- block head%}
<link rel="icon" href="{{base_url}}/static/favicon.svg" type="image/svg+xml">
<link rel="stylesheet" href="{{base_url}}/static/capsul.css">
<script>const backend_ready = new CustomEvent('backend_ready');</script>
{%- if server_type=='qt' %}
<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>
<script type="text/javascript" src="{{base_url}}/qt_backend.js"></script>
{%- else %}
<script type="text/javascript" src="{{base_url}}/html_backend.js"></script>
{%- endif %}
{% block head -%}
{%- endblock %}
</head>

<body>
{% block body -%}
{%- endblock %}
{% block script -%}
{%- endblock %}
</body>
</html>

7 changes: 0 additions & 7 deletions capsul/ui/templates/qt_backend.js

This file was deleted.

Loading

0 comments on commit 0666ff6

Please sign in to comment.