Re-Created branch form 0, to avoid conflicts

This commit is contained in:
Jose Luis Cercos Pita
2012-10-28 19:54:09 +01:00
committed by wmayer
parent 6c21b74b4b
commit d7c5054c14
42 changed files with 7824 additions and 1 deletions

View File

@@ -0,0 +1,223 @@
#***************************************************************************
#* *
#* Copyright (c) 2011, 2012 *
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* 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 Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
# FreeCAD modules
import FreeCAD as App
import FreeCADGui as Gui
# Qt library
from PyQt4 import QtGui,QtCore
# Module
import Plot
from plotUtils import Paths, Translator
class TaskPanel:
def __init__(self):
self.ui = Paths.modulePath() + "/plotPositions/TaskPanel.ui"
self.skip = False
self.item = 0
self.names = []
self.objs = []
self.plt = None
def accept(self):
return True
def reject(self):
return True
def clicked(self, index):
pass
def open(self):
pass
def needsFullSpace(self):
return True
def isAllowedAlterSelection(self):
return False
def isAllowedAlterView(self):
return True
def isAllowedAlterDocument(self):
return False
def helpRequested(self):
pass
def setupUi(self):
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.items = form.findChild(QtGui.QListWidget, "items")
form.x = form.findChild(QtGui.QDoubleSpinBox, "x")
form.y = form.findChild(QtGui.QDoubleSpinBox, "y")
form.s = form.findChild(QtGui.QDoubleSpinBox, "size")
self.form = form
self.retranslateUi()
self.updateUI()
QtCore.QObject.connect(form.items, QtCore.SIGNAL("currentRowChanged(int)"),self.onItem)
QtCore.QObject.connect(form.x, QtCore.SIGNAL("valueChanged(double)"),self.onData)
QtCore.QObject.connect(form.y, QtCore.SIGNAL("valueChanged(double)"),self.onData)
QtCore.QObject.connect(form.s, QtCore.SIGNAL("valueChanged(double)"),self.onData)
QtCore.QObject.connect(Plot.getMdiArea(),QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"),self.onMdiArea)
return False
def getMainWindow(self):
"returns the main window"
# using QtGui.qApp.activeWindow() isn't very reliable because if another
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
# returned
toplevel = QtGui.qApp.topLevelWidgets()
for i in toplevel:
if i.metaObject().className() == "Gui::MainWindow":
return i
raise Exception("No main window found")
def retranslateUi(self):
""" Set user interface locale strings.
"""
self.form.setWindowTitle(Translator.translate("Set positions and sizes"))
self.form.findChild(QtGui.QLabel, "posLabel").setText(Translator.translate("Position"))
self.form.findChild(QtGui.QLabel, "sizeLabel").setText(Translator.translate("Size"))
def onItem(self, row):
""" Executed when selected item is modified. """
# Get selected item
self.item = row
# Call to update
self.updateUI()
def onData(self, value):
""" Executed when selected item data is modified. """
plt = Plot.getPlot()
if not plt:
self.updateUI()
return
if not self.skip:
self.skip = True
name = self.names[self.item]
obj = self.objs[self.item]
x = self.form.x.value()
y = self.form.y.value()
s = self.form.s.value()
# x/y labels only have one position control
if name.find('x label') >= 0:
self.form.y.setValue(x)
elif name.find('y label') >= 0:
self.form.x.setValue(y)
# title and labels only have one size control
if name.find('title') >= 0 or name.find('label') >= 0:
obj.set_position((x,y))
obj.set_size(s)
# legend have all controls
else:
Plot.legend(plt.legend, (x,y), s)
plt.update()
self.skip = False
def onMdiArea(self, subWin):
""" Executed when window is selected on mdi area.
@param subWin Selected window.
"""
plt = Plot.getPlot()
if plt != subWin:
self.updateUI()
def updateUI(self):
""" Setup UI controls values if possible """
plt = Plot.getPlot()
self.form.items.setEnabled(bool(plt))
self.form.x.setEnabled(bool(plt))
self.form.y.setEnabled(bool(plt))
self.form.s.setEnabled(bool(plt))
if not plt:
self.plt = plt
self.form.items.clear()
return
# Refill items list only if Plot instance have been changed
if self.plt != plt:
self.plt = plt
self.plt.update() # Update plot in order to put legend in correct place
self.setList()
# Get data for controls
name = self.names[self.item]
obj = self.objs[self.item]
if name.find('title') >= 0 or name.find('label') >= 0:
p = obj.get_position()
x = p[0]
y = p[1]
s = obj.get_size()
if name.find('x label') >= 0:
self.form.y.setEnabled(False)
self.form.y.setValue(x)
elif name.find('y label') >= 0:
self.form.x.setEnabled(False)
self.form.x.setValue(y)
else:
x = plt.legPos[0]
y = plt.legPos[1]
s = obj.get_texts()[-1].get_fontsize()
# Send it to controls
self.form.x.setValue(x)
self.form.y.setValue(y)
self.form.s.setValue(s)
def setList(self):
""" Setup UI controls values if possible """
# Clear lists
self.names = []
self.objs = []
# Fill lists with available objects
if self.plt:
# Axes data
for i in range(0,len(self.plt.axesList)):
ax = self.plt.axesList[i]
# Each axes have title, xaxis and yaxis
self.names.append('title (axes %d)' % (i))
self.objs.append(ax.title)
self.names.append('x label (axes %d)' % (i))
self.objs.append(ax.xaxis.get_label())
self.names.append('y label (axes %d)' % (i))
self.objs.append(ax.yaxis.get_label())
# Legend if exist
ax = self.plt.axesList[-1]
if ax.legend_:
self.names.append('legend')
self.objs.append(ax.legend_)
# Send list to widget
self.form.items.clear()
for name in self.names:
self.form.items.addItem(name)
# Ensure that selected item is correct
if self.item >= len(self.names):
self.item = len(self.names)-1
self.form.items.setCurrentIndex(self.item)
def createTask():
panel = TaskPanel()
Gui.Control.showDialog(panel)
if panel.setupUi():
Gui.Control.closeDialog(panel)
return None
return panel

View File

@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TaskPanel</class>
<widget class="QWidget" name="TaskPanel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>296</width>
<height>336</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>336</height>
</size>
</property>
<property name="windowTitle">
<string>Set positions and sizes</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListWidget" name="items">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="posLabel">
<property name="text">
<string>Position</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="x">
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QDoubleSpinBox" name="y">
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="sizeLabel">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="size">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>99999.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,36 @@
#***************************************************************************
#* *
#* Copyright (c) 2011, 2012 *
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* 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 Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
# FreeCAD modules
import FreeCAD
import FreeCADGui
# Qt libraries
from PyQt4 import QtGui,QtCore
# Main object
import TaskPanel
def load():
""" Loads the tool """
TaskPanel.createTask()