PyFlex  1.0
Riser cross section analysis
ui_mainwindow.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 
3 # Form implementation generated from reading ui file 'mainwindow.ui'
4 #
5 # Created: Thu Dec 29 13:22:05 2011
6 # by: pyside-uic 0.2.13 running on PySide 1.0.9
7 #
8 # WARNING! All changes made in this file will be lost!
9 
10 from PySide import QtCore, QtGui
11 
12 
13 class Ui_MainWindow(object):
14  def setupUi(self, MainWindow):
15  MainWindow.setObjectName("MainWindow")
16  MainWindow.resize(573, 468)
17  self.centralwidget = QtGui.QWidget(MainWindow)
18  self.centralwidget.setObjectName("centralwidget")
19  self.vboxlayout = QtGui.QVBoxLayout(self.centralwidget)
20  self.vboxlayout.setContentsMargins(0, 0, 0, 0)
21  self.vboxlayout.setSpacing(0)
22  self.vboxlayout.setObjectName("vboxlayout")
23  self.view = QtGui.QTreeView(self.centralwidget)
24  checkValues= ['to be updated','2b updt']
25  self.view.setEditTriggers(QtGui.QAbstractItemView.CurrentChanged)
26  self.view.setItemDelegate(ComboDelegate(self))
27  self.view.setAlternatingRowColors(True)
28  self.view.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems)
29  self.view.setHorizontalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel)
30  self.view.setAnimated(False)
31  self.view.setAllColumnsShowFocus(True)
32  self.view.setObjectName("view")
33  self.view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
34  self.view.setDragDropMode(QtGui.QAbstractItemView.DragOnly)
35  self.vboxlayout.addWidget(self.view)
36  MainWindow.setCentralWidget(self.centralwidget)
37  self.menubar = QtGui.QMenuBar(MainWindow)
38  self.menubar.setGeometry(QtCore.QRect(0, 0, 573, 31))
39  self.menubar.setObjectName("menubar")
40  self.fileMenu = QtGui.QMenu(self.menubar)
41  self.fileMenu.setObjectName("fileMenu")
42  self.importMenu = QtGui.QMenu(self.menubar)
43  self.importMenu.setObjectName("importMenu")
44  self.helpMenu = QtGui.QMenu(self.menubar)
45  self.helpMenu.setObjectName("helpMenu")
46  MainWindow.setMenuBar(self.menubar)
47  self.newAction = QtGui.QAction(MainWindow)
48  self.newAction.setObjectName("newAction")
49  self.openAction = QtGui.QAction(MainWindow)
50  self.openAction.setObjectName("openAction")
51  self.exitAction = QtGui.QAction(MainWindow)
52  self.exitAction.setObjectName("exitAction")
53  self.importAction = QtGui.QAction(MainWindow)
54  self.importAction.setObjectName("importAction")
55  self.importFolderAction = QtGui.QAction(MainWindow)
56  self.importFolderAction.setObjectName("importFolderAction")
57  self.aboutAction = QtGui.QAction(MainWindow)
58  self.aboutAction.setObjectName("aboutAction")
59  self.fileMenu.addAction(self.newAction)
60  self.fileMenu.addAction(self.openAction)
61  self.fileMenu.addAction(self.exitAction)
62  self.importMenu.addAction(self.importAction)
63  self.importMenu.addAction(self.importFolderAction)
64  self.helpMenu.addAction(self.aboutAction)
65  self.menubar.addAction(self.fileMenu.menuAction())
66  self.menubar.addAction(self.importMenu.menuAction())
67  self.menubar.addAction(self.helpMenu.menuAction())
68 
69  self.retranslateUi(MainWindow)
70  QtCore.QMetaObject.connectSlotsByName(MainWindow)
71 
72  # noinspection PyCallByClass
73  def retranslateUi(self, MainWindow):
74  MainWindow.setWindowTitle(
75  QtGui.QApplication.translate("MainWindow", "PyFlex", None, QtGui.QApplication.UnicodeUTF8))
76  MainWindow.setWindowIcon(QtGui.QIcon('../icons/logo_small.png'))
77  self.fileMenu.setTitle(
78  QtGui.QApplication.translate("MainWindow", "&File", None, QtGui.QApplication.UnicodeUTF8))
79  self.importMenu.setTitle(
80  QtGui.QApplication.translate("MainWindow", "&Import", None, QtGui.QApplication.UnicodeUTF8))
81  self.helpMenu.setTitle(
82  QtGui.QApplication.translate("MainWindow", "&Help", None, QtGui.QApplication.UnicodeUTF8))
83  self.newAction.setText(QtGui.QApplication.translate("MainWindow", "New", None, QtGui.QApplication.UnicodeUTF8))
84  self.newAction.setShortcut(
85  QtGui.QApplication.translate("MainWindow", "Ctrl+N", None, QtGui.QApplication.UnicodeUTF8))
86  self.openAction.setText(
87  QtGui.QApplication.translate("MainWindow", "Open", None, QtGui.QApplication.UnicodeUTF8))
88  self.openAction.setShortcut(
89  QtGui.QApplication.translate("MainWindow", "Ctrl+O", None, QtGui.QApplication.UnicodeUTF8))
90  self.exitAction.setText(
91  QtGui.QApplication.translate("MainWindow", "E&xit", None, QtGui.QApplication.UnicodeUTF8))
92  self.exitAction.setShortcut(
93  QtGui.QApplication.translate("MainWindow", "Ctrl+Q", None, QtGui.QApplication.UnicodeUTF8))
94  self.importAction.setText(
95  QtGui.QApplication.translate("MainWindow", "Import time series", None, QtGui.QApplication.UnicodeUTF8))
96  self.importAction.setShortcut(
97  QtGui.QApplication.translate("MainWindow", "Ctrl+I", None, QtGui.QApplication.UnicodeUTF8))
98  self.importFolderAction.setText(QtGui.QApplication.translate("MainWindow", "Import time series folder", None,
99  QtGui.QApplication.UnicodeUTF8))
100  self.importFolderAction.setShortcut(
101  QtGui.QApplication.translate("MainWindow", "Ctrl+Shift+I", None, QtGui.QApplication.UnicodeUTF8))
102  self.importFolderAction.setToolTip('Imports all tim files in folder')
103  self.importFolderAction.hovered.connect(self.handleMenuHovered)
104  self.aboutAction.setText(
105  QtGui.QApplication.translate("MainWindow", "About", None, QtGui.QApplication.UnicodeUTF8))
106 
107  def handleMenuHovered(self):
108  # noinspection PyArgumentList
109  QtGui.QToolTip.showText(
110  QtGui.QCursor.pos(), self.importFolderAction.toolTip(), self)
111 
112 
113 class GenericTreeModel(QtCore.QAbstractItemModel):
114  """Superclass for all tree models in the project
115 
116  List of methods that needs to be implemented when inherting this class:
117  flags, """
118 
119  def __init__(self, parent=None):
120  super(GenericTreeModel, self).__init__(parent)
121 
122  def columnCount(self, parent):
123  if parent.isValid():
124  return parent.internalPointer().columnCount()
125  else:
126  return self.rootItem.columnCount()
127 
128  def getItem(self, index):
129  """
130  Method for getting hold of the item from its index
131  :param index: the index of the item
132  :return:the pointer to the item itself
133  """
134  if index.isValid():
135  item = index.internalPointer()
136  if item:
137  return item
138 
139  return self.rootItem
140 
141  def data(self, index, role):
142  """ Do not know. called by the view to get hold of the data I believe
143  :param index: the index
144  :param role: the role
145  :return:the data in display friendly mode
146  """
147  if not index.isValid():
148  return None
149  if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
150  item = index.internalPointer()
151  return item.data(index.column())
152  elif role == QtCore.Qt.CheckStateRole:
153  return None
154  return None
155 
156  # noinspection PyUnresolvedReferences
157  def setData(self, index, value, role=QtCore.Qt.EditRole):
158  """
159  :param index: the index of the item queried
160  :param value: the new value of the data
161  :param role: which role the view queries. only EditRole relevant
162  :return: returns the result. Should be the data put into some item.
163  """
164  if role != QtCore.Qt.EditRole:
165  return False
166 
167  item = self.getItem(index)
168  result = item.setData(index.column(), value)
169 
170  if result:
171  self.dataChanged.emit(index, index)
172 
173  return result
174 
175  # noinspection PyMethodMayBeStatic
177  return QtCore.Qt.CopyAction | QtCore.Qt.MoveAction
178 
179  def headerData(self, section, orientation, role):
180  """
181  :param section: do not know
182  :param orientation: no idea
183  :param role: in which context the view queries info
184  :return:headers mode
185  """
186  if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
187  return self.rootItem.data(section)
188  return None
189 
190  def index(self, row, column, parent):
191  """
192  :param row: the row of the tree model
193  :param column: which column of the tree model
194  :param parent: the parent of the item
195  :return:the index of the item
196  """
197  if not self.hasIndex(row, column, parent):
198  return QtCore.QModelIndex()
199  if not parent.isValid():
200  parentItem = self.rootItem
201  else:
202  parentItem = parent.internalPointer()
203  childItem = parentItem.child(row)
204  if childItem:
205  return self.createIndex(row, column, childItem)
206  else:
207  return QtCore.QModelIndex()
208 
209  def parent(self, index):
210  """
211  :param index: the index oof the item
212  :return: the index of the parent of the item
213  """
214  if not index.isValid():
215  return QtCore.QModelIndex()
216  childItem = index.internalPointer()
217  parentItem = childItem.parent()
218  if parentItem == self.rootItem:
219  return QtCore.QModelIndex()
220  return self.createIndex(parentItem.row(), 0, parentItem)
221 
222  def removeRows(self, position, rows, parent=QtCore.QModelIndex()):
223  parentItem = self.getItem(parent)
224 
225  self.beginRemoveRows(parent, position, position + rows - 1)
226  success = parentItem.removeChildren(position, rows)
227  self.endRemoveRows()
228 
229  return success
230 
231  def rowCount(self, parent):
232  """ returns the number of children of the parent. sounds like it should return the number of rows in total...
233  :param parent: the parent of something.
234  :return:
235  """
236  if parent.column() > 0:
237  return 0
238  if not parent.isValid():
239  parentItem = self.rootItem
240  else:
241  parentItem = parent.internalPointer()
242  return parentItem.childCount()
243 
244  def insertRows(self, position, rows, parent=QtCore.QModelIndex()):
245  parentItem = self.getItem(parent)
246  self.beginInsertRows(parent, position, position + rows - 1)
247  success = parentItem.insertChildren(position, rows,
248  self.rootItem.columnCount())
249  self.endInsertRows()
250 
251  return success
252 
253 class ComboDelegate(QtGui.QStyledItemDelegate):
254  """
255  A delegate that places a fully functioning QComboBox in every
256  cell of the column to which it's applied
257  """
258  updateModelandDataSignal = QtCore.Signal()
259  def __init__(self, parent):
260  super(ComboDelegate,self).__init__(parent)
261 
262  def createEditor(self, parent, option, index):
263  item=index.model().getItem(index)
264  # enters here if the item has type. For now only
265  # valid for the layer type.
266  if hasattr(item,'type'):
267  if item.type=='combo' or item.type=='presslayer':
268  combo = QtGui.QComboBox(parent)
269  combo.addItems(item.options)
270  for i in range(len(item.options)):
271  if item.options[i] == item.data(1):
272  combo.setCurrentIndex(i)
273  self.connect(combo, QtCore.SIGNAL("currentIndexChanged(int)"), self, QtCore.SLOT("currentIndexChanged()"))
274  return combo
275 
276  return super(ComboDelegate,self).createEditor(parent, option,index)
277 
278  def setEditorData(self, editor, index):
279  editor.blockSignals(True)
280  item=index.model().getItem(index)
281  if hasattr(item,'type'):
282  if item.type=='combo' or item.type=='presslayer':
283  for i in range(len(item.options)):
284  if item.options[i]==item.data:
285  editor.setCurrentIndex(i)
286  else:
287  super(ComboDelegate,self).setEditorData(editor, index)
288 
289  def setModelData(self, editor, model, index):
290  item=index.model().getItem(index)
291  if hasattr(item,'type'):
292  if item.type=='combo' or item.type=='presslayer':
293  model.setData(index, editor.currentText())
294  self.updateModelandDataSignal.emit()
295  return
296  super(ComboDelegate,self).setModelData(editor, model, index)
297 
298 
299  @QtCore.Slot()
301  self.commitData.emit(self.sender())
302 
def setupUi(self, MainWindow)
def createEditor(self, parent, option, index)
def headerData(self, section, orientation, role)
def __init__(self, parent=None)
def removeRows(self, position, rows, parent=QtCore.QModelIndex())
def data(self, index, role)
def setData(self, index, value, role=QtCore.Qt.EditRole)
def index(self, row, column, parent)
def __init__(self, parent)
def insertRows(self, position, rows, parent=QtCore.QModelIndex())
def setModelData(self, editor, model, index)
def retranslateUi(self, MainWindow)
def setEditorData(self, editor, index)