From 85549df4fbdaba0a7291fea4c301ed1a79a8b2db Mon Sep 17 00:00:00 2001 From: dae-eklen Date: Sun, 29 Jan 2012 19:45:46 +0200 Subject: [PATCH] init commit --- docs/naming-conventions.txt | 31 +++ test/imageviewer_test.py | 214 +++++++++++++++++++++ test/project.py | 184 ++++++++++++++++++ test/project_with_gr.ui | 330 ++++++++++++++++++++++++++++++++ test/test.py | 369 ++++++++++++++++++++++++++++++++++++ v/load_interface.py | 209 ++++++++++++++++++++ v/project.ui | 293 ++++++++++++++++++++++++++++ 7 files changed, 1630 insertions(+) create mode 100644 docs/naming-conventions.txt create mode 100644 test/imageviewer_test.py create mode 100644 test/project.py create mode 100644 test/project_with_gr.ui create mode 100644 test/test.py create mode 100644 v/load_interface.py create mode 100644 v/project.ui diff --git a/docs/naming-conventions.txt b/docs/naming-conventions.txt new file mode 100644 index 0000000..50d9d65 --- /dev/null +++ b/docs/naming-conventions.txt @@ -0,0 +1,31 @@ +NAMING CONVENTIONS + +Push Button -> btn +Radio Button -> rad +Tab Widget -> tab +Label -> lab +Vertical Spacer -> vsp +Horizontal Spacer -> hsp +Command Link Button -> clb +Line Edit -> eln +Text Edit -> etx +Time Edit -> etm +Plain Text Edit -> ept +Check Box -> chb +Tree View -> tre +List View -> lst +Combo Box -> cmb +Stacked Widget -> stw +Spin Box -> spb +statusbar -> stb +menu -> men +action -> act + + +verticalLayout -> vlt +horizontalLayout -> hlt +horizontalSpacer -> hsr +verticalSpacer -> vsr + + +MainWindow -> main_wnd diff --git a/test/imageviewer_test.py b/test/imageviewer_test.py new file mode 100644 index 0000000..06ec783 --- /dev/null +++ b/test/imageviewer_test.py @@ -0,0 +1,214 @@ +#!/usr/bin/env python + + +############################################################################# +## +## Copyright (C) 2010 Riverbank Computing Limited. +## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +## All rights reserved. +## +## This file is part of the examples of PyQt. +## +## $QT_BEGIN_LICENSE:BSD$ +## You may use this file under the terms of the BSD license as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +## the names of its contributors may be used to endorse or promote +## products derived from this software without specific prior written +## permission. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## $QT_END_LICENSE$ +## +############################################################################# + + +from PyQt4 import QtCore, QtGui + + +class ImageViewer(QtGui.QMainWindow): + def __init__(self): + super(ImageViewer, self).__init__() + + self.printer = QtGui.QPrinter() + self.scaleFactor = 0.0 + + self.imageLabel = QtGui.QLabel() + self.imageLabel.setBackgroundRole(QtGui.QPalette.Base) + self.imageLabel.setSizePolicy(QtGui.QSizePolicy.Ignored, + QtGui.QSizePolicy.Ignored) + self.imageLabel.setScaledContents(True) + + self.scrollArea = QtGui.QScrollArea() + self.scrollArea.setBackgroundRole(QtGui.QPalette.Dark) + self.scrollArea.setWidget(self.imageLabel) + self.setCentralWidget(self.scrollArea) + + self.createActions() + self.createMenus() + + self.setWindowTitle("Image Viewer") + self.resize(500, 400) + + def open(self): + fileName = QtGui.QFileDialog.getOpenFileName(self, "Open File", + QtCore.QDir.currentPath()) + if fileName: + image = QtGui.QImage(fileName) + if image.isNull(): + QtGui.QMessageBox.information(self, "Image Viewer", + "Cannot load %s." % fileName) + return + + self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image)) + self.scaleFactor = 1.0 + + self.printAct.setEnabled(True) + self.fitToWindowAct.setEnabled(True) + self.updateActions() + + if not self.fitToWindowAct.isChecked(): + self.imageLabel.adjustSize() + + def print_(self): + dialog = QtGui.QPrintDialog(self.printer, self) + if dialog.exec_(): + painter = QtGui.QPainter(self.printer) + rect = painter.viewport() + size = self.imageLabel.pixmap().size() + size.scale(rect.size(), QtCore.Qt.KeepAspectRatio) + #painter.setViewport(rect.x(), rect.y(), size.width(), size.height()) + painter.setWindow(self.imageLabel.pixmap().rect()) + painter.drawPixmap(0, 0, self.imageLabel.pixmap()) + + def zoomIn(self): + self.scaleImage(1.25) + + def zoomOut(self): + self.scaleImage(0.8) + + def normalSize(self): + self.imageLabel.adjustSize() + self.scaleFactor = 1.0 + + def fitToWindow(self): + fitToWindow = self.fitToWindowAct.isChecked() + self.scrollArea.setWidgetResizable(fitToWindow) + if not fitToWindow: + self.normalSize() + + self.updateActions() + + def about(self): + QtGui.QMessageBox.about(self, "About Image Viewer", + "

The Image Viewer example shows how to combine " + "QLabel and QScrollArea to display an image. QLabel is " + "typically used for displaying text, but it can also display " + "an image. QScrollArea provides a scrolling view around " + "another widget. If the child widget exceeds the size of the " + "frame, QScrollArea automatically provides scroll bars.

