00001 import string
00002
00003
00004 from cdbVisCore import *
00005 from objectclasses import *
00006 import pdb
00007
00008
00009
00010
00011
00012
00013
00014 INPUTSPINBOX = 101
00015 OUTPUTSPINBOX = 102
00016 DEVICETYPENAME = 103
00017 COLORBUTTON = 104
00018 TXTINPUTNBR = 105
00019 TXTOUTPUTNBR = 106
00020 DEVTYPE_DESCRIPTION = 107
00021 SYSNAME_CMBBOX = 108
00022 DEVTYPEID = 109
00023
00024
00025
00026
00027
00028
00029 class CreateDeviceTypeWindow(QDialog):
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 def __init__(self,parent,name,selectedsystem,creationmode=True,devicetypeobj=None,devicetypes=[]):
00051 QDialog.__init__(self,parent,name,0,0)
00052 Form1Layout = QGridLayout(self,1,1,11,6,"Form1Layout")
00053 spacingButtons = QSpacerItem(110,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
00054 Form1Layout.addMultiCell(spacingButtons,9,9,0,1)
00055
00056 self.buttonOk = QPushButton(self,"buttonOk")
00057 self.buttonOk.setAutoDefault(1)
00058 self.buttonOk.setDefault(1)
00059
00060 '''########if not self.__creationmode:
00061 devtypeidlayout = wxBoxSizer(wxVERTICAL)
00062 devtypeidlayout.Add(self.__devicetypeidcaption)
00063 devtypeidlayout.Add(self.__devtypeidtxtbox)###############'''
00064
00065 Form1Layout.addMultiCellWidget(self.buttonOk,9,9,2,4)
00066
00067 self.buttonCancel = QPushButton(self,"buttonCancel")
00068 self.buttonCancel.setAutoDefault(1)
00069
00070 Form1Layout.addMultiCellWidget(self.buttonCancel,9,9,5,6)
00071
00072 self.description = QTextEdit(self,"Description")
00073
00074 Form1Layout.addMultiCellWidget(self.description,8,8,0,6)
00075
00076 self.__nbrinputspinbutton = QSpinBox(self,"Inputnumber")
00077
00078 Form1Layout.addWidget(self.__nbrinputspinbutton,6,1)
00079 spacinginputOutput = QSpacerItem(51,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
00080 Form1Layout.addMultiCell(spacinginputOutput,6,6,2,3)
00081
00082 self.outputLabel = QLabel(self,"outputLabel")
00083
00084 Form1Layout.addMultiCellWidget(self.outputLabel,6,6,4,5)
00085
00086 self.__nbroutputspinbutton = QSpinBox(self,"Outputnumber")
00087
00088 Form1Layout.addWidget(self.__nbroutputspinbutton,6,6)
00089
00090 self.addsybsystemLabel = QLabel(self,"addsybsystemLabel")
00091
00092 Form1Layout.addMultiCellWidget(self.addsybsystemLabel,4,4,0,1)
00093
00094 self.inputLabel = QLabel(self,"inputLabel")
00095
00096 Form1Layout.addWidget(self.inputLabel,6,0)
00097
00098 self.descriptionLabel = QLabel(self,"descriptionLabel")
00099
00100 Form1Layout.addMultiCellWidget(self.descriptionLabel,7,7,0,1)
00101 spacingNameColor = QSpacerItem(31,20,QSizePolicy.Minimum,QSizePolicy.Minimum)
00102 Form1Layout.addItem(spacingNameColor,1,3)
00103
00104 self.__systemnamecaption = QLabel(self,"__systemnamecaption")
00105
00106 Form1Layout.addMultiCellWidget(self.__systemnamecaption,2,2,0,1)
00107
00108 self.__devicetypetxtbox = QLineEdit(self,"devicetypenameEdit")
00109
00110 Form1Layout.addMultiCellWidget(self.__devicetypetxtbox,1,1,0,2)
00111
00112 self.__systemnametxtbox = QLineEdit(self,"__systemnametxtbox")
00113 Form1Layout.addMultiCellWidget(self.__systemnametxtbox,3,3,0,6)
00114
00115 self.__sysnamescmbbox = QListBox(self,"__sysnamescmbbox")
00116
00117 Form1Layout.addMultiCellWidget(self.__sysnamescmbbox,5,5,0,6)
00118
00119 self.__colorbutton = QPushButton(self,"__colorbutton")
00120
00121 Form1Layout.addMultiCellWidget(self.__colorbutton,1,1,4,6)
00122
00123 self.__devicetypenameLabel = QLabel(self,"DeviceNameLabel")
00124
00125 Form1Layout.addMultiCellWidget(self.__devicetypenameLabel,0,0,0,1)
00126
00127 self.colorLabel = QLabel(self,"colorLabel")
00128
00129 Form1Layout.addMultiCellWidget(self.colorLabel,0,0,4,5)
00130 self.languageChange()
00131
00132 self.connect(self.buttonCancel,SIGNAL("released()"),self.reject)
00133 self.connect(self.buttonOk,SIGNAL("released()"),self.OkButtonClicked)
00134 self.connect(self.__colorbutton,SIGNAL("released()"),self.getColor)
00135 self.connect(self.__sysnamescmbbox,SIGNAL("doubleClicked(QListBoxItem*)"),self.AddSubSystem)
00136
00137
00138 self.__devicetypes = devicetypes
00139 self.__creationmode = creationmode
00140 self.main = parent
00141
00142 if creationmode == True:
00143 title = "Create A DeviceType"
00144 selectedsystem = selectedsystem
00145 else:
00146 title = "Modify A DeviceType"
00147 self.devicetypeobj = devicetypeobj
00148 selectedsystem = self.devicetypeobj.GetSystem()
00149 self.renameobj = None
00150 self.devicetypeid = self.devicetypeobj.GetDeviceTypeID()
00151 self.__systemnametxtbox.setText(selectedsystem)
00152 self.setCaption(title)
00153
00154 tmpsystems = self.main.GetCdb().GetSubSystems()
00155 subsystems = []
00156 for tmp in tmpsystems:
00157 subsystems.append(tmp.GetName())
00158
00159 if self.__creationmode:
00160 self.__sysnamescmbbox.clear()
00161
00162 for subsystem in subsystems: self.__sysnamescmbbox.insertItem(subsystem)
00163 else:
00164 self.__systemnametxtbox.setEnabled(False)
00165
00166 if not self.__creationmode:
00167 selected = self.devicetypeobj.GetName()
00168 selid = self.devicetypeobj.GetDeviceTypeID()
00169 else:
00170 selected = ""
00171 style = 0
00172
00173 if not self.__creationmode:
00174 self.__devicetypeidcaption = wxStaticText(self.__panel,-1,"Device Type ID:")
00175 self.__devtypeidtxtbox = wxTextCtrl(self.__panel,DEVTYPEID,str(selid),wxDefaultPosition,wxSize(50,-1),style=wxTE_READONLY)
00176 self.__devtypeidtxtbox.Disable()
00177
00178
00179 if creationmode:
00180 val_in = 0
00181 val_out = 0
00182 else:
00183 val_in = int(devicetypeobj.GetPortsIn())
00184 val_out = int(devicetypeobj.GetPortsOut())
00185
00186 if creationmode == True:
00187 self.__colorselected = (255,0,0)
00188 self.__colorbutton.setPaletteBackgroundColor(Qt.red)
00189 else:
00190 tmpcolor = devicetypeobj.GetColour()
00191 self.__colorbutton.setPaletteBackgroundColor(tmpcolor)
00192 self.__colorselected = ColorToTuple(rmpcolor)
00193
00194 if creationmode == False:
00195 self.description.setText(devicetypeobj.GetDescription())
00196
00197
00198 def getColor(self):
00199 newColor = QColorDialog.getColor(Qt.red,self)
00200 if newColor.isValid():
00201 self.__colorselected = ColorToTuple(newColor)
00202 self.__colorbutton.setPaletteBackgroundColor(newColor)
00203
00204 def languageChange(self):
00205 self.buttonOk.setText("&OK")
00206 self.buttonOk.setAccel(QString.null)
00207 self.buttonCancel.setText("&Cancel")
00208 self.buttonCancel.setAccel(QString.null)
00209 self.outputLabel.setText("Output ports:")
00210 self.addsybsystemLabel.setText("Add to subsystem:")
00211 self.inputLabel.setText("Input ports:")
00212 self.descriptionLabel.setText("Description :")
00213 self.__systemnamecaption.setText("Create in:")
00214 self.__colorbutton.setText("Color")
00215 self.__devicetypenameLabel.setText("Device Type Name:")
00216 self.colorLabel.setText("Choose color:")
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 def SaveObject(self):
00228
00229 trackValueError = 0
00230
00231 if self.__creationmode:
00232 create = True
00233 else:
00234 create = False
00235
00236
00237 try:
00238 if self.__creationmode:
00239 if str(self.__devicetypetxtbox.text()) in self.__devicetypes:
00240 raise ValidationError,"The devicetype cannot be created as the name you have given is already in use."
00241 else:
00242 if (self.__devicetypetxtbox.text()) != self.devicetypeobj.GetName():
00243 ans = wxMessageBox("You have renamed the device type, was that your intention? Remember that you can not undo renaming, \nbut you can rename the object as many times as you want later on.","Rename?",wxYES_NO | wxICON_QUESTION)
00244 if ans == wxNO:
00245 self.__devicetypetxtbox.SetValue(self.devicetypeobj.GetName())
00246 return False
00247 if self.__devicetypetxtbox.GetValue() in self.__devicetypes:
00248 raise ValidationError,"The device type cannot be created as the name you have given is already in use."
00249
00250 self.renameobj = DeviceType(self.__systemnametxtbox.GetValue(),self.__devicetypetxtbox.GetValue(),True)
00251 self.renameobj.SetOldName(self.devicetypeobj.GetName())
00252 self.renameobj.SetSaveStatus(RENAME)
00253
00254
00255 self.devicetypeobj = DeviceType(str(self.__systemnametxtbox.text()),str(self.__devicetypetxtbox.text()),create)
00256
00257 self.devicetypeobj.SetName(str(self.__devicetypetxtbox.text()))
00258 self.devicetypeobj.SetSystem(str(self.__systemnametxtbox.text()))
00259 self.devicetypeobj.SetPortsIn(int(str(self.__nbrinputspinbutton.text())))
00260 trackValueError = 1
00261 self.devicetypeobj.SetPortsOut(int(str(self.__nbroutputspinbutton.text())))
00262 trackValueError = 2
00263 self.devicetypeobj.SetDescription(str(self.description.text()))
00264 self.devicetypeobj.SetColour(self.__colorselected)
00265
00266
00267 if not self.__creationmode:
00268 if str(self.devicetypeid) != "" and str(self.devicetypeid) != "-1":
00269 self.devicetypeobj.SetDeviceTypeID(int(self.devicetypeid))
00270
00271 return True
00272
00273 except ValidationError,err:
00274 self.main.ShowError(str(err),ERR_ERROR,True)
00275 return False
00276
00277 except ValueError,err:
00278 if trackValueError == 0:
00279 self.main.ShowError("The value given for number of ports in is not an integer.",ERR_ERROR,True)
00280 elif trackValueError == 1:
00281 self.main.ShowError("The value given for number of ports out is not an integer.",ERR_ERROR,True)
00282 else:
00283 self.main.ShowError("The value given for the device type ID is not an integer.",ERR_ERROR,True)
00284 return False
00285
00286
00287
00288
00289
00290
00291
00292
00293 def OkButtonClicked(self):
00294
00295 if str(self.__devicetypetxtbox.text()) == "":
00296 self.main.ShowError("No device type name chosen.",ERR_ERROR,True)
00297 return False
00298
00299 success = self.SaveObject()
00300 if not success:
00301 return False
00302 else:
00303 self.accept()
00304
00305
00306
00307
00308
00309 def AddSubSystem(self,item):
00310
00311 if string.find(str(self.__systemnametxtbox.text()),str(item.text()),0) != -1:
00312 self.main.ShowError("Subsystem already added!",ERR_ERROR,False)
00313 else:
00314 self.__systemnametxtbox.setText(str(self.__systemnametxtbox.text()) + "," + str(item.text()))
00315
00316
00317
00318
00319
00320 def IsCreationMode(self):
00321 return self.__creationmode
00322
00323 '''def ColorButtonClicked(self,event):
00324 """ User clicks on the colour button and chooses a color for the current device type.
00325 """
00326
00327 colordialog = wxColourDialog(self)
00328 if colordialog.ShowModal() == wxID_OK:
00329 colorobj = colordialog.GetColourData()
00330 color = colorobj.GetColour()
00331 self.__colorbutton.SetBackgroundColour(color)
00332 self.__colorselected = wxColour(red=color.Red(),green=color.Green(),blue=color.Blue()) # We create a wxColour(R,G,B) object to store the color.
00333 '''
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 def GetDeviceTypeObj(self):
00345
00346 if self.__creationmode:
00347 return self.devicetypeobj
00348 else:
00349 return self.devicetypeobj, self.renameobj
00350
00351
00352