def draw(self, parent, dc, obj, rect): # obj: (self,chart,time,val) # rect: (left,top,right,bottom,width,height) axe = parent.chart2axe(obj[1]) a, b = axe.get_ylim() y = rect[3] - int((obj[3] - a) * (rect[5] / (b - a))) #print 'rect:',rect,'y range:',a,b,b-a,' val=',obj[3],(obj[3] - a),' y=',y if y <= rect[3] and y >= rect[1]: lc = wx.NamedColor("BLACK") bg = wx.NamedColor("RED") font = wx.Font(8, wx.ROMAN, wx.NORMAL, wx.NORMAL) dc.SetPen(wx.Pen(lc, 1, wx.SOLID)) dc.DrawLine(rect[0], y, rect[2], y) label = parent.GetYLabel(axe, obj[3]) textExtent = self.m_parent.GetFullTextExtent(label, font) DrawRectLabel(dc, label, rect[0], y, textExtent[0], textExtent[1], lc, bg, font, vert='top', horz='right')
def Set_Canvas ( self, BG_Color = None, grid_color = None ) : if grid_color : if not isinstance ( grid_color, wx.Colour ) : grid_color = wx.NamedColor ( grid_color ) self.Grid_Color = grid_color if BG_Color : if not isinstance ( BG_Color, wx.Colour ) : BG_Color = wx.NamedColor ( BG_Color ) self.BG_Color = BG_Color self.Brush = wx.Brush ( BG_Color ) self.Pen = wx.Pen ( self.Grid_Color, 1, wx.SOLID ) self._Redraw_Screen ()
def set_additional_properties(self, slider_width=11, slider_button_width=20, slider_increment=1.0, background_increment=10.0, button_increment=0.1, pointer_color=wx.NamedColor("RED"), auto_increment=True, max_button_increment=0.1, min_settable=None, **kwds): """Autoincrement overrides the values of slider_increment, background_increment, and button_increment. In this mode the control calculates reasonable values for these parameters depending on its size. When the user clicks on the background, the value changes by the background_increment. When the user clicks on a vernier button, the value changes by the button_increment. When the user drags the slider, the value changes by slider increment. When the user right clicks on the control, a Dialog asks for text entry of the new value. A new value is always rounded off to the nearest whole number multiple of the relevant increment. The max_button increment sets an upper limit on the button increment when auto_increment is on. If min_settable is not none, do not fire off a new value event if the control's value is less than min_settable. """ # pylint: disable-msg=w0201,w0221 wxBar.set_additional_properties(self, **kwds) self._slider_width = slider_width self._slider_button_width = slider_button_width self._slider_increment = slider_increment self._background_increment = background_increment self._button_increment = button_increment self._pointer_color = pointer_color self._auto_increment = auto_increment self._max_button_increment = max_button_increment self._min_settable = min_settable
def __init__(self, ): wx.Frame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350)) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure() self.axes = self.figure.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) self.axes.plot(t, s) self.axes.set_xlabel('t') self.axes.set_ylabel('sin(t)') self.figure_canvas = FigureCanvas(self, -1, self.figure) # Note that event is a MplEvent self.figure_canvas.mpl_connect('motion_notify_event', self.UpdateStatusBar) self.figure_canvas.Bind(wx.EVT_ENTER_WINDOW, self.ChangeCursor) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.figure_canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.SetSizer(self.sizer) self.Fit() self.statusBar = wx.StatusBar(self, -1) self.statusBar.SetFieldsCount(1) self.SetStatusBar(self.statusBar) self.toolbar = NavigationToolbar2Wx(self.figure_canvas) self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) self.toolbar.Show()
def StyleDefault(self): """Clears the editor styles to default @postcondition: style is reset to default """ self.StyleClearAll() self.SetCaretForeground(wx.NamedColor("black")) self.Colourise(0, -1)
def draw_slider(self, dc): dc.SetPen(wx.Pen(wx.NamedColor("BLACK"))) dc.SetBrush(wx.Brush(self._pointer_color)) dc.DrawRectangle(self._ptr_rect.x, self._ptr_rect.y, self._ptr_rect.width, self._ptr_rect.height) dc.DrawLine(self._value_point, self._ptr_rect.y + self._ptr_rect.height, self._value_point, self._ptr_rect.y + self._ptr_rect.height - 10)
def InitPaint(self, parent, pos, max): self.pos = wx.Point(*pos) if max: self.max = wx.Point(*max) else: self.max = None self.parent = parent self.font = wx.Font(8, wx.ROMAN, wx.NORMAL, wx.NORMAL) self.bg = wx.NamedColor("YELLOW") return wx.MemoryDC()
def draw(self, parent, dc, obj, rect): # obj: (self,chart,time,val,offtime,periodtime) # rect: (left,top,right,bottom,width,height) axe = parent.chart2axe(obj[1]) time = obj[2] #print 'time',time,' initial:',obj[4],' current:',parent.GetIndexTime(0),' new time:',obj[4] - parent.GetIndexTime(0) + time time = obj[4] - parent.GetIndexTime(0) + time # update time on the grid a, b = axe.get_xlim() period = b - a #print 'period:',period,' inital period:',obj[5],' delta:',obj[5]-period, ' new time:',time - (obj[5]-period) / 2 time = time - int((obj[5] - period) / 2) if time >= a and time <= b: x = rect[0] + int((time - a) * (rect[4] / period)) #print 'rect:',rect,'x range:',a,b,b-a,' val=',time,(time - a),' x=',x lc = wx.NamedColor("BLACK") bg = wx.NamedColor("BLUE") font = wx.Font(8, wx.ROMAN, wx.NORMAL, wx.NORMAL) dc.SetPen(wx.Pen(lc, 1, wx.SOLID)) dc.DrawLine(x, rect[1], x, rect[3]) label = parent.GetXLabel(time) textExtent = self.m_parent.GetFullTextExtent(label, font) DrawRectLabel(dc, label, x, rect[3], textExtent[0], textExtent[1], lc, bg, font, vert='bottom', horz='center')
def __init__(self, parent): super(PalletPanel, self).__init__(parent) # Layout gsizer = wx.GridSizer(3, 3, 2, 2) for colour in ("red", "green", "blue", "yellow", "purple", "black", "white", "pink", "orange", "grey", "navy", "cyan"): cobj = wx.NamedColor(colour) cs = colourselect.ColourSelect(self, colour=cobj, size=(20, 20)) gsizer.Add(cs) self.SetSizer(gsizer)
def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, size=(550, 350)) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.add_choices() #self.add_button_plot() self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.add_toolbar() # comment this out for no toolbar menuBar = wx.MenuBar() # File Menu menu = wx.Menu() menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample") self.Bind(wx.EVT_MENU, self.OnExit) menuBar.Append(menu, "&File") #~ if IS_GTK or IS_WIN: #~ # Signals menu #~ menu = wx.Menu() #~ for i, (mt, signal) in enumerate(signals): #~ bm = mathtext_to_wxbitmap(mt) #~ item = wx.MenuItem(menu, 2000 + i, "") #~ item.SetBitmap(bm) #~ menu.AppendItem(item) #~ self.Bind(wx.EVT_MENU, self.OnChangeSignal, item) #~ menuBar.Append(menu, "&Signals") #~ # Equation Menu #~ menu = wx.Menu() #~ for i, (mt, dist) in enumerate(distributions): #~ bm = mathtext_to_wxbitmap(mt) #~ item = wx.MenuItem(menu, 1000 + i, "") #~ item.SetBitmap(bm) #~ menu.AppendItem(item) #~ self.Bind(wx.EVT_MENU, self.OnChangeDistribution, item) #~ menuBar.Append(menu, "&Distributions") self.SetMenuBar(menuBar) self.SetSizer(self.sizer) self.Fit() # Initial plot self.distribution_name = distributions[0][0] self.signal_name = signals[0][0] self.process()
def __init__(self, parent): wx.Panel.__init__(self, parent, -1) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.timer = wx.Timer(self, -1) self.Bind(wx.EVT_TIMER, self.OnTimer) self.SetBackgroundColour(wx.NamedColor("white")) self.data = gen_data() self.path = gen_path(0.01) self.path.next() self.timer.Start(100)
def __init__(self): wx.Frame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350)) self.SetBackgroundColour(wx.NamedColor('WHITE')) self.figure = Figure() self.axes = self.figure.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) self.axes.plot(t, s) self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.SetSizerAndFit(self.sizer) self.add_toolbar()
def __init__(self): wx.Frame.__init__(self, None, -1, 'PyBrew', size=(550, 350)) self.SetBackgroundColour(wx.NamedColor("WHITE")) try: self.bc = BrewController() except Exception as e: wx.MessageBox(str(e), 'Fatal error') sys.exit(1) self.menubar = wx.MenuBar() i1 = self.addMenuItem(1, 'Quit', 'Quit application', self.OnQuit) self.menubar.Append(i1, '&File') i2 = self.addMenuItem(2, 'Set temp', 'Set regulator temp', self.SetTemp) self.menubar.Append(i2, '&Temp') self.SetMenuBar(self.menubar) sizer = wx.BoxSizer(wx.VERTICAL) self.figure = Figure() if not hasattr(self, 'subplot'): self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) button_sizer = wx.BoxSizer(wx.HORIZONTAL) buttons = self.bc.VALVES.keys() buttons.sort() for k in buttons: valve_button = wx.ToggleButton(self, -1, label=self.bc.VALVES[k], name=k) valve_button.Bind(wx.EVT_TOGGLEBUTTON, self.OnValve) button_sizer.Add(valve_button) sizer.Add(button_sizer) self.SetSizer(sizer) self.Fit() self.axes.axis([0, 100, -1, 100]) self.add_timer()
def __init__(self, parent, id, title, analyse_size): self.width, self.height = analyse_size wx.Frame.__init__(self, parent, id, title, style=wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX)) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure(figsize=(5, 4), dpi=100) self.axes = self.figure.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2*pi*t) self.axes.plot(t, s) self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND) # Capture the paint message # EVT_PAINT(self, self.OnPaint) # self.toolbar = MyNavigationToolbar(self.canvas, True) # self.toolbar.Realize() # if wx.Platform == '__WXMAC__': # # Mac platform (OSX 10.3, MacPython) does not seem to cope with # # having a toolbar in a sizer. This work-around gets the buttons # # back, but at the expense of having the toolbar at the top # self.SetToolBar(self.toolbar) # else: # # On Windows platform, default window size is incorrect, so set # # toolbar width to figure width. # tw, th = self.toolbar.GetSizeTuple() # fw, fh = self.canvas.GetSizeTuple() # # By adding toolbar in sizer, we are able to put it at the bottom # # of the frame - so appearance is closer to GTK version. # # As noted above, doesn't work for Mac. # self.toolbar.SetSize(wxSize(fw, th)) # self.sizer.Add(self.toolbar, 0, wxLEFT | wxEXPAND) # # # update the axes menu on the toolbar # self.toolbar.update() self.Bind(wx.EVT_CLOSE, self.OnClose) self.SetSizer(self.sizer) self.Fit()
def __init__(self): wx.Frame.__init__(self,None,-1, 'CanvasFrame',size=(550,350)) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure(figsize=(5,4), dpi=100) self.axes = self.figure.add_subplot(111) t = arange(0.0,3.0,0.01) s = sin(2*pi*t) self.axes.plot(t,s) self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND) # Capture the paint message wx.EVT_PAINT(self, self.OnPaint) self.toolbar = MyNavigationToolbar(self.canvas, True) self.toolbar.Realize() if wx.Platform == '__WXMAC__': # Mac platform (OSX 10.3, MacPython) does not seem to cope with # having a toolbar in a sizer. This work-around gets the buttons # back, but at the expense of having the toolbar at the top print "Using max workaround!" self.SetToolBar(self.toolbar) else: # On Windows platform, default window size is incorrect, so set # toolbar width to figure width. tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() # By adding toolbar in sizer, we are able to put it at the bottom # of the frame - so appearance is closer to GTK version. # As noted above, doesn't work for Mac. self.toolbar.SetSize(wx.Size(fw, th)) self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) # update the axes menu on the toolbar self.toolbar.update() self.SetSizer(self.sizer) self.Fit()
def onItemExpanding(self, event): item = event.GetItem() if item is not None: term = self.treeCtrl.GetPyData(item) if len(term.parts) > 0 and self.treeCtrl.GetChildrenCount( item) == 0: for childTerm in term.parts: if childTerm.abbreviation is not None: childItem = self.treeCtrl.AppendItem( item, childTerm.name + ' (' + childTerm.abbreviation + ')') else: childItem = self.treeCtrl.AppendItem( item, childTerm.name) self.treeCtrl.SetPyData(childItem, childTerm) if childTerm.obsolete: self.treeCtrl.SetItemTextColour( childItem, wx.NamedColor('GRAY')) if len(childTerm.parts) > 0: self.treeCtrl.SetItemHasChildren(childItem, True)
def makeFrame(self): global canvas #@@@@ # Got this trick for a two stage creation from # http://wiki.wxpython.org/index.cgi/TwoStageCreation pre = wx.PreFrame() self.res = XmlResource(homepath+"/plotwin.xrc") self.res.LoadOnFrame(pre,self.parent,"plotwin") self.PostCreate(pre) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.Show() self.figure = Figure() self.axes = [self.figure.add_subplot(111)] self.canvas = FigureCanvas(self, -1, self.figure) canvas = self.canvas #@@@@ self.sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.sizer) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.Fit() self.addToolbar()
def __init__(self, parent, id, size): self.m_parent = parent self.SetBackgroundColour(wx.NamedColor("WHITE")) # figure me self.figure = Figure(size, dpi=96) self.m_canvas = FigureCanvasEx(self, -1, self.figure) self.m_canvas.m_parent = self GObject.__init__(self, self.m_canvas) PanelPrint.__init__(self, parent, CanvasPrintout, orientation=wx.LANDSCAPE) self.m_canvas.mpl_connect('motion_notify_event', self.mouse_move) self.m_canvas.mpl_connect('button_press_event', self.on_click) self.m_toolbar = iTrade_wxToolbarGraph(self.m_canvas) wx.EVT_LEFT_DOWN(self.m_toolbar, self.OnLeftDown) # Default Tool is IND self.OnToolInd(None) # default parameters self.m_hasChart1Vol = False self.m_hasChart2Vol = False # size everything to fit in panel sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.m_canvas, 1, wx.LEFT | wx.TOP | wx.GROW) sizer.Add(self.m_toolbar, 0, wx.GROW) self.SetSizerAndFit(sizer) wx.EVT_PAINT(self, self.OnPaint) # cursor need a timer self.cursorx, self.cursory = 0, 0 self.m_timer = wx.Timer(self) wx.EVT_TIMER(self, -1, self.OnTimer)
def __init__(self, parent, couleur=None): self.parent = parent wx.Panel.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL | wx.WANTS_CHARS) self.SetBackgroundColour( couleur if couleur is not None else wx.NamedColor(u"WHITE")) vsizer = wx.BoxSizer(wx.VERTICAL) label = u"Tapez une commande ci-dessus, puis appuyez sur [Entrée]." self.resultats = wx.StaticText(self, size=(500, -1), label=label) italic = wx.Font(self.GetFont().GetPointSize(), self.GetFont().GetFamily(), wx.ITALIC, wx.NORMAL) self.resultats.SetFont(italic) self.ligne_commande = LigneCommande(self, longueur=500, action=self.action) vsizer.Add(self.ligne_commande, 1, wx.ALL | wx.EXPAND, 0) vsizer.Add(self.resultats, 1, wx.ALL | wx.EXPAND, 5) self.SetSizer(vsizer) self.Fit()
def __init__(self): wx.Frame.__init__(self, None, -1, 'Apodization Viewer') self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() # open Parameter Dialog win = ParameterFrame(self, -1) win.Show(True) # layout self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) self.SetSizer(self.sizer) self.Fit()
def __init__(self, ontology): LibraryItemFrame.__init__(self, ontology) self.treeCtrl = wx.TreeCtrl(self, wx.ID_ANY) for rootTerm in ontology.rootTerms: rootItem = self.treeCtrl.AddRoot(rootTerm.name) self.treeCtrl.SetPyData(rootItem, rootTerm) if rootTerm.obsolete: self.treeCtrl.SetItemTextColour(rootItem, wx.NamedColor('GRAY')) if len(rootTerm.parts) > 0: self.treeCtrl.SetItemHasChildren(rootItem, True) self.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.onItemExpanding, self.treeCtrl) self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.onBeginDrag, self.treeCtrl) # TODO: display attributes of the selected term sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.treeCtrl, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer)
def __init__(self): wx.Frame.__init__(self,None,-1,'Apodization Viewer') self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.params = ParameterPanel(self) self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() # layout fsizer = wx.BoxSizer(wx.VERTICAL) fsizer.Add(self.canvas,0,wx.EXPAND) fsizer.Add(self.toolbar,0,wx.EXPAND) self.sizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.params,0,wx.EXPAND) self.sizer.Add(fsizer,0,wx.EXPAND) self.SetSizer(self.sizer) self.Fit()
def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, size=(550, 350)) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.change_plot(0) self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.add_buttonbar() self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.add_toolbar() # comment this out for no toolbar menuBar = wx.MenuBar() # File Menu menu = wx.Menu() menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample") menuBar.Append(menu, "&File") if IS_GTK or IS_WIN: # Equation Menu menu = wx.Menu() for i, (mt, func) in enumerate(functions): bm = mathtext_to_wxbitmap(mt) item = wx.MenuItem(menu, 1000 + i, "") item.SetBitmap(bm) menu.AppendItem(item) self.Bind(wx.EVT_MENU, self.OnChangePlot, item) menuBar.Append(menu, "&Functions") self.SetMenuBar(menuBar) self.SetSizer(self.sizer) self.Fit()
def __init__(self, form, *args, **kwargs): wx.PopupWindow.__init__(self, form, *args, **kwargs) self.form = form self.SetBackgroundColour ( wx.NamedColor ( "yellow" ) ) self.SetForegroundColour ( wx.NamedColor ( "red" ) ) self.label = wx.StaticText ( self, label = "***", pos = (10,10) )
def __init__(self, parent, id=-1, pos=(-1, -1), size=(-1, -1)): wx.Panel.__init__(self, parent, id, pos, size) self.count = 0 self.SetBackgroundColour(wx.NamedColor('WHITE')) self.figure = Figure() # --- dd = 10 # --- Plot2 matplotlib.rcParams['timezone'] = 'US/Pacific' tz = timezone('US/Pacific') date1 = datetime.datetime(2000, 3, 2, 10, tzinfo=tz) date2 = datetime.datetime(2000, 3, 2, 15, tzinfo=tz) delta = datetime.timedelta(minutes=5) dates = drange(date1, date2, delta) self.axes1 = self.figure.add_subplot(111) yy = pylab.arrayrange(len(dates) * 1.0) majorTick = HourLocator(range(0, 25, 1), tz=tz) ysq = [y * y / dd for y in yy] line = self.axes1.plot_date(dates, ysq, tz=tz) self.axes1.xaxis.set_major_locator(majorTick) self.axes1.set_xlabel('Time (s)') self.axes1.set_ylabel('Price 2 ($)') # self.canvas = FigureCanvas(self, -1, self.figure) self.canvas.mpl_connect('motion_notify_event', self.mouse_move) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.SetSizer(self.sizer) # --- Add Toolbar self.toolbar = Toolbar(self.canvas) self.toolbar.Realize() # On Windows, default frame size behaviour is incorrect # you don't need this under Linux tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() self.toolbar.SetSize(wx.Size(fw, th)) # Create a figure manager to manage things self.figmgr = FigureManager(self.canvas, 1, self) self.sizer.Add(self.toolbar, 0, wx.EXPAND) self.toolbar.update() self.statusBar = wx.StatusBar(self, -1) self.statusBar.SetFieldsCount(1) self.sizer.Add(self.statusBar, 0, wx.EXPAND) self.Fit() # --- Обработчики событий self.Bind(wx.EVT_PAINT, self.OnPaint)
def __init__(self, files, verbose=False, title='(x,y) data', formt='k', xlabel='X', ylabel='Y', ymin=-0.1, ymax=0.05, xmin=0.0, xmax=1.0, pos=(50, 60), size=(640, 500)): wx.Frame.__init__(self, None, -1, "G3 Plot", pos, size) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.panel = None self.dpi = None self.fig = None self.canvas = None self.axes = None self.toolbar = None # Just in case we need to have these values stored self.verbose = verbose self.title = title self.formt = formt self.xlabel = xlabel self.ylabel = ylabel self.ymin = ymin self.ymax = ymax self.xmin = xmin self.xmax = xmax if self.verbose: print "xmin, xmax, ymin, ymax: ", self.xmin, self.xmax, self.ymin, self.ymax self.subplot = [] # Give the figure size in inches, and rez self.figure = Figure(figsize=(6.4, 4.8), dpi=100) # Wait to create the subplot when AddSubplot() is called # self.axes = self.figure.add_subplot(1,1,1) # self.axes.set_title(self.title) # self.axes.set_xlabel(self.xlabel) # self.axes.set_ylabel(self.ylabel) self.PlotFiles(files) # create axes and plot all the data self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND) # Capture the paint message wx.EVT_PAINT(self, self.OnPaint) self.toolbar = MyNavigationToolbar(self.canvas, True) self.toolbar.Realize() if wx.Platform == '__WXMAC__': # Mac platform (OSX 10.3, MacPython) does not seem to cope with # having a toolbar in a sizer. This work-around gets the buttons # back, but at the expense of having the toolbar at the top self.SetToolBar(self.toolbar) else: # On Windows platform, default window size is incorrect, so set # toolbar width to figure width. tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() # By adding toolbar in sizer, we are able to put it at the bottom # of the frame - so appearance is closer to GTK version. # As noted above, doesn't work for Mac. self.toolbar.SetSize(wx.Size(fw, th)) self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) # update the axes menu on the toolbar self.toolbar.update() self.SetSizer(self.sizer) self.Fit()
def fillMessages(self, forum, objID, type): objMessages = client.get(objID)._messages ids = objMessages.keys() ids.sort() ids.reverse() i = 0 self.itemData = {} self.list.Freeze() self.list.DeleteAllItems() for messageID in ids: message = objMessages[messageID] if message["forum"] == forum: # regenerate topics for messages with data if message.has_key("data") and message["topic"] == "EVENT": sourceID, msgID, locationID, turn, data = message["data"] message["topic"] = messages.getMsgText(msgID, data).split("\n")[0] self.list.InsertStringItem(i, "") self.list.SetStringItem(i, 3, message["topic"]) item = self.list.GetItem(i) itemFont = item.GetFont() if message.has_key("data"): sourceID, msgID, locationID, turn, data = message["data"] color = wx.NamedColor( sevColors[messages.getMsgSeverity(msgID)]) item.SetTextColour(color) if message["readed"]: state = _(" ") else: state = _("N") itemFont.SetWeight(wx.BOLD) else: color = wx.NamedColor(sevColors[gdata.MIN]) item.SetTextColour(color) if message["readed"]: if message["replied"]: state = _("R") else: state = _(" ") itemFont.SetWeight(wx.NORMAL) else: state = _("N") itemFont.SetWeight(wx.BOLD) item.SetFont(itemFont) self.list.SetItem(item) date = time.strftime(_("%m-%d %H:%M"), time.localtime(message["time"])) self.list.SetStringItem(i, 0, state) self.list.SetStringItem(i, 2, message["sender"]) self.list.SetStringItem(i, 1, date) self.itemData[i] = (objID, messageID, forum, type) i += 1 self.list.Thaw() self.delete.Disable() self.reply.Disable() self.newSubject.Enable(gdata.mailboxSpec[type, forum][1] != None) self.readAll.Enable(i > 0) self.deleteAll.Enable(i > 0) self.message.SetValue("")
def paint_cell(self, dc, r, c): if r < 0 or r >= self.app.rows or c < 0 or c >= self.app.cols: return val = self.app.values[r][c] if val is None: fill = 'black' stipple = self.gray12 else: fill = self.app.get_color(val) stipple = None if r == self.row and c == self.col: outline = 'red' elif self.app.changed[r][c]: outline = 'white' else: outline = 'black' dc.SetPen(wx.Pen(outline)) if stipple: brush = wx.Brush(fill, style=wx.STIPPLE) brush.SetStipple(stipple) else: brush = wx.Brush(fill, style=wx.SOLID) x0 = c * self.size + 1 x1 = x0 + self.size - 1 y0 = r * self.size + 1 y1 = y0 + self.size - 1 dc.SetBrush(brush) dc.DrawRectangle(x0, y0, x1 - x0, y1 - y0) dc.SetPen(wx.NullPen) dc.SetBrush(wx.NullBrush) if not self.app.angles: return if self.app.angles[r][c] == '*': return cx = (x0 + x1) / 2 cy = (y0 + y1) / 2 a = math.radians(float(self.app.angles[r][c])) dx = math.cos(a) * self.size / 2 dy = -math.sin(a) * self.size / 2 x0 = cx - dx y0 = cy - dy x1 = cx + dx y1 = cy + dy dx, dy = x1 - x0, y1 - y0 px, py = -dy, dx r, g, b = wx.NamedColor(fill) if r + g + b > 384: line = 'black' else: line = 'white' dc.SetPen(wx.Pen(line)) dc.DrawLine(x0, y0, x1, y1) dc.DrawLine(x1, y1, x1 + px / 6 - dx / 3, y1 + py / 6 - dy / 3) dc.DrawLine(x1, y1, x1 - px / 6 - dx / 3, y1 - py / 6 - dy / 3) dc.SetPen(wx.NullPen)
def on_paint(self, event): event.Skip() background_brush = wx.Brush(self.GetBackgroundColour()) start_brush = wx.Brush(wx.NamedColor('Green')) gold_brush = wx.Brush(wx.NamedColor('Gold')) pit_brush = wx.Brush(wx.NamedColor('Black')) red_brush = wx.Brush(wx.NamedColor('Red')) white_brush = wx.Brush(wx.NamedColor('White')) black_pen = wx.Pen(wx.NamedColor('Black'), width=1.5) red_pen = wx.Pen(wx.NamedColor('Red'), width=3.0) dc = wx.BufferedPaintDC(self) dc.SetBackground(background_brush) dc.Clear() if self.state is None: return gc = wx.GraphicsContext.Create(dc) assert isinstance(gc, wx.GraphicsContext) client_width, client_height = self.GetClientSize() board_size = self.state.board_size def print_board_tile(pos, board_tile): xi, yi = pos x = xi * 50 y = (board_size - 1 - yi) * 50 def print_wumpus(): gc.SetPen(red_pen) gc.SetBrush(red_brush) gc.DrawRectangle(x + 15, y + 15, 20, 20) def print_pit(): gc.SetPen(black_pen) gc.SetBrush(pit_brush) gc.DrawEllipse(x + 5, y + 5, 40, 40) def print_player(direction): def print_dir(): rotation = { 'up': 0, 'right': math.pi / 2, 'down': math.pi, 'left': 3 * math.pi / 2 }[direction] gc.PushState() gc.Translate(x + 25, y + 25) gc.Rotate(rotation) gc.Translate(0, -10) gc.Rotate(math.pi / 4) dir_side = 20 / math.sqrt(2) gc.DrawRectangle(-dir_side / 2, -dir_side / 2, dir_side, dir_side) gc.PopState() gc.SetPen(black_pen) gc.SetBrush(white_brush) print_dir() if self.state.gold_grabbed: gc.SetBrush(gold_brush) else: gc.SetBrush(white_brush) gc.DrawRectangle(x + 15, y + 15, 20, 20) gc.SetPen(black_pen) if pos == (0, 0): gc.SetBrush(start_brush) elif board_tile.gold and not self.state.gold_grabbed: gc.SetBrush(gold_brush) else: gc.SetBrush(background_brush) gc.DrawRectangle(x, y, 50, 50) if board_tile.pit: print_pit() if board_tile.wumpus and not self.state.wumpus_dead: print_wumpus() if self.state.player_pos == pos: print_player(self.state.player_dir) for pos, board_tile in self.state.board.iteritems(): print_board_tile(pos, board_tile) def draw_arrow(): x, y = self.state.player_pos end_x = { 'up': x, 'left': 0, 'down': x, 'right': self.state.board_size - 1 }[self.state.player_dir] end_y = { 'up': self.state.board_size - 1, 'left': y, 'down': 0, 'right': y }[self.state.player_dir] gc.SetPen(red_pen) def draw_line(x1, y1, x2, y2): x = min(x1, x2) y = min(y1, y2) w = max(abs(x1 - x2), 2) h = max(abs(y1 - y2), 2) gc.DrawRectangle(x, y, w, h) draw_line(x * 50 + 25, (board_size - y - 1) * 50 + 25, end_x * 50 + 25, (board_size - end_y - 1) * 50 + 25) if self.state.shooting: draw_arrow() def print_points(): dc.SetFont( wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) dc.DrawLabel(str(self.state.points), wx.Rect(0, (client_height - 40), client_width, 40), wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) def print_sensors(): dc.SetFont( wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) dc.DrawLabel(str(self.state.sensors()), wx.Rect(0, (client_height - 80), client_width, 40), wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) print_sensors() print_points()
def draw(self, dc, size): s_rect = wx.Rect(0, 0, size.width, size.height) elements = list(self.history.upload_data) + list( self.history.download_data) max_data = max(elements + [self.MIN_MAX_DATA]) interval = self.history.interval / 1000 seconds = self.history.max_len * interval time_label_text = "%d" % seconds + _(" seconds, ") time_label_text += str(interval) + _(" second interval") dr_label_text = _("Download rate") ur_label_text = _("Upload rate") text_color = wx.NamedColour("light gray") border_color = wx.NamedColour("gray") dr_color = wx.NamedColor("green") ur_color = wx.NamedColor("slate blue") size = 8 if sys.platform == "darwin": size = 10 dc.SetFont(wx.Font(size, wx.DEFAULT, wx.NORMAL, wx.NORMAL)) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() if (self.max_label_width == None): self.max_label_width = dc.GetTextExtent(unicode( Rate(1000000.0)))[0] self.max_label_width = max( self.max_label_width, dc.GetTextExtent(unicode(Rate(max_data)))[0]) top_label_height = dc.GetTextExtent(unicode(Rate(max_data)))[1] bottom_label_height = dc.GetTextExtent(unicode(Rate(0.0)))[1] time_label_width = dc.GetTextExtent(unicode(time_label_text))[0] time_label_height = dc.GetTextExtent(unicode(time_label_text))[1] dr_label_width = dc.GetTextExtent(unicode(dr_label_text))[0] dr_label_height = dc.GetTextExtent(unicode(dr_label_text))[1] ur_label_width = dc.GetTextExtent(unicode(ur_label_text))[0] ur_label_height = dc.GetTextExtent(unicode(ur_label_text))[1] label_spacer = 4 b_spacer = 15 legend_box_size = 10 legend_guts_height = max( (legend_box_size, ur_label_height, dr_label_height)) legend_height = legend_guts_height + b_spacer x1 = b_spacer y1 = b_spacer x2 = max( x1, s_rect.GetRight() - (label_spacer + self.max_label_width + label_spacer)) y2 = max( y1 + top_label_height + SPACING + bottom_label_height, s_rect.GetBottom() - (label_spacer + time_label_height + label_spacer + legend_height)) b_rect = wx.RectPP(wx.Point(x1, y1), wx.Point(x2, y2)) x1 = b_spacer + b_spacer y1 = max((b_rect.GetBottom() + label_spacer + time_label_height + label_spacer), s_rect.GetBottom() - (legend_box_size + b_spacer)) x2 = x1 + legend_box_size y2 = y1 + legend_box_size db_rect = wx.RectPP(wx.Point(x1, y1), wx.Point(x2, y2)) x1 = db_rect.GetRight() + label_spacer + dr_label_width + b_spacer y1 = db_rect.y x2 = x1 + legend_box_size y2 = y1 + legend_box_size ub_rect = wx.RectPP(wx.Point(x1, y1), wx.Point(x2, y2)) x1 = min(b_rect.x + 1, b_rect.GetRight()) y1 = min(b_rect.y + 1, b_rect.GetBottom()) x2 = max(x1, b_rect.GetRight() - 1) y2 = max(y1, b_rect.GetBottom() - 1) i_rect = wx.RectPP(wx.Point(x1, y1), wx.Point(x2, y2)) bw_label_x = b_rect.GetRight() + label_spacer time_label_x = max(b_rect.x, (b_rect.GetRight() / 2) - (time_label_width / 2)) dc.SetTextForeground(text_color) dc.DrawText(unicode(Rate(max_data)), bw_label_x, b_rect.y) dc.DrawText(unicode(Rate(0.0)), bw_label_x, b_rect.GetBottom() - bottom_label_height) dc.DrawText(unicode(time_label_text), time_label_x, b_rect.GetBottom() + label_spacer) dc.DrawText(unicode(dr_label_text), db_rect.GetRight() + label_spacer, db_rect.y + (legend_box_size / 2) - (dr_label_height / 2)) dc.DrawText(unicode(ur_label_text), ub_rect.GetRight() + label_spacer, ub_rect.y + (legend_box_size / 2) - (ur_label_height / 2)) pen = wx.Pen(border_color, 1, wx.SOLID) dc.SetPen(pen) brush = wx.Brush(dr_color) dc.SetBrush(brush) dc.DrawRectangle(db_rect.x, db_rect.y, db_rect.GetWidth(), db_rect.GetHeight()) brush = wx.Brush(ur_color) dc.SetBrush(brush) dc.DrawRectangle(ub_rect.x, ub_rect.y, ub_rect.GetWidth(), ub_rect.GetHeight()) dc.DrawLine(b_rect.x, b_rect.y, b_rect.GetRight(), b_rect.y) dc.DrawLine(b_rect.x, b_rect.y, b_rect.x, b_rect.GetBottom()) dc.DrawLine(b_rect.x, b_rect.GetBottom(), b_rect.GetRight(), b_rect.GetBottom()) dc.DrawLine(b_rect.GetRight(), b_rect.y, b_rect.GetRight(), b_rect.GetBottom()) pen = wx.Pen(border_color, 1, wx.DOT) dc.SetPen(pen) dc.DrawLine(i_rect.x, i_rect.y + (i_rect.height * 0.75), i_rect.GetRight(), i_rect.y + (i_rect.height * 0.75)) dc.DrawLine(i_rect.x, i_rect.y + (i_rect.height * 0.5), i_rect.GetRight(), i_rect.y + (i_rect.height * 0.5)) dc.DrawLine(i_rect.x, i_rect.y + (i_rect.height * 0.25), i_rect.GetRight(), i_rect.y + (i_rect.height * 0.25)) pen = wx.Pen(ur_color, 1, wx.SHORT_DASH) dc.SetPen(pen) self.draw_max_line(dc, self.history.max_upload_rate, max_data, i_rect, offset=3) pen = wx.Pen(ur_color, 1, wx.SOLID) dc.SetPen(pen) self.draw_graph(dc, self.history.max_len, self.history.upload_data, max_data, i_rect) pen = wx.Pen(dr_color, 1, wx.SHORT_DASH) dc.SetPen(pen) self.draw_max_line(dc, self.history.max_download_rate, max_data, i_rect) pen = wx.Pen(dr_color, 1, wx.SOLID) dc.SetPen(pen) self.draw_graph(dc, self.history.max_len, self.history.download_data, max_data, i_rect) ## variance line if wx.the_app.config['show_variance_line']: pen = wx.Pen(wx.NamedColor("yellow"), 1, wx.SHORT_DASH) dc.SetPen(pen) self.draw_max_line(dc, self.history.variance, self.history.max_variance, i_rect)