def BreederMenuRandomizeAllClick(self, Sender): generation = PdGeneration() i = 0 j = 0 newCommand = PdCommand() randomizeList = TList() if self.generations.Count <= 0: return randomizeList = None try: ucursor.cursor_startWait() randomizeList = delphi_compatability.TList().Create() if self.generations.Count > 0: for i in range(0, self.generations.Count): generation = ugener.PdGeneration(self.generations.Items[i]) if generation.plants.Count > 0: for j in range(0, generation.plants.Count): randomizeList.Add(uplant.PdPlant(generation.plants.Items[j])) newCommand = updcom.PdRandomizeCommand().createWithListOfPlants(randomizeList) (newCommand as updcom.PdRandomizeCommand).isInBreeder = true (newCommand as updcom.PdRandomizeCommand).isRandomizeAllInBreeder = true umain.MainForm.doCommand(newCommand) finally: randomizeList.free ucursor.cursor_stopWait()
def expose(self, widget, event): x, y, width, height = event.area gc = widget.window.new_gc() if self.outOfDate: ucursor.cursor_startWait() try: context = (self.backingPixmap, gc) if self.backgroundImage: self.backingPixmap.draw_rectangle( widget.get_style().white_gc, True, 0, 0, width, height) self.backingPixmap.draw_pixbuf(gc, self.backgroundImage, 0, 0, 0, 0) else: self.backingPixmap.draw_rectangle( widget.get_style().white_gc, True, 0, 0, width, height) self.draw(context, width, height) finally: ucursor.cursor_stopWait() self.outOfDate = 0 widget.window.draw_drawable(gc, self.backingPixmap, x, y, x, y, width, height) widget.window.draw_pixbuf(gc, self.glove.get_pixbuf(), 0, 0, self.gloveX - self.gloveOffsetX, self.gloveY - self.gloveOffsetY)
def BreederMenuRandomizeClick(self, Sender): newCommand = PdCommand() randomizeList = TList() aGeneration = PdGeneration() i = 0 plant = PdPlant() aGeneration = self.selectedGeneration() if aGeneration == None: return if aGeneration.selectedPlants.Count <= 0: return randomizeList = delphi_compatability.TList().Create() try: for i in range(0, aGeneration.selectedPlants.Count): plant = uplant.PdPlant(aGeneration.selectedPlants.Items[i]) randomizeList.Add(plant) newCommand = updcom.PdRandomizeCommand().createWithListOfPlants(randomizeList) (newCommand as updcom.PdRandomizeCommand).isInBreeder = true ucursor.cursor_startWait() umain.MainForm.doCommand(newCommand) finally: #command has another list, so we must free this one randomizeList.free ucursor.cursor_stopWait()
def cleanUpAfterFileSave(fileInfo): useBackup = false renamingFailed = false deletingFailed = false prompt = "" ucursor.cursor_stopWait() uwait.stopWaitMessage() useBackup = true if not fileInfo.writingWasSuccessful: # if couldn't write, then remove temp file and exit without warning DeleteFile(fileInfo.tempFile) return if fileInfo.backupFile != "": if FileExists(fileInfo.backupFile): # remove backup file if exists from prior backup # try to delete backup file deletingFailed = not DeleteFile(fileInfo.backupFile) if deletingFailed: # couldn't delete backup file prompt = "Could not write backup file " + fileInfo.backupFile + ". Continue?" if MessageDialog(prompt, mtConfirmation, [mbYes, mbNo], 0) != mrYes: # user doesn't want to proceed - so cleanup temp file DeleteFile(fileInfo.tempFile) return else: useBackup = false else: useBackup = false if FileExists(fileInfo.newFile): if useBackup: # if original file exists make backup if requested... # rename old copy of new file to make backup renamingFailed = not RenameFile(fileInfo.newFile, fileInfo.backupFile) if renamingFailed: prompt = "Could not rename old file to backup file " + fileInfo.backupFile + ". Continue?" if MessageDialog(prompt, mtConfirmation, [mbYes, mbNo], 0) != mrYes: # user doesn't want to proceed - so cleanup temp file DeleteFile(fileInfo.tempFile) return else: useBackup = false if not useBackup: # could not create backup file - so just delete old file instead of renaming deletingFailed = not DeleteFile(fileInfo.newFile) if deletingFailed: ShowMessage("Could not write file " + fileInfo.newFile) return # rename temp file to newFile name renamingFailed = not RenameFile(fileInfo.tempFile, fileInfo.newFile) if renamingFailed: # clean up by removing temp file ShowMessage("Could not write file " + fileInfo.newFile + " from " + fileInfo.tempFile) DeleteFile(fileInfo.tempFile) return if (not udomain.domain.registered) and (fileInfo.writingWasSuccessful) and (fileIsExportFile(fileInfo.fileType)): umain.MainForm.incrementUnregisteredExportCount()
def grow(self, widget, days): ucursor.cursor_startWait() try: for plant in self.drawingArea.plants: if days == -1: plant.reset() else: for day in range(days): plant.nextDay() finally: ucursor.cursor_stopWait() self.drawingArea.setOutOfDate()
def openLibrary(self, widget): fileName = ChooseFile(self.window, "Plant files", ["*.pla"]) if fileName == None: return print "Opening", fileName ucursor.cursor_startWait() try: plants = uplant.PlantLoader().loadPlantsFromFile(fileName, inPlantMover=1, justLoad=1) self.fileName = fileName self.setPlantListContents(plants) finally: ucursor.cursor_stopWait()
def _grow(self, widget, days): if not self.drawingArea.plant: return ucursor.cursor_startWait() try: if days == -1: self.drawingArea.plant.reset() else: for day in range(days): self.drawingArea.plant.nextDay() finally: ucursor.cursor_stopWait() InvalidateWidget(self.drawingArea)
def gridEndDrag(self, Sender, Target, X, Y): plant = PdPlant() newCommand = PdCommand() newPlants = TList() newPlant = PdPlant() if delphi_compatability.Application.terminated: return if Target == None: return # get plant being dragged plant = self.plantAtMouse(self.dragPlantStartPoint.X, self.dragPlantStartPoint.Y) if plant == None: return if Target == ubreedr.BreederForm.plantsDrawGrid: ubreedr.BreederForm.copyPlantToPoint(plant, X, Y) elif (Target == umain.MainForm.drawingPaintBox) or (Target == umain.MainForm.plantListDrawGrid): # make paste command - wants list of plants newPlant = uplant.PdPlant().create() plant.copyTo(newPlant) self.numTimeSeriesPlantsCopiedThisSession += 1 newPlant.setName("Time series plant " + IntToStr(self.numTimeSeriesPlantsCopiedThisSession)) if Target == umain.MainForm.drawingPaintBox: newPlant.moveTo(Point(X, Y)) else: newPlant.moveTo(umain.MainForm.standardPastePosition()) if not udomain.domain.viewPlantsInMainWindowOnePlantAtATime(): # v2.1 newPlant.calculateDrawingScaleToLookTheSameWithDomainScale() #to save memory - don't need it in main window newPlant.shrinkPreviewCache() newPlants = delphi_compatability.TList().Create() newPlants.Add(newPlant) newCommand = updcom.PdPasteCommand().createWithListOfPlantsAndOldSelectedList(newPlants, umain.MainForm.selectedPlants) updcom.PdPasteCommand(newCommand).useSpecialPastePosition = true try: #command will free plant if paste is undone ucursor.cursor_startWait() umain.MainForm.doCommand(newCommand) finally: #command has another list, so we must free this one newPlants.free ucursor.cursor_stopWait()
def expose(self, widget, event): x , y, width, height = event.area gc = widget.window.new_gc() if self.outOfDate: ucursor.cursor_startWait() try: context = (self.backingPixmap, gc) if self.backgroundImage: self.backingPixmap.draw_rectangle(widget.get_style().white_gc, True, 0, 0, width, height) self.backingPixmap.draw_pixbuf(gc, self.backgroundImage, 0, 0, 0, 0) else: self.backingPixmap.draw_rectangle(widget.get_style().white_gc, True, 0, 0, width, height) self.draw(context, width, height) finally: ucursor.cursor_stopWait() self.outOfDate = 0 widget.window.draw_drawable(gc, self.backingPixmap, x, y, x, y, width, height) widget.window.draw_pixbuf(gc, self.glove.get_pixbuf(), 0, 0, self.gloveX - self.gloveOffsetX, self.gloveY - self.gloveOffsetY)
def loadPlantFileAtStartup(): ucursor.cursor_startWait() try: if udomain.domain.plantFileLoaded: # if file loaded at startup, update for it, else act as if they picked new uwait.startWaitMessage("Drawing...") try: umain.MainForm.updateForPlantFile() finally: uwait.stopWaitMessage() else: umain.MainForm.MenuFileNewClick(umain.MainForm) if usplash.splashForm != None: usplash.splashForm.Hide() umain.MainForm.updateForChangeToDomainOptions() umain.MainForm.updateFileMenuForOtherRecentFiles() umain.MainForm.selectedPlantPartID = -1 umain.MainForm.inFormCreation = false finally: ucursor.cursor_stopWait()
def mouseDown(self, widget, event): # GTK BUG __ SEEMS TO CALL THREE TIMES IF DOUBLE CLICK 9only last is double click) isDoubleClick = event.type == gtk.gdk._2BUTTON_PRESS if isDoubleClick: self.mouseDoubleClick(event) return x = event.x y = event.y if self.drawingArea.selectedCultivar: ucursor.cursor_startWait() try: newPlant = self.drawingArea.selectedCultivar.makeCopy() newPlant.x = x newPlant.y = y newPlant.setAge(1) newPlant.randomize() self.drawingArea.plants.append(newPlant) self.drawingArea.setOutOfDate() finally: ucursor.cursor_stopWait()
def initializeWithPlant(self, aPlant, drawNow): newPlant = PdPlant() i = 0 if aPlant == None: return if not self.Visible: self.Show() self.BringToFront() self.plants.clear() self.parentPlant = aPlant ucursor.cursor_startWait() try: for i in range(0, self.numStages): newPlant = uplant.PdPlant().create() self.parentPlant.copyTo(newPlant) self.ages[i] = intround(umath.max(0.0, umath.min(1.0, self.percentsOfMaxAge[i] / 100.0)) * newPlant.pGeneral.ageAtMaturity) newPlant.setAge(self.ages[i]) self.plants.Add(newPlant) finally: ucursor.cursor_stopWait() if drawNow: self.redrawPlants()
def Cursor_StopWait(): ucursor.cursor_stopWait()
def plantsDrawGridEndDrag(self, Sender, Target, X, Y): col = 0L row = 0L plant = PdPlant() plantToReplace = PdPlant() newCommand = PdCommand() newPlants = TList() newPlant = PdPlant() if delphi_compatability.Application.terminated: return # remove lightup on cell before resetting cell self.invalidateGridCell(self.lightUpCell.X, self.lightUpCell.Y) self.lightUpCell = Point(-1, -1) if Target == None: return # get plant being dragged plant = self.plantAtMouse(self.dragPlantStartPoint.X, self.dragPlantStartPoint.Y) if plant == None: return if (Target == umain.MainForm.drawingPaintBox) or (Target == umain.MainForm.plantListDrawGrid): # make paste command - wants list of plants newPlant = uplant.PdPlant().create() plant.copyTo(newPlant) self.numBreederPlantsCopiedThisSession += 1 newPlant.setName("Breeder plant " + IntToStr(self.numBreederPlantsCopiedThisSession)) if (Target == umain.MainForm.drawingPaintBox): newPlant.moveTo(Point(X, Y)) else: newPlant.moveTo(umain.MainForm.standardPastePosition()) if not udomain.domain.viewPlantsInMainWindowOnePlantAtATime(): # v2.1 newPlant.calculateDrawingScaleToLookTheSameWithDomainScale() #to save memory - don't need it in main window newPlant.shrinkPreviewCache() newPlants = delphi_compatability.TList().Create() newPlants.Add(newPlant) newCommand = updcom.PdPasteCommand().createWithListOfPlantsAndOldSelectedList(newPlants, umain.MainForm.selectedPlants) updcom.PdPasteCommand(newCommand).useSpecialPastePosition = true try: ucursor.cursor_startWait() umain.MainForm.doCommand(newCommand) finally: #command has another list, so we must free this one newPlants.free ucursor.cursor_stopWait() #command will free plant if paste is undone elif Target == utimeser.TimeSeriesForm.grid: utimeser.TimeSeriesForm.copyPlantToPoint(plant, X, Y) elif Target == Sender: # get plant being replaced col, row = self.plantsDrawGrid.MouseToCell(X, Y, col, row) if not self.inGrid(row, col): return plantToReplace = self.plantForRowAndColumn(row, col) if plantToReplace == None: return if plantToReplace == plant: return # make replace command newCommand = updcom.PdReplaceBreederPlant().createWithPlantRowAndColumn(plant, row, col) try: ucursor.cursor_startWait() umain.MainForm.doCommand(newCommand) finally: ucursor.cursor_stopWait()
def plantsDrawGridDrawCell(self, Sender, Col, Row, Rect, State): generation = PdGeneration() plant = PdPlant() textDrawRect = TRect() try: self.plantsDrawGrid.Canvas.Font = self.plantsDrawGrid.Font self.plantsDrawGrid.Canvas.Font.Color = delphi_compatability.clBlack if Col == 0: #if (row = selectedRow) and (generations.count > 0) then #plantsDrawGrid.canvas.brush.color := clBlue #else self.plantsDrawGrid.Canvas.Brush.Color = delphi_compatability.clWhite self.plantsDrawGrid.Canvas.Pen.Color = self.plantsDrawGrid.Canvas.Brush.Color self.plantsDrawGrid.Canvas.Rectangle(Rect.left, Rect.top, Rect.right, Rect.bottom) if Row > self.generations.Count - 1: return #if row = selectedRow then #plantsDrawGrid.canvas.font.color := clWhite; textDrawRect.Left = Rect.left + usupport.rWidth(Rect) / 2 - self.plantsDrawGrid.Canvas.TextWidth(IntToStr(Row + 1)) / 2 textDrawRect.Top = Rect.top + usupport.rHeight(Rect) / 2 - self.plantsDrawGrid.Canvas.TextHeight("0") / 2 self.plantsDrawGrid.Canvas.TextOut(textDrawRect.Left, textDrawRect.Top, IntToStr(Row + 1)) return else: self.plantsDrawGrid.Canvas.Brush.Color = delphi_compatability.clWhite self.plantsDrawGrid.Canvas.Pen.Width = 1 self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clWhite self.plantsDrawGrid.Canvas.Rectangle(Rect.left, Rect.top, Rect.right, Rect.bottom) generation = None generation = self.generationForIndex(Row) if generation == None: return plant = None plant = generation.plantForIndex(Col - 1) if plant == None: return if not plant.previewCacheUpToDate: # draw plant # draw gray solid box to show delay for drawing plant cache self.plantsDrawGrid.Canvas.Brush.Style = delphi_compatability.TFPBrushStyle.bsSolid self.plantsDrawGrid.Canvas.Brush.Color = delphi_compatability.clSilver self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clSilver # FIX unresolved WITH expression: Rect self.plantsDrawGrid.Canvas.Rectangle(self.Left + 1, self.Top + 1, UNRESOLVED.right, UNRESOLVED.bottom) # draw plant preview cache plant.fixedPreviewScale = false plant.fixedDrawPosition = false plant.drawPreviewIntoCache(Point(self.plantsDrawGrid.DefaultColWidth, self.plantsDrawGrid.DefaultRowHeight), uplant.kDontConsiderDomainScale, umain.kDrawNow) plant.previewCache.Transparent = false ubmpsupport.copyBitmapToCanvasWithGlobalPalette(plant.previewCache, self.plantsDrawGrid.Canvas, Rect) # draw selection rectangle self.plantsDrawGrid.Canvas.Brush.Style = delphi_compatability.TFPBrushStyle.bsClear self.plantsDrawGrid.Canvas.Pen.Width = 2 if (Col == self.lightUpCell.X) and (Row == self.lightUpCell.Y): self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clAqua elif Row == self.selectedRow: if plant == generation.firstSelectedPlant(): self.plantsDrawGrid.Canvas.Pen.Color = udomain.domain.options.firstSelectionRectangleColor elif plant == generation.secondSelectedPlant(): self.plantsDrawGrid.Canvas.Pen.Color = udomain.domain.options.multiSelectionRectangleColor else: self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clSilver else: self.plantsDrawGrid.Canvas.Pen.Color = delphi_compatability.clSilver # FIX unresolved WITH expression: Rect self.plantsDrawGrid.Canvas.Rectangle(self.Left + 1, self.Top + 1, UNRESOLVED.right, UNRESOLVED.bottom) if plant == generation.firstParent: # draw parent indicator self.plantsDrawGrid.Canvas.TextOut(Rect.left + 4, Rect.top + 2, "p1") elif plant == generation.secondParent: self.plantsDrawGrid.Canvas.TextOut(Rect.left + 4, Rect.top + 2, "p2") finally: ucursor.cursor_stopWait()
def reconcileFileWithTdoLibrary(self, plantFileName, tdoLibrary): result = 0 plantFileTdos = TListCollection() libraryFileTdos = TListCollection() plantFile = TextFile() tdoFile = TextFile() outputTdoFile = TextFile() i = 0 j = 0 tdo = KfObject3d() plantFileTdo = KfObject3d() libraryTdo = KfObject3d() matchInLibrary = false aLine = "" fileInfo = SaveFileNamesStructure() result = 0 if not FileExists(plantFileName): # check that files exist plantFileName = usupport.getFileOpenInfo(usupport.kFileTypePlant, plantFileName, "Choose a plant file") if plantFileName == "": return result if not FileExists(tdoLibrary): tdoLibrary = usupport.getFileOpenInfo(usupport.kFileTypeTdo, tdoLibrary, "Choose a 3D object library (tdo) file") if tdoLibrary == "": return result plantFileTdos = ucollect.TListCollection().Create() libraryFileTdos = ucollect.TListCollection().Create() try: ucursor.cursor_startWait() # read tdos from plants AssignFile(plantFile, plantFileName) try: # v1.5 usupport.setDecimalSeparator() Reset(plantFile) while not UNRESOLVED.eof(plantFile): UNRESOLVED.readln(plantFile, aLine) if UNRESOLVED.pos(utdo.kStartTdoString, aLine) > 0: tdo = utdo.KfObject3D().create() tdo.readFromFileStream(plantFile, utdo.kInTdoLibrary) plantFileTdos.Add(tdo) finally: CloseFile(plantFile) # read tdos from library AssignFile(tdoFile, tdoLibrary) try: # v1.5 usupport.setDecimalSeparator() Reset(tdoFile) while not UNRESOLVED.eof(tdoFile): tdo = utdo.KfObject3D().create() tdo.readFromFileStream(tdoFile, utdo.kInTdoLibrary) libraryFileTdos.Add(tdo) finally: CloseFile(tdoFile) if plantFileTdos.Count > 0: for i in range(0, plantFileTdos.Count): # add plant tdos not in library list to library list plantFileTdo = utdo.KfObject3D(plantFileTdos.Items[i]) matchInLibrary = false if libraryFileTdos.Count > 0: for j in range(0, libraryFileTdos.Count): libraryTdo = utdo.KfObject3D(libraryFileTdos.Items[j]) if plantFileTdo.isSameAs(libraryTdo): matchInLibrary = true break if not matchInLibrary: tdo = utdo.KfObject3D().create() tdo.copyFrom(plantFileTdo) libraryFileTdos.Add(tdo) result += 1 if result > 0: if usupport.getFileSaveInfo(usupport.kFileTypeTdo, usupport.kDontAskForFileName, tdoLibrary, fileInfo): # if any tdos in plant file but not in library, rewrite library AssignFile(outputTdoFile, fileInfo.tempFile) try: # v1.5 usupport.setDecimalSeparator() Rewrite(outputTdoFile) usupport.startFileSave(fileInfo) if libraryFileTdos.Count > 0: for i in range(0, libraryFileTdos.Count): tdo = UNRESOLVED.TObject(libraryFileTdos.Items[i]) as utdo.KfObject3D if tdo == None: continue tdo.writeToFileStream(outputTdoFile, utdo.kInTdoLibrary) fileInfo.writingWasSuccessful = true finally: CloseFile(outputTdoFile) usupport.cleanUpAfterFileSave(fileInfo) finally: plantFileTdos.free libraryFileTdos.free ucursor.cursor_stopWait() return result