jfsposeidon/scrap/show_html.py
2022-07-28 14:08:48 +02:00

251 lines
7.1 KiB
Python

import sys,os
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
web =QWebEngineView()
#web.load(QUrl('http://192.168.2.242:8000/'))
script_dir = os.path.dirname(__file__)
file_path = os.path.join(script_dir, 'test.html')
with open(file_path,encoding="UTF-8") as f:
html = f.read()
print(file_path)
web.load(QUrl.fromLocalFile(file_path))
web.show()
sys.exit(app.exec_())
# import pandas as pd
# from bokeh import plotting, embed, resources
# from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
# import os
# class Widget(QtWidgets.QWidget):
# def __init__(self, parent=None):
# super(Widget, self).__init__(parent)
# button = QtWidgets.QPushButton("Submit")
# saveit = QtWidgets.QPushButton('save')
# self.m_output = QtWebEngineWidgets.QWebEngineView()
# button.clicked.connect(self.on_button_clicked)
# saveit.clicked.connect(self.do_save)
# lay = QtWidgets.QVBoxLayout(self)
# lay.addWidget(button)
# lay.addWidget(saveit)
# lay.addWidget(self.m_output)
# self.resize(640, 480)
# @QtCore.pyqtSlot()
# def do_save(self):
# p = plotting.figure(plot_width=300, plot_height=300)
# data = {"Day": [0, 1, 2, 3, 0, 1], "Num": [0, 0, 1, 1, 2, 3]}
# df = pd.DataFrame(data)
# p.hexbin(df.Day, df.Num, size=0.5)
# html = embed.file_html(p, resources.CDN, "my plot")
# script_dir = os.path.dirname(__file__)
# file_path = os.path.join(script_dir, './test.html')
# with open(file_path,'w',encoding='utf_8') as f:
# f.write(html)
# print(html)
# self.m_output.setHtml(html)
# @QtCore.pyqtSlot()
# def on_button_clicked(self):
# # p = plotting.figure(plot_width=300, plot_height=300)
# # data = {"Day": [0, 1, 2, 3, 0, 1], "Num": [0, 0, 1, 1, 2, 3]}
# # df = pd.DataFrame(data)
# # p.hexbin(df.Day, df.Num, size=0.5)
# # html = embed.file_html(p, resources.CDN, "my plot")
# # self.m_output.setHtml(html)
# #self.m_output.setContent(html,"text/html;charset=UTF-8","")
# # html =''
# # script_dir = os.path.dirname(__file__)
# # file_path = os.path.join(script_dir, './test.html')
# # with open(file_path,encoding="UTF-8") as f:
# # html = f.read()
# # print(html)
# self.m_output.load(QtCore.QUrl('https://t-online.de'))
# if __name__ == "__main__":
# import sys
# app = QtWidgets.QApplication(sys.argv)
# w = Widget()
# w.show()
# sys.exit(app.exec_())
# from PyQt5.QtWidgets import QApplication
# from PyQt5.QtWebEngineWidgets import QWebEngineView
# from PyQt5.QtWebChannel import QWebChannel
# from PyQt5.QtCore import QObject, pyqtSlot, QUrl, QVariant
# import os
# class CallHandler(QObject):
# @pyqtSlot(result=QVariant)
# def test(self):
# print('call received')
# return QVariant({"abc": "def", "ab": 22})
# # take an argument from javascript - JS: handler.test1('hello!')
# @pyqtSlot(QVariant, result=QVariant)
# def test1(self, args):
# print('i got')
# print(args)
# return "ok"
# class WebView(QWebEngineView):
# def __init__(self):
# super(WebView, self).__init__()
# self.channel = QWebChannel()
# self.handler = CallHandler()
# self.channel.registerObject('handler', self.handler)
# self.page().setWebChannel(self.channel)
# file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "test.html"))
# local_url = QUrl.fromLocalFile(file_path)
# self.load(local_url)
# if __name__ == "__main__":
# app = QApplication([])
# view = WebView()
# view.show()
# app.exec_()
# from bokeh.plotting import figure, show
# # prepare some data
# x = [1, 2, 3, 4, 5]
# y = [6, 7, 2, 4, 5]
# # create a new plot with a title and axis labels
# p = figure(title="Simple line example", x_axis_label="x", y_axis_label="y")
# # add a line renderer with legend and line thickness
# p.line(x, y, legend_label="Temp.", line_width=2)
# # show the results
# show(p)
# import sys
# from pathlib import Path
# from PyQt5 import QAxContainer
# from PyQt5.QtCore import Qt
# from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLineEdit, QApplication
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
# from PyQt5.QtWebEngineWidgets import QWebEngineView
# from PyQt5.QtCore import pyqtSlot
# from bokeh.layouts import column
# from bokeh.models import ColumnDataSource, CustomJS, Slider
# from bokeh.plotting import Figure, output_file
# from bokeh.embed import file_html
# from bokeh.resources import CDN
# class App(QWidget):
# def __init__(self):
# super().__init__()
# self.resize(500, 500)
# self.initUI()
# def initUI(self):
# button = QPushButton('start', self)
# button.move(100, 70)
# button.clicked.connect(self.on_click)
# self.layout = QVBoxLayout()
# self.layout1 = QVBoxLayout()
# self.layout1.addWidget(button)
# self.layout2 = QVBoxLayout()
# self.layout.addLayout(self.layout1)
# self.layout.addLayout(self.layout2)
# self.setLayout(self.layout)
# self.show()
# @pyqtSlot()
# def on_click(self):
# print('PyQt5 button click')
# self.m_output = QWebEngineView()
# self.layout2.addWidget(self.m_output)
# #html_file = self.bokeh_function()
# html_file = self.test_html()
# self.m_output.setHtml(html_file)
# self.m_output.show()
# def bokeh_function(self):
# # taken from https://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html
# output_file("js_on_change.html")
# x = [x * 0.005 for x in range(0, 200)]
# y = x
# source = ColumnDataSource(data=dict(x=x, y=y))
# plot = Figure(width=400, height=400)
# plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
# callback = CustomJS(args=dict(source=source), code="""
# const data = source.data;
# const f = cb_obj.value
# const x = data['x']
# const y = data['y']
# for (let i = 0; i < x.length; i++) {
# y[i] = Math.pow(x[i], f)
# }
# source.change.emit();
# """)
# slider = Slider(start=0.1, end=4, value=1, step=.1, title="power")
# slider.js_on_change('value', callback)
# layout = column(slider, plot)
# html = file_html(layout, CDN, "my plot")
# return html
# def test_html(self):
# html = '<html><head><meta charset="utf-8" />'
# html += '<script src="{}"></script></head>'
# html += '<body>'
# #html += plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
# html += 'Hi there!'
# html += '</body></html>'
# return html
# if __name__ == '__main__':
# app = QApplication(sys.argv)
# ex = App()
# sys.exit(app.exec_())