def __init__(self, parent, id=-1): wx.Panel.__init__(self, parent, id) main_sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(main_sizer) btn_ok = wx.Button(self, wx.ID_OK) btn_cancel = wx.Button(self, wx.ID_CANCEL) btn_ok.SetDefault() sizer_btn = wx.BoxSizer(wx.HORIZONTAL) sizer_btn.Add(btn_ok, 0, wx.ALL | wx.EXPAND, 5) sizer_btn.Add(wx.BoxSizer(), 1, wx.ALL | wx.EXPAND, 5) sizer_btn.Add(btn_cancel, 0, wx.ALL | wx.EXPAND, 5) plt_list = [ 'Select Pollutant', 'E_ALD', 'E_CO', 'E_CSL', 'E_ECI', 'E_ECJ', 'E_ETH', 'E_HC3', 'E_HC5', 'E_HC8', 'E_HCHO', 'E_ISO', 'E_KET', 'E_NH3', 'E_NO', 'E_NO3I', 'E_NO3J', 'E_OL2', 'E_OLI', 'E_OLT', 'E_ORA2', 'E_ORGI', 'E_ORGJ', 'E_PM25I', 'E_PM25J', 'E_PM_10', 'E_SO2', 'E_SO4I', 'E_SO4J', 'E_TOL', 'E_XYL' ] self.plt_list = plt_list self.choice_plt = wx.ComboBox(self, -1, choices=plt_list) self.choice_plt.SetSelection(0) txt_label = wx.StaticText(self, -1, "Pollutant: ") sizer_plt = wx.BoxSizer(wx.HORIZONTAL) sizer_plt.Add(txt_label, 1, wx.ALL | wx.EXPAND, 5) sizer_plt.Add(self.choice_plt, 2, wx.ALL | wx.EXPAND, 5) self.sheet_list = [] self.choice_sheet = wx.Choice(self, -1, choices=self.sheet_list) txt_sheet_label = wx.StaticText(self, -1, "Worksheet: ") sizer_sheet = wx.BoxSizer(wx.HORIZONTAL) sizer_sheet.Add(txt_sheet_label, 1, wx.ALL | wx.EXPAND, 5) sizer_sheet.Add(self.choice_sheet, 2, wx.ALL | wx.EXPAND, 5) self.te_conv_f = commons.GrayTextCtrl( self, -1, 'Default value: 1.0)', validator=commons.EvalNumberTextValidator(True)) sizer_conv_header = wx.BoxSizer(wx.HORIZONTAL) sizer_conv_header.Add(wx.StaticText(self, -1, "Conversion Factor "), 0, wx.ALL | wx.EXPAND, 0) sizer_conv_header.Add(wx.StaticLine(self, -1), 1, wx.CENTER, 5) self.te_row_start = commons.GrayTextCtrl( self, -1, 'Starting Row (e.g.: 2)', validator=commons.NumberTextValidator()) self.te_row_end = commons.GrayTextCtrl( self, -1, 'Ending Row (e.g.: 101)', validator=commons.NumberTextValidator()) sizer_sz = wx.BoxSizer(wx.HORIZONTAL) sizer_sz.Add(self.te_row_start, 1, wx.ALL | wx.EXPAND, 5) sizer_sz.Add(self.te_row_end, 1, wx.ALL | wx.EXPAND, 5) sizer_sz_header = wx.BoxSizer(wx.HORIZONTAL) sizer_sz_header.Add(wx.StaticText(self, -1, "Data Rows "), 0, wx.ALL | wx.EXPAND, 0) sizer_sz_header.Add(wx.StaticLine(self, -1), 1, wx.CENTER, 5) self.te_emiss_column = commons.GrayTextCtrl( self, -1, 'Column (e.g. A)', validator=commons.AlphaTextValidator()) sizer_emiss_header = wx.BoxSizer(wx.HORIZONTAL) sizer_emiss_header.Add(wx.StaticText(self, -1, "Emission Column "), 0, wx.ALL | wx.EXPAND, 0) sizer_emiss_header.Add(wx.StaticLine(self, -1), 1, wx.CENTER, 5) self.te_lat_column = commons.GrayTextCtrl( self, -1, 'Column (e.g. B)', validator=commons.AlphaTextValidator()) sizer_lat_header = wx.BoxSizer(wx.HORIZONTAL) sizer_lat_header.Add(wx.StaticText(self, -1, "Latitude Column "), 0, wx.ALL | wx.EXPAND, 0) sizer_lat_header.Add(wx.StaticLine(self, -1), 1, wx.CENTER, 5) self.te_lon_column = commons.GrayTextCtrl( self, -1, 'Column (e.g. C)', validator=commons.AlphaTextValidator()) sizer_lon_header = wx.BoxSizer(wx.HORIZONTAL) sizer_lon_header.Add(wx.StaticText(self, -1, "Longitude Column "), 0, wx.ALL | wx.EXPAND, 0) sizer_lon_header.Add(wx.StaticLine(self, -1), 1, wx.CENTER, 5) self.te_x_column = commons.GrayTextCtrl( self, -1, 'Column (e.g. D)', validator=commons.AlphaTextValidator()) sizer_x_header = wx.BoxSizer(wx.HORIZONTAL) sizer_x_header.Add(wx.StaticText(self, -1, "X Column "), 0, wx.ALL | wx.EXPAND, 0) sizer_x_header.Add(wx.StaticLine(self, -1), 1, wx.CENTER, 5) self.te_y_column = commons.GrayTextCtrl( self, -1, 'Column (e.g. E)', validator=commons.AlphaTextValidator()) sizer_y_header = wx.BoxSizer(wx.HORIZONTAL) sizer_y_header.Add(wx.StaticText(self, -1, "Y Column "), 0, wx.ALL | wx.EXPAND, 0) sizer_y_header.Add(wx.StaticLine(self, -1), 1, wx.CENTER, 5) main_sizer.Add(sizer_plt, 0, wx.ALL | wx.EXPAND, 0) main_sizer.Add(sizer_sheet, 0, wx.ALL | wx.EXPAND, 0) txt_desc = wordwrap( u"Use conversion factor to convert unit to mol/km\u00b2/hour", 300, wx.ClientDC(self)) main_sizer.Add(wx.StaticText(self, -1, txt_desc), 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(sizer_conv_header, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(self.te_conv_f, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(sizer_sz_header, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(sizer_sz, 0, wx.ALL | wx.EXPAND, 0) main_sizer.Add(sizer_emiss_header, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(self.te_emiss_column, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(sizer_lat_header, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(self.te_lat_column, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(sizer_lon_header, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(self.te_lon_column, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(sizer_x_header, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(self.te_x_column, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(sizer_y_header, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(self.te_y_column, 0, wx.ALL | wx.EXPAND, 5) main_sizer.Add(wx.StaticLine(self, -1), 1, wx.ALL | wx.EXPAND, 5) main_sizer.Add(sizer_btn, 0, wx.ALL | wx.EXPAND, 0) self.Bind(wx.EVT_BUTTON, self.OnOk, btn_ok)
def Rest(self): """Stop the animation and return to frame 0.""" self.Stop() self.current = self.rest self.Draw(wx.ClientDC(self))
def UpdateDrawing(self): dc = wx.BufferedDC(wx.ClientDC(self), self._Buffer) self.Draw(dc)
def SetColor(self, color): self.color = color self.Draw(wx.ClientDC(self))
def DrawMarks(self, e): dc = wx.ClientDC(self) geometry_mark.draw(dc, f, k=1)
def drawAll(self): dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.drawBg(dc) self.drawLogo(dc) self.drawScore(dc) self.drawTiles(dc)
def OnSizingDragLeft(self, pt, draw, x, y, keys=0, attachment=0): """ A handler for sizing events. This is overriden to manipulate the sizing behaviour so that the diagonal handles always maintain aspect ratio """ if pt._type == ogl.CONTROL_POINT_DIAGONAL: self.doMaintainAspect = 1 else: self.doMaintainAspect = 0 ogl.Shape.OnSizingDragLeft(self, pt, draw, x, y, keys, attachment) if platform.system() != "Darwin": return # --------------------------------------- # # This is a bug fix for the Mac version. # # Remove this if or when OGL properly # # draws outlines when sizing annotations. # # --------------------------------------- # shape = self.GetShape() controlPts = shape._controlPoints minX = minY = sys.maxint maxX = maxY = -sys.maxint - 1 for controlPt in controlPts: minX = min(minX, controlPt.GetX()) minY = min(minY, controlPt.GetY()) maxX = max(maxX, controlPt.GetX()) maxY = max(maxY, controlPt.GetY()) # Types: # ogl.CONTROL_POINT_HORIZONTAL # ogl.CONTROL_POINT_DIAGONAL # ogl.CONTROL_POINT_VERTICAL width, height = pt._controlPointDragEndWidth, pt._controlPointDragEndHeight # pt._controlPointDragPosX pt._controlPointDragPosY # pt._controlPointDragStartX, pt._controlPointDragStartY canvas = shape.GetCanvas() dc = wx.ClientDC(canvas) dc.SetPen(wx.Pen(wx.Colour(255, 255, 255), 1, wx.DOT)) dc.SetBrush(wx.TRANSPARENT_BRUSH) canvas.Refresh() canvas.Update() type = shape.AnnotationType if type == "CIRCLE" or type == "RECTANGLE" or type == "SCALEBAR": x, y, w, h = pt._controlPointDragPosX, pt._controlPointDragPosY, pt._controlPointDragEndWidth, pt._controlPointDragEndHeight x0, y0, cw, ch = self.GetCanvas().GetClientRect() # The outline drawing appears offset on Mac at least. compensation = 4 points = [ [x - w / 2.0 - compensation, y - h / 2.0 - compensation], [x + w / 2.0 - compensation, y - h / 2.0 - compensation], [x + w / 2.0 - compensation, y + h / 2.0 - compensation], [x - w / 2.0 - compensation, y + h / 2.0 - compensation], [x - w / 2.0 - compensation, y - h / 2.0 - compensation], ] points = [(x + x0, y + y0) for (x, y) in points] dc.DrawLines(points)
def onSchShortest(self, e): ''' button search shortest 1. get the choice from combo box 2. find the shortest path using self.graph 3. return text output and set to textCtrl value 4. get the coordinates of the cities along the path 5. call function convPosition() to convert from longitute/latitute to screen coordinates and save them to global variables 6. draw lines on bitmap ''' ''' draw original map and lines ???why need draw here ''' dc = wx.ClientDC(self.panel5) img = self.img pnSize = self.panel5.GetSize() imgSize = img.GetSize() newPosLength = 0 newPosHeight = 0 if (imgSize[0] * 1.0 / imgSize[1] > pnSize[0] * 1.0 / pnSize[1]): # if the image l/b larger than that of panel # the image's length should be the same as that of the panel newImgLength = pnSize[0] newImgHeight = pnSize[0] * imgSize[1] / imgSize[0] newPosHeight = (pnSize[1] - newImgHeight) / 2 else: newImgHeight = pnSize[1] newImgLength = pnSize[1] * imgSize[0] / imgSize[1] newPosLength = (pnSize[0] - newImgLength) / 2 #print newPosLength, newPosHeight img = img.Scale(newImgLength, newImgHeight) png = img.ConvertToBitmap() dc.DrawBitmapPoint(png, (newPosLength, newPosHeight)) # draw dots # draw lines unit = (pnSize[0] + pnSize[1]) / 100 k = unit #k is the coefficient for the middle point of the spline #initialize the previous positions (x1, x2, y1, y2) = (0, 0, 0, 0) dc.SetPen(wx.Pen('BLUE')) for item in self.lineList: (bPosX, bPosY) = self.convPosition((newImgLength, newImgHeight), (item[0], item[1])) (ePosX, ePosY) = self.convPosition((newImgLength, newImgHeight), (item[2], item[3])) (x3, y3, x4, y4) = (bPosX + newPosLength, bPosY + newPosHeight, ePosX + newPosLength, ePosY + newPosHeight) if (x1 == x3 and x2 == x4 and y1 == y3 and y2 == y4): k = k + unit else: k = unit x1 = x3 x2 = x4 y1 = y3 y2 = y4 #(xm, ym)is the middle point for spline xm = (x1 + x2) / 2 ym = (y1 + y2) / 2 (rx, ry) = self.verticalVect(x1, y1, x2, y2) ''' (rx,ry)is a vector with length of 1 vertical to the vector from 1 to 2 ''' xm = xm + k * rx ym = ym + k * ry dc.DrawSpline(((x1, y1), (xm, ym), (x2, y2))) departure = self.cbDep.GetValue() destin = self.cbDes.GetValue() if departure == destin: self.tc.SetValue( 'Departure airport and destination airport are the same!') else: # set txtCtrl value schResult = self.graph.findShortestPath(departure, destin) self.shortestPath = schResult[1] self.tc.SetValue(schResult[0]) dc.SetPen(wx.Pen('RED')) for item in schResult[1]: # draw lines (bPosX, bPosY) = self.convPosition( (newImgLength, newImgHeight), (item[0], item[1])) (ePosX, ePosY) = self.convPosition( (newImgLength, newImgHeight), (item[2], item[3])) (x1, y1, x2, y2) = (bPosX + newPosLength, bPosY + newPosHeight, ePosX + newPosLength, ePosY + newPosHeight) xm = (x1 + x2) / 2 ym = (y1 + y2) / 2 (rx, ry) = self.verticalVect(x1, y1, x2, y2) xm = xm + unit * rx ym = ym + unit * ry dc.DrawSpline(((x1, y1), (xm, ym), (x2, y2))) dc.SetTextForeground('Red') dc.DrawText(item[4], xm, ym) dc.SetTextForeground('Black') dc.SetPen(wx.Pen('Black')) airportList = self.graph.getAirportPositions() for item in airportList: imgPos = self.convPosition((newImgLength, newImgHeight), (item[1], item[2])) dc.DrawCircle(imgPos[0] + newPosLength, imgPos[1] + newPosHeight, 5) dc.DrawText(item[0], imgPos[0] + newPosLength + 5, imgPos[1] + newPosHeight + 5)
def setStartOnDc_p(self, evt): """set the first duration point in grid""" self.startOnDc += 1 #print self.startOnDc dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.DrawIt(dc)
def Draw(self, Force=False): """ Canvas.Draw(Force=False) Re-draws the canvas. Note that the buffer will not be re-drawn unless something has changed. If you change a DrawObject directly, then the canvas will not know anything has changed. In this case, you can force a re-draw by passing int True for the Force flag: Canvas.Draw(Force=True) There is a main buffer set up to double buffer the screen, so you can get quick re-draws when the window gets uncovered. If there are any objects in self._ForeDrawList, then the background gets drawn to a new buffer, and the foreground objects get drawn on top of it. The final result if blitted to the screen, and stored for future Paint events. This is done so that you can have a complicated background, but have something changing on the foreground, without having to wait for the background to get re-drawn. This can be used to support simple animation, for instance. """ if N.sometrue(self.PanelSize <= 2): # it's possible for this to get called before being properly initialized. return if self.Debug: start = clock() ScreenDC = wx.ClientDC(self) ViewPortWorld = N.array((self.PixelToWorld( (0, 0)), self.PixelToWorld(self.PanelSize))) self.ViewPortBB = N.array( (N.minimum.reduce(ViewPortWorld), N.maximum.reduce(ViewPortWorld))) dc = wx.MemoryDC() dc.SelectObject(self._Buffer) if self._BackgroundDirty or Force: dc.SetBackground(self.BackgroundBrush) dc.Clear() if self._HTBitmap is not None: HTdc = wx.MemoryDC() HTdc.SelectObject(self._HTBitmap) HTdc.Clear() else: HTdc = None if self.GridUnder is not None: self.GridUnder._Draw(dc, self) self._DrawObjects(dc, self._DrawList, ScreenDC, self.ViewPortBB, HTdc) self._BackgroundDirty = False del HTdc if self._ForeDrawList: ## If an object was just added to the Foreground, there might not yet be a buffer if self._ForegroundBuffer is None: self._ForegroundBuffer = wx.Bitmap(self.PanelSize[0], self.PanelSize[1]) dc = wx.MemoryDC( ) ## I got some strange errors (linewidths wrong) if I didn't make a new DC here dc.SelectObject(self._ForegroundBuffer) dc.DrawBitmap(self._Buffer, 0, 0) if self._ForegroundHTBitmap is not None: ForegroundHTdc = wx.MemoryDC() ForegroundHTdc.SelectObject(self._ForegroundHTBitmap) ForegroundHTdc.Clear() if self._HTBitmap is not None: #Draw the background HT buffer to the foreground HT buffer ForegroundHTdc.DrawBitmap(self._HTBitmap, 0, 0) else: ForegroundHTdc = None self._DrawObjects(dc, self._ForeDrawList, ScreenDC, self.ViewPortBB, ForegroundHTdc) if self.GridOver is not None: self.GridOver._Draw(dc, self) ScreenDC.Blit(0, 0, self.PanelSize[0], self.PanelSize[1], dc, 0, 0) # If the canvas is in the middle of a zoom or move, # the Rubber Band box needs to be re-drawn ##fixme: maybe GUIModes should never be None, and rather have a Do-nothing GUI-Mode. if self.GUIMode is not None: self.GUIMode.UpdateScreen() if self.Debug: print("Drawing took %f seconds of CPU time" % (clock() - start)) if self._HTBitmap is not None: self._HTBitmap.SaveFile('junk.png', wx.BITMAP_TYPE_PNG) ## Clear the font cache. If you don't do this, the X font server ## starts to take up Massive amounts of memory This is mostly a ## problem with very large fonts, that you get with scaled text ## when zoomed in. DrawObject.FontList = {}
def onClear(self, e): ''' When either comobox is set to a new value, or the button reverse direction is clicked, clear the textbox and the shortest line in the graph ''' self.tc.Clear() dc = wx.ClientDC(self.panel5) img = self.img pnSize = self.panel5.GetSize() imgSize = img.GetSize() newPosLength = 0 newPosHeight = 0 if (imgSize[0] * 1.0 / imgSize[1] > pnSize[0] * 1.0 / pnSize[1]): # if the image l/b larger than that of panel # the image's length should be the same as that of the panel newImgLength = pnSize[0] newImgHeight = pnSize[0] * imgSize[1] / imgSize[0] newPosHeight = (pnSize[1] - newImgHeight) / 2 else: newImgHeight = pnSize[1] newImgLength = pnSize[1] * imgSize[0] / imgSize[1] newPosLength = (pnSize[0] - newImgLength) / 2 #print newPosLength, newPosHeight img = img.Scale(newImgLength, newImgHeight) png = img.ConvertToBitmap() dc.DrawBitmapPoint(png, (newPosLength, newPosHeight)) # draw dots # draw lines unit = (pnSize[0] + pnSize[1]) / 100 k = unit #k is the coefficient for the middle point of the spline #initialize the previous positions (x1, x2, y1, y2) = (0, 0, 0, 0) dc.SetPen(wx.Pen('BLUE')) for item in self.lineList: (bPosX, bPosY) = self.convPosition((newImgLength, newImgHeight), (item[0], item[1])) (ePosX, ePosY) = self.convPosition((newImgLength, newImgHeight), (item[2], item[3])) (x3, y3, x4, y4) = (bPosX + newPosLength, bPosY + newPosHeight, ePosX + newPosLength, ePosY + newPosHeight) if (x1 == x3 and x2 == x4 and y1 == y3 and y2 == y4): k = k + unit else: k = unit x1 = x3 x2 = x4 y1 = y3 y2 = y4 #(xm, ym)is the middle point for spline xm = (x1 + x2) / 2 ym = (y1 + y2) / 2 (rx, ry) = self.verticalVect(x1, y1, x2, y2) ''' (rx,ry)is a vector with length of 1 vertical to the vector from 1 to 2 ''' xm = xm + k * rx ym = ym + k * ry dc.DrawSpline(((x1, y1), (xm, ym), (x2, y2))) dc.SetPen(wx.Pen('Black')) airportList = self.graph.getAirportPositions() for item in airportList: imgPos = self.convPosition((newImgLength, newImgHeight), (item[1], item[2])) dc.DrawCircle(imgPos[0] + newPosLength, imgPos[1] + newPosHeight, 5) dc.DrawText(item[0], imgPos[0] + newPosLength + 5, imgPos[1] + newPosHeight + 5)
def SetFont(self, font): """Set the font for the label""" wx.Panel.SetFont(self, font) self.SetLabel(self.label) self.Draw(wx.ClientDC(self))
global frame global bmp dc = wx.PaintDC(frame) dc.DrawBitmap(bmp, 0, 0, True) return app = wx.App() frame = wx.Frame(None, wx.ID_ANY, "Shaped Window", style=wx.FRAME_SHAPED | wx.NO_BORDER | wx.CLOSE_BOX) img = wx.Image("./faceman.png", wx.BITMAP_TYPE_PNG) img.SetMaskColour(255, 255, 255) img.SetMask(True) bmp = wx.BitmapFromImage(img) frame.SetClientSize((bmp.GetWidth(), bmp.GetHeight())) dc = wx.ClientDC(frame) dc.DrawBitmap(bmp, 0, 0, True) reg = wx.RegionFromBitmap(bmp) frame.SetShape(reg) frame.Bind(wx.EVT_PAINT, OnPaint) frame.Bind(wx.EVT_WINDOW_CREATE, OnCreate) frame.Show(True) app.MainLoop()
def _getIndicatorDC(self): dc = wx.ClientDC(self.GetMainWindow()) dc.SetPen(wx.Pen(wx.WHITE, 3)) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetLogicalFunction(wx.XOR) return dc
def DoGetBestSize(self): """Calculate the best size of the button @return: wx.Size """ width = 8 height = 10 label_width = 0 label_height = 0 caption_width = 0 caption_height = 0 if self._bmp['enable'] is not None: bsize = self._bmp['enable'].GetSize() width += (bsize[0] + 12) height = bsize[1] + (self._margin * 2) else: width += 10 if self.GetLabel(): lsize = self.GetTextExtent(self.GetLabel()) label_width = lsize[0] label_height = lsize[1] if self._label2 != '': if wx.Platform == '__WXMAC__': dc = wx.GraphicsContext.CreateMeasuringContext() else: dc = wx.ClientDC(self) #dc = wx.MemoryDC() dc.SetFont(self._label2_font) min_w, min_h = self.GetSize() #self._size if min_w == -1: min_w = 120 txt_w = min_w - width - 10 if wx.Platform == '__WXGTK__': txt_w += 40 lines = wx.lib.wordwrap.wordwrap(self._label2, width=txt_w, dc=dc) self._caption_lines = lines offset = 0 if wx.Platform == "__WXMAC__": buffer = 4 else: buffer = 0 for line in lines.splitlines(): line_w, line_h = dc.GetTextExtent(line) if line_w > caption_width: caption_width = line_w caption_height += line_h + buffer if (wx.Platform == '__WXMSW__'): caption_height += 4 width += max(caption_width, label_width) + 4 height = max(caption_height + label_height + 12, height) if self._menu is not None or self._style & MB_STYLE_DROPARROW: width += 12 if width < self.GetSize()[0]: #self._size[0] : width = self.GetSize()[0] best = wx.Size(width, height) self.CacheBestSize(best) return best
def setZoom_in(self, evt): """zoom in the grid""" if self.steps >= 4.0: self.steps = self.steps * .5 dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.DrawIt(dc)
def clear(self): dc = wx.ClientDC(self) dc.Clear()
def setZoom_out(self, evt): """zoom in the grid""" self.steps = self.steps * 2 dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.DrawIt(dc)
def OnDragLeft(self, draw, x, y, keys=0, attachment=0): self.SetX(x) self.SetY(y) self._shape.SetPointsFromControl(self) self._shape.updateEraseRect() self._shape.OnDraw(wx.ClientDC(self.GetCanvas()))
def timeGridSetting(self, evt): """time grid variable""" self.stepsMultiplier = self.stepsDict[self.stepsIndex] #print self.stepsMultiplier dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.DrawIt(dc)
def RebootPlayer(self): self.prgDialog = wx.ProgressDialog(tr("dlg_title_reboot"), wordwrap(tr("dlg_msg_reboot"), 350, wx.ClientDC(self)), parent = self) Publisher.subscribe(self.RebootComplete, "boot_complete") self.prgDialog.Pulse() msgData = network.messages.getMessage(PLAYER_REBOOT) network.udpconnector.sendMessage(msgData, self.host, UDP_REBOOT_TIMEOUT)
def recordPoint(self, evt): """record position on left down""" position = evt.GetPositionTuple() toappend = 1 ktime = 0 kpitch = 0 kquality = .1 kfeed = 0 klf = 20 khf = 15000 kpan = 0.5 kreso = 0.0 kdist = 0.0 kinvol = 1.0 kinvolr = 0.0 koutvol = 1.0 koutvolr = 0.0 kmode = 0 #add condition to chech if on the grid if ((self.bordx / 2) <= position[0] <= (self.dcw - self.bordx / 2)) and ( (self.bordy / 2) <= position[1] <= (self.dch - self.bordy / 2)): #if point is on the grid - create a delay musicalV = self.screenToValues(position) ktime = musicalV[0] if self.timeQuantize: #se tempo quantizzato ktime = floatops.floatMultRound(ktime, self.stepsMultiplier) kpitch = musicalV[1] if self.pitcQuantize: #se pitch quantizzato kpitch = floatops.floatMultRound(kpitch, 1.0) ind = 1 if len(self.points) == 0: evento = [ ind, ktime, kpitch, kquality, kfeed, klf, khf, kpan, kreso, kdist, kinvol, kinvolr, koutvol, koutvolr, kmode ] self.points.append(evento) else: toappend = 1 count = 0 while count < len(self.points): tocheck = self.points[count] if tocheck[0] <= 0: ind = count + 1 evento = [ ind, ktime, kpitch, kquality, kfeed, klf, khf, kpan, kreso, kdist, kinvol, kinvolr, koutvol, koutvolr, kmode ] self.points[count] = evento toappend = 0 break count += 1 if toappend == 1: ind = len(self.points) + 1 evento = [ ind, ktime, kpitch, kquality, kfeed, klf, khf, kpan, kreso, kdist, kinvol, kinvolr, koutvol, koutvolr, kmode ] self.points.append(evento) #to csound ftable = 'f %i 0 16 -2 %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f' % ( evento[0] + 100, evento[0], evento[1], evento[2], evento[3], evento[4], evento[5], evento[6], evento[7], evento[8], evento[9], evento[10], evento[11], evento[12], evento[13], evento[14]) instr = 'i %f 0.02 -1' % (30.0 + evento[0] * 0.001) #print self.points self.cSound.InputMessage(ftable + '\n' + instr) #update interface elif ((self.bordx / 2) <= position[0] <= (self.dcw - self.bordx / 2)) and ( ((self.bordy / 2) > position[1]) or ((self.dch - self.bordy / 2) < position[1])): #if point is above or below the grid - recycle musicalV = self.screenToValues(position) ktime = musicalV[0] if self.timeQuantize: #se tempo quantizzato ktime = floatops.floatMultRound(ktime, self.stepsMultiplier) #self.recycle[0] = ktime self.recycle = ktime #ToCsound self.cSound.TableSet(99, 1, ktime) instr = 'i 40 0.02 -1' self.cSound.InputMessage(instr) #Update inputPanel self.GetParent().inPanel.updateGraphics("ON", ktime) dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.DrawIt(dc)
def __OnUpdateAnimation(self, e): dc = wx.ClientDC(self.GetGridWindow()) self.PrepareDC(dc) for key in self.__animations.keys(): row, col, id = key if (not self.IsRectVisible(self.CellToRect(row, col))): self.__animations.pop(key) continue animation = self.__animations[key] animation.Update(dc) # used to test this class ##class MainFrame(wx.Frame): ## def __init__(self, parent, title): ## wx.Frame.__init__(self, parent, -1, title, size = (640, 480)) ## grid = FGrid(self) ## self.__grid = grid ## ## grid.AppendContext("Show All Columns", self.__OnShowAllColumns) ## ## grid.AppendColumn(1, "Filename") ## grid.AppendColumn(2, "Thumbnails") ## grid.AppendColumn(3, "Result") ## grid.AppendColumn(4, "A really really really long name") ## grid.AppendColumn(5, "Blah") ## grid.AppendColumn(6, "Foo") ## grid.AppendColumn(7, "Bar") ## grid.AppendColumn(8, "Hello") ## grid.AppendColumn(9, "Test") ## ## grid.AppendRow(1) ## grid.AppendRow(2) ## grid.AppendRow(3) ## grid.AppendRow(4) ## ## grid.InsertData(1, 1, "A") ## grid.InsertData(2, 1, "G") ## grid.InsertData(3, 1, "E") ## grid.InsertData(4, 1, "A") ## ## grid.InsertData(1, 2, "Z(A)") ## grid.InsertData(2, 2, "X(G)") ## grid.InsertData(3, 2, "Y(E)") ## grid.InsertData(4, 2, "A(A)") ## ## grid.InsertData(1, 3, "F(A)") ## grid.InsertData(2, 3, "D(G)") ## grid.InsertData(3, 3, "H(E)") ## grid.InsertData(4, 3, "A(A)") ## ## grid.DeleteRow(4) ## ## grid.SetColumnOrder([1,]) ## grid.SortColumn(0, True) ## grid.SetColumnOrder([2,]) ## # grid.SetColumnOrder([9, 8, 3, 1]) ## ## def __OnShowAllColumns(self, e): ## self.__grid.SetColumnOrder([1,2,3,4,5,6,7,8,9]) ## ##app = wx.PySimpleApp() ##frame = MainFrame(None, "Test") ##frame.Show() ##app.MainLoop()
def RecalculateTabSizes(self): numtabs = len(self._pages) if numtabs == 0: return width = self.GetSize().GetWidth() - self._tab_margin_left - self._tab_margin_right tabsep = self._art.GetMetric(RIBBON_ART_TAB_SEPARATION_SIZE) x = self._tab_margin_left y = 0 if width >= self._tabs_total_width_ideal: # Simple case: everything at ideal width for info in self._pages: info.rect.x = x info.rect.y = y info.rect.width = info.ideal_width info.rect.height = self._tab_height x += info.rect.width + tabsep self._tab_scroll_buttons_shown = False self._tab_scroll_left_button_rect.SetWidth(0) self._tab_scroll_right_button_rect.SetWidth(0) elif width < self._tabs_total_width_minimum: # Simple case: everything minimum with scrollbar for info in self._pages: info.rect.x = x info.rect.y = y info.rect.width = info.minimum_width info.rect.height = self._tab_height x += info.rect.width + tabsep if not self._tab_scroll_buttons_shown: self._tab_scroll_left_button_state = RIBBON_SCROLL_BTN_NORMAL self._tab_scroll_right_button_state = RIBBON_SCROLL_BTN_NORMAL self._tab_scroll_buttons_shown = True temp_dc = wx.ClientDC(self) self._tab_scroll_left_button_rect.SetWidth(self._art.GetScrollButtonMinimumSize(temp_dc, self, RIBBON_SCROLL_BTN_LEFT | RIBBON_SCROLL_BTN_NORMAL | RIBBON_SCROLL_BTN_FOR_TABS).GetWidth()) self._tab_scroll_left_button_rect.SetHeight(self._tab_height) self._tab_scroll_left_button_rect.SetX(self._tab_margin_left) self._tab_scroll_left_button_rect.SetY(0) self._tab_scroll_right_button_rect.SetWidth(self._art.GetScrollButtonMinimumSize(temp_dc, self, RIBBON_SCROLL_BTN_RIGHT | RIBBON_SCROLL_BTN_NORMAL | RIBBON_SCROLL_BTN_FOR_TABS).GetWidth()) self._tab_scroll_right_button_rect.SetHeight(self._tab_height) self._tab_scroll_right_button_rect.SetX(self.GetClientSize().GetWidth() - self._tab_margin_right - self._tab_scroll_right_button_rect.GetWidth()) self._tab_scroll_right_button_rect.SetY(0) if self._tab_scroll_amount == 0: self._tab_scroll_left_button_rect.SetWidth(0) elif self._tab_scroll_amount + width >= self._tabs_total_width_minimum: self._tab_scroll_amount = self._tabs_total_width_minimum - width self._tab_scroll_right_button_rect.SetX(self._tab_scroll_right_button_rect.GetX() + self._tab_scroll_right_button_rect.GetWidth()) self._tab_scroll_right_button_rect.SetWidth(0) for info in self._pages: info.rect.x -= self._tab_scroll_amount else: self._tab_scroll_buttons_shown = False self._tab_scroll_left_button_rect.SetWidth(0) self._tab_scroll_right_button_rect.SetWidth(0) # Complex case: everything sized such that: minimum <= width < ideal # # Strategy: # 1) Uniformly reduce all tab widths from ideal to small_must_have_separator_width # 2) Reduce the largest tab by 1 pixel, repeating until all tabs are same width (or at minimum) # 3) Uniformly reduce all tabs down to their minimum width # smallest_tab_width = 10000 total_small_width = tabsep * (numtabs - 1) for info in self._pages: if info.small_must_have_separator_width < smallest_tab_width: smallest_tab_width = info.small_must_have_separator_width total_small_width += info.small_must_have_separator_width if width >= total_small_width: # Do (1) total_delta = self._tabs_total_width_ideal - total_small_width total_small_width -= tabsep*(numtabs - 1) width -= tabsep*(numtabs - 1) for info in self._pages: delta = info.ideal_width - info.small_must_have_separator_width info.rect.x = x info.rect.y = y info.rect.width = info.small_must_have_separator_width + delta*(width - total_small_width)/total_delta info.rect.height = self._tab_height x += info.rect.width + tabsep total_delta -= delta total_small_width -= info.small_must_have_separator_width width -= info.rect.width else: total_small_width = tabsep*(numtabs - 1) for info in self._pages: if info.minimum_width < smallest_tab_width: total_small_width += smallest_tab_width else: total_small_width += info.minimum_width if width >= total_small_width: # Do (2) sorted_pages = [] for info in self._pages: # Sneaky obj array trickery to not copy the tab descriptors sorted_pages.append(info) sorted_pages.sort(self.OrderPageTabInfoBySmallWidthAsc) width -= tabsep*(numtabs - 1) for i, info in enumerate(self._pages): if info.small_must_have_separator_width*(numtabs - i) <= width: info.rect.width = info.small_must_have_separator_width else: info.rect.width = width/(numtabs - i) width -= info.rect.width for i, info in enumerate(self._pages): info.rect.x = x info.rect.y = y info.rect.height = self._tab_height x += info.rect.width + tabsep sorted_pages.pop(numtabs - (i + 1)) else: # Do (3) total_small_width = (smallest_tab_width + tabsep)*numtabs - tabsep total_delta = total_small_width - self._tabs_total_width_minimum total_small_width = self._tabs_total_width_minimum - tabsep*(numtabs - 1) width -= tabsep*(numtabs - 1) for info in self._pages: delta = smallest_tab_width - info.minimum_width info.rect.x = x info.rect.y = y info.rect.width = info.minimum_width + delta*(width - total_small_width)/total_delta info.rect.height = self._tab_height x += info.rect.width + tabsep total_delta -= delta total_small_width -= info.minimum_width width -= info.rect.width
def OnMotion(self, event): print("OnMotion") if event.Dragging() and event.LeftIsDown(): dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.drawMotion(dc, event) event.Skip()
def DrawLine(self): dc = wx.ClientDC(self) dc.DrawLine(50, 60, 190, 60)
def InitFonts(self): dc = wx.ClientDC(self) self.font = self.NiceFontForPlatform() dc.SetFont(self.font) self.fw = dc.GetCharWidth() self.fh = dc.GetCharHeight()
def OnEndDragLeft(self, x, y, keys = 0, attachment = 0): dc = wx.ClientDC(self.GetCanvas()) self.GetCanvas().PrepareDC(dc) dividedObject = self._shape if not dividedObject.GetRegions()[self.regionId]: return thisRegion = dividedObject.GetRegions()[self.regionId] nextRegion = None dc.SetLogicalFunction(wx.COPY) if self._canvas.HasCapture(): self._canvas.ReleaseMouse() # Find the old top and bottom of this region, # and calculate the new proportion for this region # if legal. currentY = dividedObject.GetY() - dividedObject.GetHeight() / 2.0 maxY = dividedObject.GetY() + dividedObject.GetHeight() / 2.0 # Save values theRegionTop = 0 nextRegionBottom = 0 for i in range(len(dividedObject.GetRegions())): region = dividedObject.GetRegions()[i] proportion = region._regionProportionY yy = currentY + dividedObject.GetHeight() * proportion actualY = min(maxY, yy) if region == thisRegion: thisRegionTop = currentY if i + 1 < len(dividedObject.GetRegions()): nextRegion = dividedObject.GetRegions()[i + 1] if region == nextRegion: nextRegionBottom = actualY currentY = actualY if not nextRegion: return # Check that we haven't gone above this region or below # next region. if y <= thisRegionTop or y >= nextRegionBottom: return dividedObject.EraseLinks(dc) # Now calculate the new proportions of this region and the next region thisProportion = float(y - thisRegionTop) / dividedObject.GetHeight() nextProportion = float(nextRegionBottom - y) / dividedObject.GetHeight() thisRegion.SetProportions(0, thisProportion) nextRegion.SetProportions(0, nextProportion) self._yoffset = y - dividedObject.GetY() # Now reformat text for i, region in enumerate(dividedObject.GetRegions()): if region.GetText(): s = region.GetText() dividedObject.FormatText(dc, s, i) dividedObject.SetRegionSizes() dividedObject.Draw(dc) dividedObject.GetEventHandler().OnMoveLinks(dc)
def Update(self): dc = wx.BufferedDC(wx.ClientDC(self), self.buffer) self.DrawFace(dc) self.DrawPOV(dc)
def AddButton(self, button_id, label, bitmap, bitmap_small=wx.NullBitmap, bitmap_disabled=wx.NullBitmap, bitmap_small_disabled=wx.NullBitmap, kind=RIBBON_BUTTON_NORMAL, help_string="", client_data=None): if not bitmap.IsOk() and not bitmap_small.IsOk(): raise Exception("exception") if not self._buttons: if bitmap.IsOk(): self._bitmap_size_large = bitmap.GetSize() if not bitmap_small.IsOk(): w, h = self._bitmap_size_large self._bitmap_size_small = wx.Size(0.5 * w, 0.5 * h) if bitmap_small.IsOk(): self._bitmap_size_small = bitmap_small.GetSize() if not bitmap.IsOk(): w, h = self._bitmap_size_small self._bitmap_size_large = wx.Size(2 * w, 2 * h) base = RibbonButtonBarButtonBase() base.id = button_id base.label = label base.bitmap_large = bitmap if not base.bitmap_large.IsOk(): base.bitmap_large = self.MakeResizedBitmap(base.bitmap_small, self._bitmap_size_large) elif base.bitmap_large.GetSize() != self._bitmap_size_large: base.bitmap_large = self.MakeResizedBitmap(base.bitmap_large, self._bitmap_size_large) base.bitmap_small = bitmap_small if not base.bitmap_small.IsOk(): base.bitmap_small = self.MakeResizedBitmap(base.bitmap_large, self._bitmap_size_small) elif base.bitmap_small.GetSize() != self._bitmap_size_small: base.bitmap_small = self.MakeResizedBitmap(base.bitmap_small, self._bitmap_size_small) base.bitmap_large_disabled = bitmap_disabled if not base.bitmap_large_disabled.IsOk(): base.bitmap_large_disabled = self.MakeDisabledBitmap( base.bitmap_large) base.bitmap_small_disabled = bitmap_small_disabled if not base.bitmap_small_disabled.IsOk(): base.bitmap_small_disabled = self.MakeDisabledBitmap( base.bitmap_small) base.kind = kind base.help_string = help_string base.client_data = client_data base.state = 0 temp_dc = wx.ClientDC(self) self.FetchButtonSizeInfo(base, RIBBON_BUTTONBAR_BUTTON_SMALL, temp_dc) self.FetchButtonSizeInfo(base, RIBBON_BUTTONBAR_BUTTON_MEDIUM, temp_dc) self.FetchButtonSizeInfo(base, RIBBON_BUTTONBAR_BUTTON_LARGE, temp_dc) # TODO self._buttons.append(base) self._layouts_valid = False return base