" + "

The example demonstrates how QLabel's ability to scale " + "its contents (QLabel.scaledContents), and QScrollArea's " + "ability to automatically resize its contents " + "(QScrollArea.widgetResizable), can be used to implement " + "zooming and scaling features.

" + "

In addition the example shows how to use QPainter to " + "print an image.

") + + def createActions(self): + self.openAct = QtGui.QAction("&Open...", self, shortcut="Ctrl+O", + triggered=self.open) + + self.printAct = QtGui.QAction("&Print...", self, shortcut="Ctrl+P", + enabled=False, triggered=self.print_) + + self.exitAct = QtGui.QAction("E&xit", self, shortcut="Ctrl+Q", + triggered=self.close) + + self.zoomInAct = QtGui.QAction("Zoom &In (25%)", self, + shortcut="Ctrl++", enabled=False, triggered=self.zoomIn) + + self.zoomOutAct = QtGui.QAction("Zoom &Out (25%)", self, + shortcut="Ctrl+-", enabled=False, triggered=self.zoomOut) + + self.normalSizeAct = QtGui.QAction("&Normal Size", self, + shortcut="Ctrl+S", enabled=False, triggered=self.normalSize) + + self.fitToWindowAct = QtGui.QAction("&Fit to Window", self, + enabled=False, checkable=True, shortcut="Ctrl+F", + triggered=self.fitToWindow) + + self.aboutAct = QtGui.QAction("&About", self, triggered=self.about) + + self.aboutQtAct = QtGui.QAction("About &Qt", self, + triggered=QtGui.qApp.aboutQt) + + def createMenus(self): + self.fileMenu = QtGui.QMenu("&File", self) + self.fileMenu.addAction(self.openAct) + self.fileMenu.addAction(self.printAct) + self.fileMenu.addSeparator() + self.fileMenu.addAction(self.exitAct) + + self.viewMenu = QtGui.QMenu("&View", self) + self.viewMenu.addAction(self.zoomInAct) + self.viewMenu.addAction(self.zoomOutAct) + self.viewMenu.addAction(self.normalSizeAct) + self.viewMenu.addSeparator() + self.viewMenu.addAction(self.fitToWindowAct) + + self.helpMenu = QtGui.QMenu("&Help", self) + self.helpMenu.addAction(self.aboutAct) + self.helpMenu.addAction(self.aboutQtAct) + + self.menuBar().addMenu(self.fileMenu) + self.menuBar().addMenu(self.viewMenu) + self.menuBar().addMenu(self.helpMenu) + + def updateActions(self): + self.zoomInAct.setEnabled(not self.fitToWindowAct.isChecked()) + self.zoomOutAct.setEnabled(not self.fitToWindowAct.isChecked()) + self.normalSizeAct.setEnabled(not self.fitToWindowAct.isChecked()) + + def scaleImage(self, factor): + self.scaleFactor *= factor + self.imageLabel.resize(self.scaleFactor * self.imageLabel.pixmap().size()) + + self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor) + self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor) + + self.zoomInAct.setEnabled(self.scaleFactor < 3.0) + self.zoomOutAct.setEnabled(self.scaleFactor > 0.333) + + def adjustScrollBar(self, scrollBar, factor): + scrollBar.setValue(int(factor * scrollBar.value() + + ((factor - 1) * scrollBar.pageStep()/2))) + + +if __name__ == '__main__': + + import sys + + app = QtGui.QApplication(sys.argv) + imageViewer = ImageViewer() + imageViewer.show() + sys.exit(app.exec_()) diff --git a/test/project.py b/test/project.py new file mode 100644 index 0000000..a6fa0e2 --- /dev/null +++ b/test/project.py @@ -0,0 +1,184 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'project.ui' +# +# Created: Sat Jan 28 14:42:19 2012 +# by: PyQt4 UI code generator 4.8.5 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +try: + _fromUtf8 = QtCore.QString.fromUtf8 +except AttributeError: + _fromUtf8 = lambda s: s + +class Ui_wnd_main(object): + def setupUi(self, wnd_main): + wnd_main.setObjectName(_fromUtf8("wnd_main")) + wnd_main.resize(700, 500) + wnd_main.setMinimumSize(QtCore.QSize(700, 500)) + wnd_main.setWindowTitle(QtGui.QApplication.translate("wnd_main", "E-learning", None, QtGui.QApplication.UnicodeUTF8)) + wnd_main.setToolTip(_fromUtf8("")) + wnd_main.setWhatsThis(_fromUtf8("")) + self.centralwidget = QtGui.QWidget(wnd_main) + self.centralwidget.setObjectName(_fromUtf8("centralwidget")) + self.horizontalLayout_4 = QtGui.QHBoxLayout(self.centralwidget) + self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4")) + self.vlt_all = QtGui.QVBoxLayout() + self.vlt_all.setObjectName(_fromUtf8("vlt_all")) + self.hlt_canvas_session_formula = QtGui.QHBoxLayout() + self.hlt_canvas_session_formula.setObjectName(_fromUtf8("hlt_canvas_session_formula")) + self.btn_canvas_session = QtGui.QPushButton(self.centralwidget) + self.btn_canvas_session.setText(QtGui.QApplication.translate("wnd_main", "Canvas session", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_canvas_session.setCheckable(True) + self.btn_canvas_session.setChecked(True) + self.btn_canvas_session.setAutoDefault(False) + self.btn_canvas_session.setDefault(False) + self.btn_canvas_session.setFlat(False) + self.btn_canvas_session.setObjectName(_fromUtf8("btn_canvas_session")) + self.hlt_canvas_session_formula.addWidget(self.btn_canvas_session) + self.vlt_formula = QtGui.QVBoxLayout() + self.vlt_formula.setObjectName(_fromUtf8("vlt_formula")) + self.lab_insert_formula = QtGui.QLabel(self.centralwidget) + self.lab_insert_formula.setText(QtGui.QApplication.translate("wnd_main", "Insert formula:", None, QtGui.QApplication.UnicodeUTF8)) + self.lab_insert_formula.setObjectName(_fromUtf8("lab_insert_formula")) + self.vlt_formula.addWidget(self.lab_insert_formula) + self.eln_insert_formula = QtGui.QLineEdit(self.centralwidget) + self.eln_insert_formula.setObjectName(_fromUtf8("eln_insert_formula")) + self.vlt_formula.addWidget(self.eln_insert_formula) + self.hlt_canvas_session_formula.addLayout(self.vlt_formula) + self.btn_insert_formula = QtGui.QPushButton(self.centralwidget) + self.btn_insert_formula.setText(QtGui.QApplication.translate("wnd_main", "Insert", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_insert_formula.setObjectName(_fromUtf8("btn_insert_formula")) + self.hlt_canvas_session_formula.addWidget(self.btn_insert_formula) + self.vlt_all.addLayout(self.hlt_canvas_session_formula) + self.hlt_canvas_menu_buttons = QtGui.QHBoxLayout() + self.hlt_canvas_menu_buttons.setObjectName(_fromUtf8("hlt_canvas_menu_buttons")) + self.vlt_menu_buttons = QtGui.QVBoxLayout() + self.vlt_menu_buttons.setObjectName(_fromUtf8("vlt_menu_buttons")) + self.btn_color = QtGui.QPushButton(self.centralwidget) + self.btn_color.setText(QtGui.QApplication.translate("wnd_main", "Color", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_color.setCheckable(False) + self.btn_color.setObjectName(_fromUtf8("btn_color")) + self.vlt_menu_buttons.addWidget(self.btn_color) + self.btn_size = QtGui.QPushButton(self.centralwidget) + self.btn_size.setText(QtGui.QApplication.translate("wnd_main", "Size", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_size.setObjectName(_fromUtf8("btn_size")) + self.vlt_menu_buttons.addWidget(self.btn_size) + self.btn_clear = QtGui.QPushButton(self.centralwidget) + self.btn_clear.setText(QtGui.QApplication.translate("wnd_main", "Clear", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_clear.setObjectName(_fromUtf8("btn_clear")) + self.vlt_menu_buttons.addWidget(self.btn_clear) + self.btn_add = QtGui.QPushButton(self.centralwidget) + self.btn_add.setText(QtGui.QApplication.translate("wnd_main", "Add", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_add.setObjectName(_fromUtf8("btn_add")) + self.vlt_menu_buttons.addWidget(self.btn_add) + self.btn_undo = QtGui.QPushButton(self.centralwidget) + self.btn_undo.setText(QtGui.QApplication.translate("wnd_main", "Undo", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_undo.setObjectName(_fromUtf8("btn_undo")) + self.vlt_menu_buttons.addWidget(self.btn_undo) + spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.vlt_menu_buttons.addItem(spacerItem) + self.hlt_canvas_menu_buttons.addLayout(self.vlt_menu_buttons) + self.graphicsView = QtGui.QGraphicsView(self.centralwidget) + self.graphicsView.setObjectName(_fromUtf8("graphicsView")) + self.hlt_canvas_menu_buttons.addWidget(self.graphicsView) + self.vlt_all.addLayout(self.hlt_canvas_menu_buttons) + self.hlt_audio_save = QtGui.QHBoxLayout() + self.hlt_audio_save.setObjectName(_fromUtf8("hlt_audio_save")) + self.btn_audio_session = QtGui.QPushButton(self.centralwidget) + self.btn_audio_session.setText(QtGui.QApplication.translate("wnd_main", "Audio session", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_audio_session.setCheckable(True) + self.btn_audio_session.setObjectName(_fromUtf8("btn_audio_session")) + self.hlt_audio_save.addWidget(self.btn_audio_session) + self.btn_mute = QtGui.QPushButton(self.centralwidget) + self.btn_mute.setText(QtGui.QApplication.translate("wnd_main", "Mute", None, QtGui.QApplication.UnicodeUTF8)) + self.btn_mute.setCheckable(True) + self.btn_mute.setObjectName(_fromUtf8("btn_mute")) + self.hlt_audio_save.addWidget(self.btn_mute) + spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.hlt_audio_save.addItem(spacerItem1) + self.vlt_all.addLayout(self.hlt_audio_save) + self.horizontalLayout_4.addLayout(self.vlt_all) + wnd_main.setCentralWidget(self.centralwidget) + self.menubar = QtGui.QMenuBar(wnd_main) + self.menubar.setGeometry(QtCore.QRect(0, 0, 700, 26)) + self.menubar.setObjectName(_fromUtf8("menubar")) + self.men_options = QtGui.QMenu(self.menubar) + self.men_options.setTitle(QtGui.QApplication.translate("wnd_main", "Options", None, QtGui.QApplication.UnicodeUTF8)) + self.men_options.setObjectName(_fromUtf8("men_options")) + self.men_help = QtGui.QMenu(self.menubar) + self.men_help.setTitle(QtGui.QApplication.translate("wnd_main", "Help", None, QtGui.QApplication.UnicodeUTF8)) + self.men_help.setObjectName(_fromUtf8("men_help")) + self.men_file = QtGui.QMenu(self.menubar) + self.men_file.setTitle(QtGui.QApplication.translate("wnd_main", "File", None, QtGui.QApplication.UnicodeUTF8)) + self.men_file.setObjectName(_fromUtf8("men_file")) + self.men_save_as = QtGui.QMenu(self.men_file) + self.men_save_as.setTitle(QtGui.QApplication.translate("wnd_main", "Save As", None, QtGui.QApplication.UnicodeUTF8)) + self.men_save_as.setObjectName(_fromUtf8("men_save_as")) + wnd_main.setMenuBar(self.menubar) + self.stb_main = QtGui.QStatusBar(wnd_main) + self.stb_main.setObjectName(_fromUtf8("stb_main")) + wnd_main.setStatusBar(self.stb_main) + self.act_color = QtGui.QAction(wnd_main) + self.act_color.setText(QtGui.QApplication.translate("wnd_main", "Color", None, QtGui.QApplication.UnicodeUTF8)) + self.act_color.setShortcut(QtGui.QApplication.translate("wnd_main", "C", None, QtGui.QApplication.UnicodeUTF8)) + self.act_color.setObjectName(_fromUtf8("act_color")) + self.act_size = QtGui.QAction(wnd_main) + self.act_size.setText(QtGui.QApplication.translate("wnd_main", "Size", None, QtGui.QApplication.UnicodeUTF8)) + self.act_size.setShortcut(QtGui.QApplication.translate("wnd_main", "S", None, QtGui.QApplication.UnicodeUTF8)) + self.act_size.setObjectName(_fromUtf8("act_size")) + self.act_add = QtGui.QAction(wnd_main) + self.act_add.setText(QtGui.QApplication.translate("wnd_main", "Add", None, QtGui.QApplication.UnicodeUTF8)) + self.act_add.setShortcut(QtGui.QApplication.translate("wnd_main", "A", None, QtGui.QApplication.UnicodeUTF8)) + self.act_add.setObjectName(_fromUtf8("act_add")) + self.act_undo = QtGui.QAction(wnd_main) + self.act_undo.setText(QtGui.QApplication.translate("wnd_main", "Undo", None, QtGui.QApplication.UnicodeUTF8)) + self.act_undo.setShortcut(QtGui.QApplication.translate("wnd_main", "U", None, QtGui.QApplication.UnicodeUTF8)) + self.act_undo.setObjectName(_fromUtf8("act_undo")) + self.act_settings = QtGui.QAction(wnd_main) + self.act_settings.setText(QtGui.QApplication.translate("wnd_main", "Settings", None, QtGui.QApplication.UnicodeUTF8)) + self.act_settings.setShortcut(QtGui.QApplication.translate("wnd_main", "S", None, QtGui.QApplication.UnicodeUTF8)) + self.act_settings.setObjectName(_fromUtf8("act_settings")) + self.act_clear = QtGui.QAction(wnd_main) + self.act_clear.setText(QtGui.QApplication.translate("wnd_main", "Clear", None, QtGui.QApplication.UnicodeUTF8)) + self.act_clear.setShortcut(QtGui.QApplication.translate("wnd_main", "L", None, QtGui.QApplication.UnicodeUTF8)) + self.act_clear.setObjectName(_fromUtf8("act_clear")) + self.act_jpg = QtGui.QAction(wnd_main) + self.act_jpg.setText(QtGui.QApplication.translate("wnd_main", ".jpg", None, QtGui.QApplication.UnicodeUTF8)) + self.act_jpg.setObjectName(_fromUtf8("act_jpg")) + self.act_bmp = QtGui.QAction(wnd_main) + self.act_bmp.setText(QtGui.QApplication.translate("wnd_main", ".bmp", None, QtGui.QApplication.UnicodeUTF8)) + self.act_bmp.setObjectName(_fromUtf8("act_bmp")) + self.men_options.addAction(self.act_color) + self.men_options.addAction(self.act_size) + self.men_options.addAction(self.act_clear) + self.men_options.addAction(self.act_add) + self.men_options.addAction(self.act_undo) + self.men_options.addSeparator() + self.men_options.addAction(self.act_settings) + self.men_save_as.addAction(self.act_jpg) + self.men_save_as.addAction(self.act_bmp) + self.men_file.addAction(self.men_save_as.menuAction()) + self.menubar.addAction(self.men_file.menuAction()) + self.menubar.addAction(self.men_options.menuAction()) + self.menubar.addAction(self.men_help.menuAction()) + + self.retranslateUi(wnd_main) + QtCore.QMetaObject.connectSlotsByName(wnd_main) + wnd_main.setTabOrder(self.btn_canvas_session, self.eln_insert_formula) + wnd_main.setTabOrder(self.eln_insert_formula, self.btn_insert_formula) + wnd_main.setTabOrder(self.btn_insert_formula, self.btn_color) + wnd_main.setTabOrder(self.btn_color, self.btn_size) + wnd_main.setTabOrder(self.btn_size, self.btn_clear) + wnd_main.setTabOrder(self.btn_clear, self.btn_add) + wnd_main.setTabOrder(self.btn_add, self.btn_undo) + wnd_main.setTabOrder(self.btn_undo, self.btn_audio_session) + wnd_main.setTabOrder(self.btn_audio_session, self.btn_mute) + wnd_main.setTabOrder(self.btn_mute, self.graphicsView) + + def retranslateUi(self, wnd_main): + pass + diff --git a/test/project_with_gr.ui b/test/project_with_gr.ui new file mode 100644 index 0000000..062a94b --- /dev/null +++ b/test/project_with_gr.ui @@ -0,0 +1,330 @@ + + + wnd_main + + + + 0 + 0 + 700 + 500 + + + + + 700 + 500 + + + + E-learning + + + + + + + + + + + + + + + + + Canvas session + + + true + + + true + + + false + + + false + + + false + + + + + + + + + Insert formula: + + + + + + + + + + + + Insert + + + + + + + + + + + + + + 70 + 16777215 + + + + Color + + + false + + + + + + + + 70 + 16777215 + + + + Size + + + + + + + + 70 + 16777215 + + + + Clear + + + + + + + + 70 + 16777215 + + + + Add + + + + + + + + 70 + 16777215 + + + + Undo + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + Audio session + + + true + + + + + + + Mute + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 0 + 0 + 700 + 26 + + + + + Options + + + + + + + + + + + + Help + + + + + File + + + + Save As + + + + + + + + + + + + + + Color + + + C + + + + + Size + + + S + + + + + Add + + + A + + + + + Undo + + + U + + + + + Settings + + + S + + + + + Clear + + + L + + + + + .jpg + + + + + .bmp + + + + + btn_canvas_session + eln_insert_formula + btn_insert_formula + btn_color + btn_size + btn_clear + btn_add + btn_undo + btn_audio_session + btn_mute + graphicsView + + + + diff --git a/test/test.py b/test/test.py new file mode 100644 index 0000000..13baa03 --- /dev/null +++ b/test/test.py @@ -0,0 +1,369 @@ +#!/usr/bin/env python + + +############################################################################# +## +## Copyright (C) 2010 Riverbank Computing Limited. +## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +## All rights reserved. +## +## This file is part of the examples of PyQt. +## +## $QT_BEGIN_LICENSE:BSD$ +## You may use this file under the terms of the BSD license as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +## the names of its contributors may be used to endorse or promote +## products derived from this software without specific prior written +## permission. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## $QT_END_LICENSE$ +## +############################################################################# + + +# These are only needed for Python v2 but are harmless for Python v3. +import sip +sip.setapi('QString', 2) +sip.setapi('QVariant', 2) + +from PyQt4 import QtCore, QtGui + + +class ScribbleArea(QtGui.QWidget): + """ + this scales the image but it's not good, too many refreshes really mess it up!!! + """ + def __init__(self, parent=None): + super(ScribbleArea, self).__init__(parent) + + self.setAttribute(QtCore.Qt.WA_StaticContents) + self.modified = False + self.scribbling = False + self.myPenWidth = 1 + self.myPenColor = QtCore.Qt.blue + imageSize = QtCore.QSize(500, 500) +# self.image = QtGui.QImage() + self.image = QtGui.QImage(imageSize, QtGui.QImage.Format_RGB32) + self.lastPoint = QtCore.QPoint() + + def openImage(self, fileName): + loadedImage = QtGui.QImage() + if not loadedImage.load(fileName): + return False + + w = loadedImage.width() + h = loadedImage.height() + self.mainWindow.resize(w, h) + +# newSize = loadedImage.size().expandedTo(self.size()) +# self.resizeImage(loadedImage, newSize) + self.image = loadedImage + self.modified = False + self.update() + return True + + def saveImage(self, fileName, fileFormat): + visibleImage = self.image + self.resizeImage(visibleImage, self.size()) + + if visibleImage.save(fileName, fileFormat): + self.modified = False + return True + else: + return False + + def setPenColor(self, newColor): + self.myPenColor = newColor + + def setPenWidth(self, newWidth): + self.myPenWidth = newWidth + + def clearImage(self): + self.image.fill(QtGui.qRgb(255, 255, 255)) + self.modified = True + self.update() + + def mousePressEvent(self, event): +# print "self.image.width() = %d" % self.image.width() +# print "self.image.height() = %d" % self.image.height() +# print "self.image.size() = %s" % self.image.size() +# print "self.size() = %s" % self.size() +# print "event.pos() = %s" % event.pos() + if event.button() == QtCore.Qt.LeftButton: + self.lastPoint = event.pos() + self.scribbling = True + + def mouseMoveEvent(self, event): + if (event.buttons() & QtCore.Qt.LeftButton) and self.scribbling: + self.drawLineTo(event.pos()) + + def mouseReleaseEvent(self, event): + if event.button() == QtCore.Qt.LeftButton and self.scribbling: + self.drawLineTo(event.pos()) + self.scribbling = False + + def paintEvent(self, event): + painter = QtGui.QPainter(self) + painter.drawImage(event.rect(), self.image) + + def resizeEvent(self, event): +# print "resize event" +# print "event = %s" % event +# print "event.oldSize() = %s" % event.oldSize() +# print "event.size() = %s" % event.size() + + self.resizeImage(self.image, event.size()) + +# if self.width() > self.image.width() or self.height() > self.image.height(): +# newWidth = max(self.width() + 128, self.image.width()) +# newHeight = max(self.height() + 128, self.image.height()) +# print "newWidth = %d, newHeight = %d" % (newWidth, newHeight) +# self.resizeImage(self.image, QtCore.QSize(newWidth, newHeight)) +# self.update() + + super(ScribbleArea, self).resizeEvent(event) + + def drawLineTo(self, endPoint): + painter = QtGui.QPainter(self.image) + painter.setPen(QtGui.QPen(self.myPenColor, self.myPenWidth, + QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) + painter.drawLine(self.lastPoint, endPoint) + self.modified = True + + # rad = self.myPenWidth / 2 + 2 + # self.update(QtCore.QRect(self.lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad)) + self.update() + self.lastPoint = QtCore.QPoint(endPoint) + + def resizeImage(self, image, newSize): + if image.size() == newSize: + return + +# print "image.size() = %s" % repr(image.size()) +# print "newSize = %s" % newSize + +# this resizes the canvas without resampling the image + newImage = QtGui.QImage(newSize, QtGui.QImage.Format_RGB32) + newImage.fill(QtGui.qRgb(255, 255, 255)) + painter = QtGui.QPainter(newImage) + painter.drawImage(QtCore.QPoint(0, 0), image) + + +## this resampled the image but it gets messed up with so many events... +## painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform, True) +## painter.setRenderHint(QtGui.QPainter.HighQualityAntialiasing, True) +# +# newImage = QtGui.QImage(newSize, QtGui.QImage.Format_RGB32) +# newImage.fill(QtGui.qRgb(255, 255, 255)) +# painter = QtGui.QPainter(newImage) +# srcRect = QtCore.QRect(QtCore.QPoint(0,0), image.size()) +# dstRect = QtCore.QRect(QtCore.QPoint(0,0), newSize) +## print "srcRect = %s" % srcRect +## print "dstRect = %s" % dstRect +# painter.drawImage(dstRect, image, srcRect) + + + self.image = newImage + + def print_(self): + printer = QtGui.QPrinter(QtGui.QPrinter.HighResolution) + + printDialog = QtGui.QPrintDialog(printer, self) + if printDialog.exec_() == QtGui.QDialog.Accepted: + painter = QtGui.QPainter(printer) + rect = painter.viewport() + size = self.image.size() + size.scale(rect.size(), QtCore.Qt.KeepAspectRatio) + painter.setViewport(rect.x(), rect.y(), size.width(), size.height()) + painter.setWindow(self.image.rect()) + painter.drawImage(0, 0, self.image) + painter.end() + + def isModified(self): + return self.modified + + def penColor(self): + return self.myPenColor + + def penWidth(self): + return self.myPenWidth + + +class MainWindow(QtGui.QMainWindow): + def __init__(self): + super(MainWindow, self).__init__() + + self.saveAsActs = [] + + self.scribbleArea = ScribbleArea(self) + self.scribbleArea.clearImage() + self.scribbleArea.mainWindow = self # maybe not using this? + self.setCentralWidget(self.scribbleArea) + + self.createActions() + self.createMenus() + + self.setWindowTitle("Scribble") + self.resize(500, 500) + + def closeEvent(self, event): + if self.maybeSave(): + event.accept() + else: + event.ignore() + + def open(self): + if self.maybeSave(): + fileName = QtGui.QFileDialog.getOpenFileName(self, "Open File", + QtCore.QDir.currentPath()) + if fileName: + self.scribbleArea.openImage(fileName) + + def save(self): + #action = self.sender() + #fileFormat = action.data() + #self.saveFile(fileFormat) + action = self.sender().data() + self.saveFile(action) + + def penColor(self): + newColor = QtGui.QColorDialog.getColor(self.scribbleArea.penColor()) + if newColor.isValid(): + self.scribbleArea.setPenColor(newColor) + + def penWidth(self): + newWidth, ok = QtGui.QInputDialog.getInteger(self, "Scribble", + "Select pen width:", self.scribbleArea.penWidth(), 1, 50, 1) + if ok: + self.scribbleArea.setPenWidth(newWidth) + + def about(self): + QtGui.QMessageBox.about(self, "About Scribble", + "

The Scribble example shows how to use " + "QMainWindow as the base widget for an application, and how " + "to reimplement some of QWidget's event handlers to receive " + "the events generated for the application's widgets:

" + "

We reimplement the mouse event handlers to facilitate " + "drawing, the paint event handler to update the application " + "and the resize event handler to optimize the application's " + "appearance. In addition we reimplement the close event " + "handler to intercept the close events before terminating " + "the application.

" + "

The example also demonstrates how to use QPainter to " + "draw an image in real time, as well as to repaint " + "widgets.

") + + def createActions(self): + self.openAct = QtGui.QAction("&Open...", self, shortcut="Ctrl+O", + triggered=self.open) + + for format in QtGui.QImageWriter.supportedImageFormats(): + format = str(format) + + text = format.upper() + "..." + + action = QtGui.QAction(text, self, triggered=self.save) + action.setData(format) + self.saveAsActs.append(action) + + self.printAct = QtGui.QAction("&Print...", self, + triggered=self.scribbleArea.print_) + + self.exitAct = QtGui.QAction("E&xit", self, shortcut="Ctrl+Q", + triggered=self.close) + + self.penColorAct = QtGui.QAction("&Pen Color...", self, + triggered=self.penColor) + + self.penWidthAct = QtGui.QAction("Pen &Width...", self, + triggered=self.penWidth) + + self.clearScreenAct = QtGui.QAction("&Clear Screen", self, + shortcut="Ctrl+L", triggered=self.scribbleArea.clearImage) + + self.aboutAct = QtGui.QAction("&About", self, triggered=self.about) + + self.aboutQtAct = QtGui.QAction("About &Qt", self, + triggered=QtGui.qApp.aboutQt) + + def createMenus(self): + self.saveAsMenu = QtGui.QMenu("&Save As", self) + for action in self.saveAsActs: + self.saveAsMenu.addAction(action) + + fileMenu = QtGui.QMenu("&File", self) + fileMenu.addAction(self.openAct) + fileMenu.addMenu(self.saveAsMenu) + fileMenu.addAction(self.printAct) + fileMenu.addSeparator() + fileMenu.addAction(self.exitAct) + + optionMenu = QtGui.QMenu("&Options", self) + optionMenu.addAction(self.penColorAct) + optionMenu.addAction(self.penWidthAct) + optionMenu.addSeparator() + optionMenu.addAction(self.clearScreenAct) + + helpMenu = QtGui.QMenu("&Help", self) + helpMenu.addAction(self.aboutAct) + helpMenu.addAction(self.aboutQtAct) + + self.menuBar().addMenu(fileMenu) + self.menuBar().addMenu(optionMenu) + self.menuBar().addMenu(helpMenu) + + def maybeSave(self): + if self.scribbleArea.isModified(): + ret = QtGui.QMessageBox.warning(self, "Scribble", + "The image has been modified.\n" + "Do you want to save your changes?", + QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | + QtGui.QMessageBox.Cancel) + if ret == QtGui.QMessageBox.Save: + return self.saveFile('png') + elif ret == QtGui.QMessageBox.Cancel: + return False + + return True + + def saveFile(self, fileFormat): + initialPath = QtCore.QDir.currentPath() + '/untitled.' + fileFormat + + fileName = QtGui.QFileDialog.getSaveFileName(self, "Save As", + initialPath, + "%s Files (*.%s);;All Files (*)" % (fileFormat.upper(), fileFormat)) + if fileName: + return self.scribbleArea.saveImage(fileName, fileFormat) + + return False + + +if __name__ == '__main__': + + import sys + + app = QtGui.QApplication(sys.argv) + window = MainWindow() + window.show() + sys.exit(app.exec_()) diff --git a/v/load_interface.py b/v/load_interface.py new file mode 100644 index 0000000..df7356b --- /dev/null +++ b/v/load_interface.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python + +# These are only needed for Python v2 but are harmless for Python v3 +import sip +sip.setapi('QString', 2) +sip.setapi('QVariant', 2) + +import sys +from PyQt4 import QtCore, QtGui, uic + + +class ScribbleArea(QtGui.QWidget): + """ + class adds QImage to MyMainWindow, overrides parent's event functions + """ + def __init__(self, parent=None): + super(ScribbleArea, self).__init__(parent) + + self.setAttribute(QtCore.Qt.WA_StaticContents) + + self.modified = False + self.scribbling = False + + self.myPenWidth = 2 + self.myPenColor = QtGui.QColor(0, 85, 255) #QtCore.Qt.blue + + imageSize = QtCore.QSize() + self.image = QtGui.QImage(imageSize, QtGui.QImage.Format_RGB32) + self.lastPoint = QtCore.QPoint() + + def saveImage(self, fileName, fileFormat): + # saves visible image + visibleImage = self.image + self.resizeImage(visibleImage, self.size()) + + if visibleImage.save(fileName, fileFormat): + self.modified = False + return True + else: + return False + + def mousePressEvent(self, event): +# print "self.image.width() = %d" % self.image.width() +# print "self.image.height() = %d" % self.image.height() +# print "self.image.size() = %s" % self.image.size() +# print "self.size() = %s" % self.size() +# print "event.pos() = %s" % event.pos() + if event.button() == QtCore.Qt.LeftButton: + self.lastPoint = event.pos() + self.scribbling = True + + def mouseMoveEvent(self, event): + if (event.buttons() & QtCore.Qt.LeftButton) and self.scribbling: + self.drawLineTo(event.pos()) + print "event.pos() = ", event.x(), " ", event.y(), "-", \ + self.myPenWidth, "-", \ + self.myPenColor.red(), " ", \ + self.myPenColor.green(), " ", self.myPenColor.blue() + + def mouseReleaseEvent(self, event): + if event.button() == QtCore.Qt.LeftButton and self.scribbling: + self.drawLineTo(event.pos()) + self.scribbling = False + + def paintEvent(self, event): + painter = QtGui.QPainter(self) + painter.drawImage(event.rect(), self.image) + + def resizeEvent(self, event): + self.resizeImage(self.image, event.size()) + + super(ScribbleArea, self).resizeEvent(event) + + def resizeImage(self, image, newSize): + if image.size() == newSize: + return + + newImage = QtGui.QImage(newSize, QtGui.QImage.Format_RGB32) + newImage.fill(QtGui.qRgb(255, 255, 255)) + painter = QtGui.QPainter(newImage) + painter.drawImage(QtCore.QPoint(0, 0), image) + #painter.drawImage(0, 0, image, 900, 900) + + self.image = newImage + + def drawLineTo(self, endPoint): + painter = QtGui.QPainter(self.image) + painter.setPen(QtGui.QPen(self.myPenColor, self.myPenWidth, + QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) + painter.drawLine(self.lastPoint, endPoint) + self.modified = True + + self.update() + self.lastPoint = QtCore.QPoint(endPoint) + + def isModified(self): + return self.modified + + def penColor(self): + return self.myPenColor + + def penWidth(self): + return self.myPenWidth + + def setPenColor(self, newColor): + self.myPenColor = newColor + + def setPenWidth(self, newWidth): + self.myPenWidth = newWidth + + +class MyMainWindow(QtGui.QMainWindow): + """ + class for loading and extending .ui file generated in Qt Designer; + has basic functionality of interface + """ + def __init__(self, parent=None): + super(MyMainWindow, self).__init__(parent) + + self.saveAsActs = [] + + # loading .ui + uic.loadUi('project.ui', self) + + # ading QImage + self.scribbleArea = ScribbleArea(self) + self.clearImage() + """ + self.scrollArea = QtGui.QScrollArea() + self.scrollArea.setBackgroundRole(QtGui.QPalette.Dark) + self.scrollArea.setWidget(self.scribbleArea) + """ + self.hlt_canvas_menu_buttons.addWidget(self.scribbleArea) + + # connect functions + self.connect(self.btn_clear, QtCore.SIGNAL('clicked()'), self.clearImage) + self.connect(self.btn_color, QtCore.SIGNAL('clicked()'), self.penColor) + self.connect(self.btn_size, QtCore.SIGNAL('clicked()'), self.penWidth) + + # create menu bar + self.createActions() + self.createMenus() + + def penColor(self): + # opens dialog to change pen color + newColor = QtGui.QColorDialog.getColor(self.scribbleArea.penColor()) + if newColor.isValid(): + self.scribbleArea.setPenColor(newColor) + + def penWidth(self): + # opens dialog to change pen width + newWidth, ok = QtGui.QInputDialog.getInteger(self, "E-learning", + "Select pen width:", self.scribbleArea.penWidth(), 1, 50, 1) + if ok: + self.scribbleArea.setPenWidth(newWidth) + + def clearImage(self): + # clears image + self.scribbleArea.image.fill(QtGui.qRgb(255, 255, 255)) + self.scribbleArea.modified = True + self.scribbleArea.update() + + def saveFile(self): + # opens dialog to save file with selected file type + fileFormat = self.sender().data() + initialPath = QtCore.QDir.currentPath() + '/untitled.' + fileFormat + fileName = QtGui.QFileDialog.getSaveFileName(self, "Save As", initialPath, + "%s Files (*.%s);;All Files (*)" % (fileFormat.upper(), fileFormat)) + + if fileName: + return self.scribbleArea.saveImage(fileName, fileFormat) + + return False + + def createActions(self): + # creates sub menus + for format in QtGui.QImageWriter.supportedImageFormats(): + format = str(format) + + text = "." + format.lower() + + action = QtGui.QAction(text, self, triggered=self.saveFile) + action.setData(format) + self.saveAsActs.append(action) + + self.exitAct = QtGui.QAction("E&xit", self, shortcut="Ctrl+Q", + triggered=self.close) + + def createMenus(self): + # creates menus + self.saveAsMenu = QtGui.QMenu("&Save As", self) + for action in self.saveAsActs: + self.saveAsMenu.addAction(action) + + fileMenu = QtGui.QMenu("&File", self) + fileMenu.addMenu(self.saveAsMenu) + fileMenu.addAction(self.exitAct) + + helpMenu = QtGui.QMenu("&Help", self) + self.menuBar().addMenu(fileMenu) + self.menuBar().addMenu(helpMenu) + + + +if __name__ == "__main__": + app = QtGui.QApplication(sys.argv) + myApp = MyMainWindow() + myApp.show() + sys.exit(app.exec_()) diff --git a/v/project.ui b/v/project.ui new file mode 100644 index 0000000..88d09fd --- /dev/null +++ b/v/project.ui @@ -0,0 +1,293 @@ + + + wnd_main + + + + 0 + 0 + 700 + 500 + + + + + 700 + 500 + + + + E-learning + + + + + + + + + + + + + + + + + Canvas session + + + true + + + true + + + false + + + false + + + false + + + + + + + + + Insert formula: + + + + + + + + + + + + Insert + + + + + + + + + + + + + + 70 + 16777215 + + + + Color + + + false + + + + + + + + 70 + 16777215 + + + + Size + + + + + + + + 70 + 16777215 + + + + Clear + + + + + + + + 70 + 16777215 + + + + Add + + + + + + + + 70 + 16777215 + + + + Undo + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + Audio session + + + true + + + + + + + Mute + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 0 + 0 + 700 + 26 + + + + + + + Color + + + C + + + + + Size + + + S + + + + + Add + + + A + + + + + Undo + + + U + + + + + Settings + + + S + + + + + Clear + + + L + + + + + .jpg + + + + + .bmp + + + + + btn_canvas_session + eln_insert_formula + btn_insert_formula + btn_color + btn_size + btn_clear + btn_add + btn_undo + btn_audio_session + btn_mute + + + +