~openteachermaintainers/opengamedesigner/trunk

« back to all changes in this revision

Viewing changes to configwindows/object.py

  • Committer: Marten de Vries
  • Date: 2012-06-03 19:50:30 UTC
  • Revision ID: marten94@gmail.com-20120603195030-4o9baw5lcxm3ckc7
A lot of updates, but currently still broken.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#       along with OpenGameDesigner.  If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
22
from PyQt4 import QtCore, QtGui
23
 
try:
24
 
        import json
25
 
except ImportError:
26
 
        import simplejson as json
 
23
import json
 
24
 
27
25
import uuid
28
26
import copy
29
27
 
49
47
import actionwindows.comment
50
48
 
51
49
#editors
 
50
import editors.item
 
51
import editors.remove
52
52
import editors.trash
53
53
 
54
54
class ActionTreeModel(QtCore.QAbstractListModel):
914
914
                self.retranslate()
915
915
                self.update(name)
916
916
 
917
 
                self._spriteWidget.currentIndexChanged.connect(self._saveSprite)
 
917
                self._spriteWidget.changed.connect(self._saveSprite)
918
918
                self._spriteRemoveButton.clicked.connect(self._removeSprite)
919
919
 
 
920
                self._solidWidget.clicked.connect(self._saveSolid)
 
921
 
920
922
                self._eventsView.newSelection.connect(self._updateActions)
921
923
                self._actionsView.activated.connect(self._showActionWindow)
922
924
                self._actionsModel.openEditor.connect(self._showActionWindow)
1025
1027
 
1026
1028
        def _setupUi(self, name):
1027
1029
                self._spriteLabel = QtGui.QLabel()
1028
 
                self._spriteWidget = QtGui.QComboBox()
1029
 
                self._spriteWidget.setModel(self._model)
1030
 
                self._spriteWidget.setRootModelIndex(self._model.imagesRoot)
 
1030
                self._spriteWidget = editors.item.ItemEditor(self._model, self._model.imagesRoot)
1031
1031
                self._spriteRemoveButton = editors.remove.RemoveButton()
1032
1032
 
 
1033
                self._solidLabel = QtGui.QLabel()
 
1034
                self._solidWidget = QtGui.QCheckBox()
 
1035
 
1033
1036
                # Layout
1034
1037
                spriteLayout = QtGui.QHBoxLayout()
1035
1038
                spriteLayout.addWidget(self._spriteWidget)
1037
1040
 
1038
1041
                form = QtGui.QFormLayout()
1039
1042
                form.addRow(self._spriteLabel, spriteLayout)
 
1043
                form.addRow(self._solidLabel, self._solidWidget)
1040
1044
 
1041
1045
                self._eventsView = SelectionTreeView()
1042
1046
                self._eventsView.setItemsExpandable(False)
1094
1098
                self._layout.addWidget(splitter, 1)
1095
1099
                self.setLayout(self._layout)
1096
1100
 
1097
 
        def _saveSprite(self, row):
1098
 
                # Don't save if no sprite was selected
1099
 
                if row == -1:
1100
 
                        return
1101
 
                index = self._spriteWidget.rootModelIndex().child(
1102
 
                        row,
1103
 
                        self._spriteWidget.modelColumn()
1104
 
                )
1105
 
                name = self._model.data(index, QtCore.Qt.DisplayRole)
1106
 
                self._definition['entries']['sprite'] = lpsparser.Name(name)
 
1101
        def _saveSprite(self, name):
 
1102
                self._definition['entries']['sprite'] = name
 
1103
                self._onChange()
 
1104
 
 
1105
        def _saveSolid(self, checked):
 
1106
                self._definition['entries']['solid'] = checked
1107
1107
                self._onChange()
1108
1108
 
1109
1109
        def _removeSprite(self, row):
1115
1115
        def update(self, name):
1116
1116
                self._name = name
1117
1117
 
1118
 
                #set current sprite item if one
1119
 
                defs = self._model.definitionsForType(self._model.typeForIndex(
1120
 
                        self._spriteWidget.rootModelIndex()
1121
 
                ))
1122
 
                if 'sprite' in self._definition['entries']:
 
1118
                try:
1123
1119
                        imageName = self._definition['entries']['sprite']
1124
 
                        row = sorted(defs).index(imageName)
1125
 
                        self._spriteWidget.setCurrentIndex(row)
 
1120
                except KeyError:
 
1121
                        self._spriteWidget.update(None)
1126
1122
                else:
1127
 
                        self._spriteWidget.setCurrentIndex(-1)
 
1123
                        self._spriteWidget.update(imageName)
 
1124
 
 
1125
                try:
 
1126
                        self._solidWidget.setChecked(self._definition['entries']['solid'])
 
1127
                except KeyError:
 
1128
                        self._solidWidget.setChecked(True) #the default
1128
1129
 
1129
1130
                self._eventsModel.reset()
1130
1131
 
1131
1132
        def retranslate(self):
1132
1133
                self._spriteLabel.setText(_("Sprite"))
 
1134
                self._solidLabel.setText(_("Solid"))
1133
1135
                self._addEventButton.setText(_("Add event"))
1134
1136
 
1135
1137
                self._availableActionsWidget.retranslate()