import OpenGL.GL as gl import OpenGL.GLU as glu import OpenGL.GLUT as glut from PyQt5 import QtWidgets as qWidget from PyQt5 import QtGui as qGui from PyQt5 import QtCore as qCore from PyQt5 import uic import sys import os from PyQt5.QtCore import pyqtSignal, QPoint, QSize, Qt from PyQt5.QtWidgets import QMainWindow, QAction, QApplication, QWidget, QPushButton, qApp, QLabel, QHBoxLayout, QVBoxLayout, QSplitter class mainWindow(qWidget.QMainWindow): """Main window class.""" xRotationChanged = pyqtSignal(int) yRotationChanged = pyqtSignal(int) zRotationChanged = pyqtSignal(int) hRotationChanged = pyqtSignal(int) def __init__(self, *args): print("__init__") self.object = 0 self.xRot = 0 self.yRot = 0 self.zRot = 0 self.hRot = 1 self.lastPos = QPoint() super(mainWindow, self).__init__(*args) ui = os.path.join(os.path.dirname(__file__), 'test.ui') uic.loadUi(ui, self) ## self.trolltechGreen = QColor.fromCmykF(0.40, 0.0, 1.0, 0.0) def setupUI(self): print("setupUI") self.windowsHeight = self.openGLWidget.height() self.windowsWidth = self.openGLWidget.width() self.openGLWidget.initializeGL() self.openGLWidget.resizeGL(self.windowsWidth, self.windowsHeight) self.openGLWidget.paintGL = self.paintGL self.openGLWidget.initializeGL = self.initializeGL def paintGL(self): print("paintGL") gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) #очищаем буфер цвета и глубины gl.glMatrixMode(gl.GL_PROJECTION) #включаем матрицу проекции gl.glLoadIdentity() #обнуление матрицы. единичная x, y, width, height = gl.glGetDoublev(gl.GL_VIEWPORT) glu.gluPerspective( #создаем матрицу перспективы 45, # field of view in degrees width / float(height or 1), # aspect ratio .25, # near clipping plane 200, # far clipping plane ) gl.glMatrixMode(gl.GL_MODELVIEW) #включаем матрицу модели gl.glLoadIdentity() #обнуление матрицы. единичная ## glu.gluLookAt(12, 12, 12, 0, 0, 0, 0, 1, 0) print (self.hRot) glu.gluLookAt(12, 12, int(self.hRot), 0, 1, 0, 0, 1, 0) ## glu.gluLookAt(12, 12, 10, 0, 0, 0, 0, 1, 0) glut.glutWireSphere(2, 13, 13) def initializeGL(self): print("initializeGL") gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_DEPTH_TEST) def wheelEvent(self,event): ##приращение при прокрутке мыши print("wheelEvent") self.setHRotation(event.angleDelta().y()/120) self.paintGL() def setHRotation(self, zpozit): print("setHRotation") if self.hRot + zpozit<0: self.hRot =self.hRot else: self.hRot =self.hRot + zpozit self.hRotationChanged.emit(self.hRot) self.update() print (self.hRot) app = qWidget.QApplication(sys.argv) window = mainWindow() window.setupUI() window.show() sys.exit(app.exec_())
Romblerhttp://pyqtgraph.org/documentation/3dgraphics.html
Опять решил изучать питон на примере своего проекта.
# -*- coding: utf-8 -*- from PyQt5.QtWidgets import QMainWindow, QAction, QApplication, QWidget, QPushButton, qApp, QLabel, QHBoxLayout, QVBoxLayout, QSplitter from PyQt5.QtGui import QIcon, QPixmap, QPainter, QImage, QMatrix4x4, QQuaternion, QVector3D, QColor, QGuiApplication from PyQt5.QtCore import QSize, Qt import sys from PyQt5.Qt3DCore import QEntity, QTransform, QAspectEngine from PyQt5.Qt3DRender import QCamera, QCameraLens, QRenderAspect from PyQt5.Qt3DInput import QInputAspect from PyQt5.Qt3DExtras import QForwardRenderer, QPhongMaterial, QCylinderMesh, QSphereMesh, QTorusMesh, Qt3DWindow, QOrbitCameraController from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import uic from PyQt5.QtWidgets import * from PyQt5 import QtWidgets qtCreatorFile = "test.ui" Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) #loadUiType ( ) - она возвращает кортеж из двух элементов: ссылки на класс формы и ссылки на базовы й класс. import sys import math import os import module1 class Application(QtWidgets.QMainWindow, Ui_MainWindow): def __init__(self): super().__init__() ## super(mainWindow, self).__init__(*args) ui = os.path.join(os.path.dirname(__file__), qtCreatorFile) uic.loadUi(ui, self) # ## self.widget=View3D() ## print (self.widget.geometry()) self.view3d = View3D() self.setCentralWidget(self.view3d) self.Load.triggered.connect(self.showDialog) #нажатие загрузить def showDialog(self): #диалог открытия файла fname = QFileDialog.getOpenFileName(self, 'Загрузить файл', '/home')[0] file = open(fname, 'r') with file: text = file.read() module1.Printl(text) self.textkod.setText(text) file.close() class View3D(QWidget): def __init__(self): super(View3D, self).__init__() self.view = Qt3DWindow() self.container = self.createWindowContainer(self.view) self.label = QtWidgets.QLabel("Ghalo!") self.textkod = QtWidgets.QTextEdit("Ghalo!") ## self.textkod.setGeometry(QtCore.QRect(0, 0, 281, 651)) ## self.textkod.setObjectName("textkod") vboxlayout = QHBoxLayout() ## vboxlayout.addWidget(self.textkod) vboxlayout.addWidget(self.label) vboxlayout.addWidget(self.container) self.setLayout(vboxlayout) self.scene = createScene() initialiseCamera(self.view, self.scene)# Camera. self.view.setRootEntity(self.scene) def initialiseCamera(view, scene): # Camera. camera = view.camera() camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0) camera.setPosition(QVector3D(0.0, 0.0, 40.0)) camera.setViewCenter(QVector3D(0.0, 0.0, 0.0)) # For camera controls. camController = QOrbitCameraController(scene) camController.setLinearSpeed(50.0) camController.setLookSpeed(180.0) camController.setCamera(camera) def createScene(): # Root entity. rootEntity = QEntity() # Material. material = QPhongMaterial(rootEntity) # Torus. torusEntity = QEntity(rootEntity) torusMesh = QTorusMesh() torusMesh.setRadius(5) torusMesh.setMinorRadius(1) torusMesh.setRings(100) torusMesh.setSlices(20) torusTransform = QTransform() torusTransform.setScale3D(QVector3D(1.5, 1.0, 0.5)) torusTransform.setRotation(QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0)) torusEntity.addComponent(torusMesh) torusEntity.addComponent(torusTransform) torusEntity.addComponent(material) # Sphere. sphereEntity = QEntity(rootEntity) sphereMesh = QSphereMesh() sphereMesh.setRadius(3) sphereEntity.addComponent(sphereMesh) sphereEntity.addComponent(material) return rootEntity ##class Application(QMainWindow): if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) ex = Application() ex.show() sys.exit(app.exec_())
FishHookна сколько я знаю браузерные программы не позволяют работать с файлами. а мне же необходимо будет читать информацию из файла и создавать новые.
Romblerсовсем нет, вот например чтение из csv
на сколько я знаю браузерные программы не позволяют работать с файлами
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Line Chart</title> <script src="js/Chart.min.js"></script> <style> body, html { background: #eeeeee; /* цвет фона */ min-width: 800px; } div { text-align: center; margin: 3px; border: 1px solid #ccc; } input[type="file"] { display:none; } table { border-collapse: collapse; border: solid gray 1px; width: 100%; } td,th { border: solid gray 1px;; align: center; color: #333; } button { font-size: 14px; font-family: Tahoma, Times New Roman; color: #333; background: #ddd; border-radius: 10px; margin: 5px; } button:hover { font-size: 16px; background: #eee; } #chart { float: right; height: 60%; width: 88%; } #data { float: right; width: 88%; } #controls { float: left; width: 10%; } </style> </head> <body> <div id="controls"> <button onclick="showFileInput()">Выбрать<br>файл</button> <!--button>User<br>Button 1</button> <button>User<br>Button 2</button> <button>User<br>Button 3</button> <button>User<br>Button 4</button> <button>User<br>Button 5</button> <button>User<br>Button 6</button> <button>User<br>Button 7</button> <button>User<br>Button 8</button--> <input id="fileInput" type="file" accept=".csv" size="10" onchange="processFiles(this.files)"> </div> <div id="chart"> <canvas id="myChart" width="600" height="300"></canvas> </div> <div id="data"></div> </body> <script> var ctx = document.querySelector("#myChart"); var chart; var COLORS = ['#ff0000dd','#00ff00dd','#0000ffdd','#ff00ffdd','#4dc9f6dd','#f67019dd', '#f53794dd','#537bc4dd','#acc236dd','#166a8fdd','#00a950dd','#58595bdd','#8549baaa' ]; var color_index = -1; function getColor() { color_index ++; color_index %= COLORS.length; return COLORS[color_index]; }; var config = { type: 'line', data: { labels: [], datasets: [] }, options : { scales: { yAxes: [{ ticks: { beginAtZero:true } }] }, legend:{ display: true, position: 'right', labels: { fontSize: 14, fontColor: 'rgb(0,0,0,0.7)' } }, tooltips: { mode: 'point', backgroundColor: 'rgba(0,0,0,0.5)', //titleFontColor: 'rgba(255,255,255)' } } }; function addDataset(label='',data=[]) { var newColor = getColor(); var newDataset = { label: label, backgroundColor: newColor, borderColor: newColor, borderWidth: 1, data: data, fill: false, lineTension: 0, pointRadius: 3, pointHoverRadius: 5 }; config.data.datasets.push(newDataset); }; function csvToData(data) { var rows = data.trim().split(/\r?\n|\r/); var labels = rows[0].split(/;|,/).slice(1); config.data.labels = labels; for (var i = 1; i < rows.length; i++) { cells = rows[i].split(/;|,/); var label = cells.shift(); addDataset(label,cells) } }; function csvToTable(data) { var rows = data.trim().split(/\r?\n|\n/); var table = document.createElement('table'); var tbody = document.createElement('tbody'); var head = rows[0].split(/,|;/); var thead = document.createElement('thead'); var tr = document.createElement('tr'); for (var i = 0; i < head.length; i ++) { var th = document.createElement('th'); th.textContent = head[i]; tr.appendChild(th); } thead.appendChild(tr); table.appendChild(thead); for (var row = 1; row < rows.length; row ++) { var cols = rows[row].split(/;|,/) var tr = document.createElement('tr'); for (var col = 0; col < cols.length; col ++) { var cell = document.createElement('td'); cell.textContent = cols[col]; cell.contentEditable = true; tr.appendChild(cell); } tbody.appendChild(tr); } table.appendChild(tbody) return table; }; function tableToData(t) { var out = []; var rows = t.rows; for (var i = 1; i < rows.length; i ++) { var cells = rows[i].cells; var tmp = []; for (var j = 0; j < cells.length; j ++) { tmp.push(cells[j].textContent); } out.push(tmp); } //console.log(out); return out; }; function showFileInput() { var fileInput = document.getElementById("fileInput"); fileInput.click(); }; function processFiles(files) { var file = files[0]; var reader = new FileReader(); reader.onload = function (e) { var output = document.querySelector("#data"); output.innerHTML = ""; var t = csvToTable(e.target.result); output.appendChild(t); csvToData(e.target.result); chart = new Chart(ctx,config); }; reader.readAsText(file); }; </script> </html>
vic57А с выложенными кодами совсем ничего не получится сделать?
Romblerпосмотрите примеры и выберите какой надо
А с выложенными кодами совсем ничего не получится сделать?