More canvas work, added shared_canvas.py
This commit is contained in:
parent
0802f745e1
commit
292ef21d9b
|
@ -9,6 +9,8 @@
|
|||
*.so
|
||||
*.dll
|
||||
|
||||
*.pro.user
|
||||
|
||||
*.pyc
|
||||
ui_*.py
|
||||
icons_rc.py
|
||||
|
|
|
@ -17,17 +17,17 @@
|
|||
# For a full copy of the GNU General Public License see the COPYING file
|
||||
|
||||
# Imports (Global)
|
||||
from PyQt4.QtCore import pyqtSlot, Qt, QSettings
|
||||
from PyQt4.QtGui import QApplication, QDialog, QDialogButtonBox, QMainWindow, QPainter, QTableWidgetItem
|
||||
from PyQt4.QtCore import pyqtSlot, QSettings
|
||||
from PyQt4.QtGui import QApplication, QDialog, QDialogButtonBox, QMainWindow, QTableWidgetItem
|
||||
from PyQt4.QtXml import QDomDocument
|
||||
|
||||
# Imports (Custom Stuff)
|
||||
import patchcanvas
|
||||
import ui_catarina, icons_rc
|
||||
import ui_catarina_addgroup, ui_catarina_removegroup, ui_catarina_renamegroup
|
||||
import ui_catarina_addport, ui_catarina_removeport, ui_catarina_renameport
|
||||
import ui_catarina_connectports, ui_catarina_disconnectports
|
||||
from shared import *
|
||||
from shared_canvas import *
|
||||
|
||||
try:
|
||||
from PyQt4.QtOpenGL import QGLWidget
|
||||
|
@ -616,7 +616,7 @@ class CatarinaMainW(QMainWindow, ui_catarina.Ui_CatarinaMainW):
|
|||
self.connect(self.b_ports_connect, SIGNAL("clicked()"), SLOT("slot_connectPorts()"))
|
||||
self.connect(self.b_ports_disconnect, SIGNAL("clicked()"), SLOT("slot_disconnectPorts()"))
|
||||
|
||||
#setCanvasConnections(self)
|
||||
setCanvasConnections(self)
|
||||
|
||||
#self.connect(self.act_settings_configure, SIGNAL("triggered()"), self.configureCatarina)
|
||||
|
||||
|
@ -754,6 +754,24 @@ class CatarinaMainW(QMainWindow, ui_catarina.Ui_CatarinaMainW):
|
|||
self.m_connection_list.remove(connection)
|
||||
break
|
||||
|
||||
def init_ports_prepare(self):
|
||||
pass
|
||||
|
||||
def init_ports(self):
|
||||
for group in self.m_group_list:
|
||||
patchcanvas.addGroup(group[iGroupId], group[iGroupName], patchcanvas.SPLIT_YES if (group[iGroupSplit]) else patchcanvas.SPLIT_NO, group[iGroupIcon])
|
||||
|
||||
for group_pos in self.m_group_list_pos:
|
||||
patchcanvas.setGroupPos(group_pos[iGroupPosId], group_pos[iGroupPosX_o], group_pos[iGroupPosY_o], group_pos[iGroupPosX_i], group_pos[iGroupPosY_i])
|
||||
|
||||
for port in self.m_port_list:
|
||||
patchcanvas.addPort(port[iPortGroup], port[iPortId], port[iPortName], port[iPortMode], port[iPortType])
|
||||
|
||||
for connection in self.m_connection_list:
|
||||
patchcanvas.connectPorts(connection[iConnId], connection[iConnOutput], connection[iConnInput])
|
||||
|
||||
self.m_group_list_pos = []
|
||||
|
||||
def saveFile(self, path):
|
||||
content = ("<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
"<!DOCTYPE CATARINA>\n"
|
||||
|
@ -918,23 +936,10 @@ class CatarinaMainW(QMainWindow, ui_catarina.Ui_CatarinaMainW):
|
|||
self.m_last_connection_id += 1
|
||||
|
||||
patchcanvas.clear()
|
||||
self.init_ports()
|
||||
|
||||
for group in self.m_group_list:
|
||||
patchcanvas.addGroup(group[iGroupId], group[iGroupName], patchcanvas.SPLIT_YES if (group[iGroupSplit]) else patchcanvas.SPLIT_NO, group[iGroupIcon])
|
||||
|
||||
for group_pos in self.m_group_list_pos:
|
||||
patchcanvas.setGroupPos(group_pos[iGroupPosId], group_pos[iGroupPosX_o], group_pos[iGroupPosY_o], group_pos[iGroupPosX_i], group_pos[iGroupPosY_i])
|
||||
|
||||
for port in self.m_port_list:
|
||||
patchcanvas.addPort(port[iPortGroup], port[iPortId], port[iPortName], port[iPortMode], port[iPortType])
|
||||
|
||||
for connection in self.m_connection_list:
|
||||
patchcanvas.connectPorts(connection[iConnId], connection[iConnOutput], connection[iConnInput])
|
||||
|
||||
self.m_group_list_pos = []
|
||||
|
||||
#self.scene.zoom_fit()
|
||||
#self.scene.zoom_reset()
|
||||
self.scene.zoom_fit()
|
||||
self.scene.zoom_reset()
|
||||
|
||||
@pyqtSlot()
|
||||
def slot_projectNew(self):
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Common/Shared code related to PatchCanvas
|
||||
# Copyright (C) 2012 Filipe Coelho <falktx@gmail.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# For a full copy of the GNU General Public License see the COPYING file
|
||||
|
||||
# Imports (Global)
|
||||
import os
|
||||
from PyQt4.QtCore import Qt, SIGNAL
|
||||
from PyQt4.QtGui import QFileDialog, QImage, QPainter, QPrinter, QPrintDialog
|
||||
|
||||
# Imports (Custom Stuff)
|
||||
import patchcanvas
|
||||
|
||||
# Shared Canvas code
|
||||
def canvas_arrange(self):
|
||||
patchcanvas.Arrange()
|
||||
|
||||
def canvas_refresh(self):
|
||||
self.init_ports_prepare()
|
||||
patchcanvas.clear()
|
||||
self.init_ports()
|
||||
|
||||
def canvas_zoom_fit(self):
|
||||
self.scene.zoom_fit()
|
||||
|
||||
def canvas_zoom_in(self):
|
||||
self.scene.zoom_in()
|
||||
|
||||
def canvas_zoom_out(self):
|
||||
self.scene.zoom_out()
|
||||
|
||||
def canvas_zoom_reset(self):
|
||||
self.scene.zoom_reset()
|
||||
|
||||
def canvas_print(self):
|
||||
self.scene.clearSelection()
|
||||
self.m_export_printer = QPrinter()
|
||||
dialog = QPrintDialog(self.m_export_printer, self)
|
||||
if (dialog.exec_()):
|
||||
painter = QPainter(self.m_export_printer)
|
||||
painter.setRenderHint(QPainter.Antialiasing)
|
||||
painter.setRenderHint(QPainter.TextAntialiasing)
|
||||
self.scene.render(painter)
|
||||
|
||||
def canvas_save_image(self):
|
||||
newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
|
||||
print(newPath)
|
||||
|
||||
if (newPath):
|
||||
self.scene.clearSelection()
|
||||
if (newPath.endswith((".jpg", ".jpG", ".jPG", ".JPG", ".JPg", ".Jpg"))):
|
||||
img_format = "JPG"
|
||||
elif (newPath.endswith((".png", ".pnG", ".pNG", ".PNG", ".PNg", ".Png"))):
|
||||
img_format = "PNG"
|
||||
else:
|
||||
# File-dialog may not auto-add the extension
|
||||
img_format = "PNG"
|
||||
newPath += ".png"
|
||||
|
||||
self.m_export_image = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
|
||||
painter = QPainter(self.m_export_image)
|
||||
painter.setRenderHint(QPainter.Antialiasing)
|
||||
painter.setRenderHint(QPainter.TextAntialiasing)
|
||||
self.scene.render(painter)
|
||||
self.m_export_image.save(newPath, img_format, 100)
|
||||
|
||||
# Shared Connections
|
||||
def setCanvasConnections(self):
|
||||
self.act_canvas_arrange.setEnabled(False)
|
||||
self.connect(self.act_canvas_arrange, SIGNAL("triggered()"), lambda: canvas_arrange(self))
|
||||
self.connect(self.act_canvas_refresh, SIGNAL("triggered()"), lambda: canvas_refresh(self))
|
||||
self.connect(self.act_canvas_zoom_fit, SIGNAL("triggered()"), lambda: canvas_zoom_fit(self))
|
||||
self.connect(self.act_canvas_zoom_in, SIGNAL("triggered()"), lambda: canvas_zoom_in(self))
|
||||
self.connect(self.act_canvas_zoom_out, SIGNAL("triggered()"), lambda: canvas_zoom_out(self))
|
||||
self.connect(self.act_canvas_zoom_100, SIGNAL("triggered()"), lambda: canvas_zoom_reset(self))
|
||||
self.connect(self.act_canvas_print, SIGNAL("triggered()"), lambda: canvas_print(self))
|
||||
self.connect(self.act_canvas_save_image, SIGNAL("triggered()"), lambda: canvas_save_image(self))
|
||||
self.connect(self.b_canvas_zoom_fit, SIGNAL("clicked()"), lambda: canvas_zoom_fit(self))
|
||||
self.connect(self.b_canvas_zoom_in, SIGNAL("clicked()"), lambda: canvas_zoom_in(self))
|
||||
self.connect(self.b_canvas_zoom_out, SIGNAL("clicked()"), lambda: canvas_zoom_out(self))
|
||||
self.connect(self.b_canvas_zoom_100, SIGNAL("clicked()"), lambda: canvas_zoom_reset(self))
|
Loading…
Reference in New Issue