Пример #1
0
class MyGraph(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, 'It Looks Like a Line Graph!')

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)

        # create some sizers
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        checkSizer = wx.BoxSizer(wx.HORIZONTAL)

        # create the widgets
        self.canvas = PlotCanvas(panel)
        self.canvas.Draw(drawLinePlot())
        toggleGrid = wx.CheckBox(panel, label="Show Grid")
        toggleGrid.Bind(wx.EVT_CHECKBOX, self.onToggleGrid)
        toggleLegend = wx.CheckBox(panel, label="Show Legend")
        toggleLegend.Bind(wx.EVT_CHECKBOX, self.onToggleLegend)

        # layout the widgets
        mainSizer.Add(self.canvas, 1, wx.EXPAND)
        checkSizer.Add(toggleGrid, 0, wx.ALL, 5)
        checkSizer.Add(toggleLegend, 0, wx.ALL, 5)
        mainSizer.Add(checkSizer)
        panel.SetSizer(mainSizer)

    def onToggleGrid(self, event):
        """"""
        self.canvas.SetEnableGrid(event.IsChecked())

    def onToggleLegend(self, event):
        """"""
        self.canvas.SetEnableLegend(event.IsChecked())
Пример #2
0
    def drawBarGraph():
        self.canvas = PlotCanvas(panel)
        self.canvas.Draw(drawBarGraph())
        toggleGrid = wx.CheckBox(panel, label="Show Grid")
        toggleGrid.Bind(wx.EVT_CHECKBOX, self.onToggleGrid)
        toggleLegend = wx.CheckBox(panel, label="Show Legend")
        toggleLegend.Bind(wx.EVT_CHECKBOX, self.onToggleLegend)

        points1 = [(1, 0), (1, 10)]
        line1 = PolyLine(points1, colour='green', legend='Feb.', width=10)
        points1g = [(2, 0), (2, 4)]
        line1g = PolyLine(points1g, colour='red', legend='Mar.', width=10)
        points1b = [(3, 0), (3, 100)]
        line1b = PolyLine(points1b, colour='blue', legend='Apr.', width=10)

        points2 = [(4, 0), (4, 12)]
        line2 = PolyLine(points2, colour='Yellow', legend='May', width=10)
        points2g = [(5, 0), (5, 8)]
        line2g = PolyLine(points2g, colour='orange', legend='June', width=10)
        points2b = [(6, 0), (6, 4)]
        line2b = PolyLine(points2b, colour='brown', legend='July', width=10)

        return PlotGraphics([line1, line1g, line1b, line2, line2g, line2b],
                            "Bar Graph - (Turn on Grid, Legend)", "Months",
                            "Number of Students")
Пример #3
0
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY,
                          'My First Plot (to take over the world!)')

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)

        # create some sizers
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        checkSizer = wx.BoxSizer(wx.HORIZONTAL)

        # create the widgets
        self.canvas = PlotCanvas(panel)
        self.canvas.Draw(drawBarGraph())
        toggleGrid = wx.CheckBox(panel, label="Show Grid")
        toggleGrid.Bind(wx.EVT_CHECKBOX, self.onToggleGrid)
        toggleLegend = wx.CheckBox(panel, label="Show Legend")
        toggleLegend.Bind(wx.EVT_CHECKBOX, self.onToggleLegend)

        # layout the widgets
        mainSizer.Add(self.canvas, 1, wx.EXPAND)
        checkSizer.Add(toggleGrid, 0, wx.ALL, 5)
        checkSizer.Add(toggleLegend, 0, wx.ALL, 5)
        mainSizer.Add(checkSizer)
        panel.SetSizer(mainSizer)
Пример #4
0
    def __init__(self, parent, title):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          title,
                          pos=(150, 150),
                          size=(550, 400))

        # Create the menubar
        menuBar = wx.MenuBar()

        # and a menu
        menu = wx.Menu()

        # add an item to the menu, using \tKeyName automatically
        # creates an accelerator, the third param is some help text
        # that will show up in the statusbar
        menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")

        # bind the menu event to an event handler
        self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)

        # and put the menu on the menubar
        menuBar.Append(menu, "&File")
        self.SetMenuBar(menuBar)

        self.CreateStatusBar()

        # Now create the Panel to put the other controls on.
        #panel = wx.Panel(self)
        self.plot = PlotCanvas(self)
        self.fill_Plot()
Пример #5
0
 def __init__(self):
     wx.Frame.__init__(self, None, -1, 'DataWxProcess', size=(400, 300))
     self.panel = wx.Panel(self, -1)
     #self.childPlotPanel = wx.Panel(self.panel,-1,size = (200,150))
     self.modelButton1 = wx.Button(self.panel,
                                   -1,
                                   size=(50, 30),
                                   label='Model1')
     self.modelButton2 = wx.Button(self.panel,
                                   -1,
                                   size=(50, 30),
                                   label='Model2')
     self.modelButton3 = wx.Button(self.panel,
                                   -1,
                                   size=(50, 30),
                                   label='Model3')
     self.modelButton4 = wx.Button(self.panel,
                                   -1,
                                   size=(50, 30),
                                   label='Model4')
     self.modelButton1.Bind(wx.EVT_BUTTON, self.OnButtonClick_Model1)
     self.modelButton2.Bind(wx.EVT_BUTTON, self.OnButtonClick_Model2)
     self.modelButton3.Bind(wx.EVT_BUTTON, self.OnButtonClick_Model3)
     self.modelButton4.Bind(wx.EVT_BUTTON, self.OnButtonClick_Model4)
     #self.canvas = PlotCanvas(self.childPlotPanel,id = -1,size = (200,150))
     self.canvas = PlotCanvas(self.panel, id=-1, size=(200, 150))
     self.canvas.Draw(self.DrawBarGraph())
     hbox = wx.BoxSizer()
     #hbox.Add(self.childPlotPanel,proportion = 1,flag = wx.EXPAND)
     hbox.Add(self.modelButton1, proportion=0)
     hbox.Add(self.modelButton2, proportion=0)
     hbox.Add(self.modelButton3, proportion=0)
     hbox.Add(self.modelButton4, proportion=0)
     #		hbox.Add(self.canvas,proportion = 2,flag = wx.EXPAND)
     self.panel.SetSizer(hbox)
Пример #6
0
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, 'Plotting File Data')

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
        self.canvas = PlotCanvas(panel)
        self.canvas.Draw(self.createPlotGraphics())

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        panel.SetSizer(sizer)
Пример #7
0
 def __init__(self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.DefaultSize, style = 0):
     PlotCanvas.__init__(self, parent, id, pos, size, style)
     self.lines = PolySpline([], legend= 'Red Line', colour='red')
     self.xAxis = (0, 30)         
     self.yAxis = (-5, 5)
     self.clr = 'black'
     self.SetEnableGrid(True)
     self.SetGridColour("red")
     self.SetXSpec(5)
     self.SetShowScrollbars(True)
     self.SetMinSize((200,200))
     self.sr = 250
Пример #8
0
class piramida_penduduk(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self,
                          id=wxID_PIRAMIDA_PENDUDUK,
                          name=u'piramida_penduduk',
                          parent=prnt,
                          pos=wx.Point(341, 167),
                          size=wx.Size(911, 445),
                          style=wx.DEFAULT_FRAME_STYLE,
                          title=u'Perbandingan Penduduk')
        self.SetClientSize(wx.Size(911, 445))

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.drawBarGraph()

    def drawBarGraph():
        self.canvas = PlotCanvas(panel)
        self.canvas.Draw(drawBarGraph())
        toggleGrid = wx.CheckBox(panel, label="Show Grid")
        toggleGrid.Bind(wx.EVT_CHECKBOX, self.onToggleGrid)
        toggleLegend = wx.CheckBox(panel, label="Show Legend")
        toggleLegend.Bind(wx.EVT_CHECKBOX, self.onToggleLegend)

        points1 = [(1, 0), (1, 10)]
        line1 = PolyLine(points1, colour='green', legend='Feb.', width=10)
        points1g = [(2, 0), (2, 4)]
        line1g = PolyLine(points1g, colour='red', legend='Mar.', width=10)
        points1b = [(3, 0), (3, 100)]
        line1b = PolyLine(points1b, colour='blue', legend='Apr.', width=10)

        points2 = [(4, 0), (4, 12)]
        line2 = PolyLine(points2, colour='Yellow', legend='May', width=10)
        points2g = [(5, 0), (5, 8)]
        line2g = PolyLine(points2g, colour='orange', legend='June', width=10)
        points2b = [(6, 0), (6, 4)]
        line2b = PolyLine(points2b, colour='brown', legend='July', width=10)

        return PlotGraphics([line1, line1g, line1b, line2, line2g, line2b],
                            "Bar Graph - (Turn on Grid, Legend)", "Months",
                            "Number of Students")

    def onToggleGrid(self, event):
        """"""
        self.canvas.SetEnableGrid(event.IsChecked())

    #----------------------------------------------------------------------
    def onToggleLegend(self, event):
        """"""
        self.canvas.SetEnableLegend(event.IsChecked())
Пример #9
0
 def __do_layout(self):
     
     self.__panel.SetBackgroundColour("Gray")
     
     self.__main_sizer  = wx.BoxSizer(wx.VERTICAL)
     self.__check_sizer = wx.BoxSizer(wx.HORIZONTAL)
     
     self.__canvas = PlotCanvas(self.__panel)  
     
     self.__check_sizer.Add(self.__toggle_grid, 0, wx.ALL, 5)
     self.__main_sizer.Add(self.__canvas, 1, wx.EXPAND)
     self.__main_sizer.Add(self.__check_sizer)
     self.__panel.SetSizer(self.__main_sizer)
     self.__panel.SetAutoLayout(True)
     
     self.plot()
Пример #10
0
    def _init_ui(self):
        """Builds GUI.
        """

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.best_canvas = PlotCanvas(self)
        self.best_canvas.useScientificNotation = True
        self.current_canvas = PlotCanvas(self)
        self.current_canvas.useScientificNotation = True
        sizer.Add(self.best_canvas, 1, wx.EXPAND)
        sizer.Add(self.current_canvas, 1, wx.EXPAND)
        self._plot()

        self.SetSizer(sizer)

        pub.subscribe(self._on_solver_state_end, 'SOLVER_STATE_END')
        pub.subscribe(self._on_solver_state_reset, 'SOLVER_STATE_RESET')
Пример #11
0
 def __init__(self, grafica):
     wx.Frame.__init__(self, None, wx.ID_ANY, 'Grafica de resultados')
     panel = wx.Panel(self, wx.ID_ANY)
     mainSizer = wx.BoxSizer(wx.VERTICAL)
     checkSizer = wx.BoxSizer(wx.HORIZONTAL)
     self.canvas = PlotCanvas(panel)
     self.canvas.SetShowScrollbars(True)
     self.canvas.SetEnableZoom(True)
     self.canvas.Draw(grafica)
     toggleGrid = wx.CheckBox(panel, label="Ver cuadricula")
     toggleGrid.Bind(wx.EVT_CHECKBOX, self.onToggleGrid)
     toggleLegend = wx.CheckBox(panel, label="Ver leyenda")
     toggleLegend.Bind(wx.EVT_CHECKBOX, self.onToggleLegend)
     mainSizer.Add(self.canvas, 1, wx.EXPAND)
     checkSizer.Add(toggleGrid, 0, wx.ALL, 5)
     checkSizer.Add(toggleLegend, 0, wx.ALL, 5)
     mainSizer.Add(checkSizer)
     panel.SetSizer(mainSizer)
Пример #12
0
class DataWxProcess(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'DataWxProcess', size=(400, 300))
        self.panel = wx.Panel(self, -1)
        #self.childPlotPanel = wx.Panel(self.panel,-1,size = (200,150))
        self.modelButton1 = wx.Button(self.panel,
                                      -1,
                                      size=(50, 30),
                                      label='Model1')
        self.modelButton2 = wx.Button(self.panel,
                                      -1,
                                      size=(50, 30),
                                      label='Model2')
        self.modelButton3 = wx.Button(self.panel,
                                      -1,
                                      size=(50, 30),
                                      label='Model3')
        self.modelButton4 = wx.Button(self.panel,
                                      -1,
                                      size=(50, 30),
                                      label='Model4')
        self.modelButton1.Bind(wx.EVT_BUTTON, self.OnButtonClick_Model1)
        self.modelButton2.Bind(wx.EVT_BUTTON, self.OnButtonClick_Model2)
        self.modelButton3.Bind(wx.EVT_BUTTON, self.OnButtonClick_Model3)
        self.modelButton4.Bind(wx.EVT_BUTTON, self.OnButtonClick_Model4)
        #self.canvas = PlotCanvas(self.childPlotPanel,id = -1,size = (200,150))
        self.canvas = PlotCanvas(self.panel, id=-1, size=(200, 150))
        self.canvas.Draw(self.DrawBarGraph())
        hbox = wx.BoxSizer()
        #hbox.Add(self.childPlotPanel,proportion = 1,flag = wx.EXPAND)
        hbox.Add(self.modelButton1, proportion=0)
        hbox.Add(self.modelButton2, proportion=0)
        hbox.Add(self.modelButton3, proportion=0)
        hbox.Add(self.modelButton4, proportion=0)
        #		hbox.Add(self.canvas,proportion = 2,flag = wx.EXPAND)
        self.panel.SetSizer(hbox)

    def OnButtonClick_Model1(self, event):
        pass

    def OnButtonClick_Model2(self, event):
        pass

    def OnButtonClick_Model3(self, event):
        pass

    def OnButtonClick_Model4(self, event):
        pass

    def DrawBarGraph(self):
        points = [(1, 0), (1, 200)]
        line1 = PolyLine(points, colour='green', legend='Feb', width=100)
        return PlotGraphics([line1], "Bar Graph - test", "Months",
                            "Number of Students")
Пример #13
0
 def _xticks(self, *args):
     ticks = PlotCanvas._xticks(self, *args)
     customTicks = []
     #the rule is last num div Xspec instead the total num, so we add one, when  moding the tick.
     for tick in ticks:
         if  (int(tick[0])%self.sr) == 0:
             customTicks.append((tick[0],str(int(tick[0])/self.sr)))
         else:
             customTicks.append((tick[0],''))
             
     return customTicks
Пример #14
0
class plot(wx.Frame):
 
    #----------------------------------------------------------------------
    def __init__(self, grafica):
        wx.Frame.__init__(self, None, wx.ID_ANY, 'Grafica de resultados')
        panel = wx.Panel(self, wx.ID_ANY)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        checkSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.canvas = PlotCanvas(panel)
        self.canvas.SetShowScrollbars(True)
        self.canvas.SetEnableZoom(True)
        self.canvas.Draw(grafica)
        toggleGrid = wx.CheckBox(panel, label="Ver cuadricula")
        toggleGrid.Bind(wx.EVT_CHECKBOX, self.onToggleGrid)
        toggleLegend = wx.CheckBox(panel, label="Ver leyenda")
        toggleLegend.Bind(wx.EVT_CHECKBOX, self.onToggleLegend)
        mainSizer.Add(self.canvas, 1, wx.EXPAND)
        checkSizer.Add(toggleGrid, 0, wx.ALL, 5)
        checkSizer.Add(toggleLegend, 0, wx.ALL, 5)
        mainSizer.Add(checkSizer)
        panel.SetSizer(mainSizer)
    def onToggleGrid(self, event):
        self.canvas.Reset()
        self.canvas.SetEnableGrid(event.IsChecked())
    
    def onToggleLegend(self, event):
        self.canvas.SetEnableLegend(event.IsChecked())
    def dibujar(self):
        app = wx.App(False)
 
        self.Show()
        app.MainLoop()
Пример #15
0
	def __init__(self, parent):
		wx.Panel.__init__(self, parent)
		self.ancestor = parent
		self.fontpointsize=wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).GetPointSize()
		self.colour = wx.Colour(30,70,115, alpha=wx.ALPHA_OPAQUE)
		self.canvas = PlotCanvas(self)
		if IsNotWX4():
			self.canvas.SetInitialSize(size=self.GetClientSize())
			self.canvas.SetShowScrollbars(True)
			self.canvas.SetEnableZoom(False)
			self.canvas.SetFontSizeAxis(point=12)
			self.canvas.SetFontSizeTitle(point=12)
			self.canvas.SetGridColour(wx.Colour(0, 0, 0))
			self.canvas.SetForegroundColour(wx.Colour(0, 0, 0))
			self.canvas.SetBackgroundColour(wx.Colour(255, 255, 255))
		else:
			self.canvas.axesPen = wx.Pen(self.colour, width=1, style=wx.PENSTYLE_SOLID)
			self.canvas.SetForegroundColour(wx.Colour(0, 0, 0))
			self.canvas.SetBackgroundColour(wx.Colour(255, 255, 255))
			self.canvas.enableGrid = (True,True)
			self.canvas.fontSizeAxis = self.fontpointsize
			self.canvas.fontSizeTitle = self.fontpointsize
		self.vbox = wx.BoxSizer(wx.VERTICAL)
		self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW)
		self.paused = False
		self.hbox_btn = wx.BoxSizer(wx.HORIZONTAL)
		self.hbox_btn.AddSpacer(20)
		self.button_pause =wx.Button(self, label="Pause Graph")
		self.Bind(wx.EVT_BUTTON, self.OnClickPauseButton, self.button_pause)
		self.hbox_btn.Add(self.button_pause)
		self.button_save =wx.Button(self, label="Save Data")
		self.Bind(wx.EVT_BUTTON, self.OnClickSaveButton, self.button_save)
		self.hbox_btn.Add(self.button_save)
		self.vbox.Add(self.hbox_btn, 0, wx.EXPAND)
		self.SetSizer(self.vbox)
		self.Fit()
		self.Show()
		self.data_poll_timer = wx.Timer(self)
		self.Bind(wx.EVT_TIMER, self.UpdateGraph, self.data_poll_timer)
Пример #16
0
class MyGraph(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, 'Plotting File Data')

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
        self.canvas = PlotCanvas(panel)
        self.canvas.Draw(self.createPlotGraphics())

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        panel.SetSizer(sizer)

    def readFile(self):
        """
        Reads the hard-coded file
        """
        # normally you would want to pass a file path in, NOT hard code it!
        with open("data.txt") as fobj:
            # skip the first two lines of text in the file
            data = fobj.readlines()[2:-1]

        temps = []
        for line in data:
            parts = line.split(",")
            date = parts[0].split("-")
            day = date[2]
            points = [(day, parts[3]), (day, parts[1])]
            temps.append(points)
        return temps

    def createPlotGraphics(self):
        """
        Create the plot's graphics
        """
        temps = self.readFile()
        lines = []
        for temp in temps:
            tempInt = int(temp[1][1])
            if tempInt < 60:
                color = "blue"
            elif tempInt >= 60 and tempInt <= 75:
                color = "orange"
            else:
                color = "red"
            lines.append(PolyLine(temp, colour=color, width=10))

        return PlotGraphics(lines, "Bar Graph of Temperatures", "Days",
                            "Temperatures")
Пример #17
0
class PanelGraph(wx.Panel):
	def __init__(self, parent):
		wx.Panel.__init__(self, parent)
		self.ancestor = parent
		self.fontpointsize=wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).GetPointSize()
		self.colour = wx.Colour(30,70,115, alpha=wx.ALPHA_OPAQUE)
		self.canvas = PlotCanvas(self)
		if IsNotWX4():
			self.canvas.SetInitialSize(size=self.GetClientSize())
			self.canvas.SetShowScrollbars(True)
			self.canvas.SetEnableZoom(False)
			self.canvas.SetFontSizeAxis(point=12)
			self.canvas.SetFontSizeTitle(point=12)
			self.canvas.SetGridColour(wx.Colour(0, 0, 0))
			self.canvas.SetForegroundColour(wx.Colour(0, 0, 0))
			self.canvas.SetBackgroundColour(wx.Colour(255, 255, 255))
		else:
			self.canvas.axesPen = wx.Pen(self.colour, width=1, style=wx.PENSTYLE_SOLID)
			self.canvas.SetForegroundColour(wx.Colour(0, 0, 0))
			self.canvas.SetBackgroundColour(wx.Colour(255, 255, 255))
			self.canvas.enableGrid = (True,True)
			self.canvas.fontSizeAxis = self.fontpointsize
			self.canvas.fontSizeTitle = self.fontpointsize
		self.vbox = wx.BoxSizer(wx.VERTICAL)
		self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW)
		self.paused = False
		self.hbox_btn = wx.BoxSizer(wx.HORIZONTAL)
		self.hbox_btn.AddSpacer(20)
		self.button_pause =wx.Button(self, label="Pause Graph")
		self.Bind(wx.EVT_BUTTON, self.OnClickPauseButton, self.button_pause)
		self.hbox_btn.Add(self.button_pause)
		self.button_save =wx.Button(self, label="Save Data")
		self.Bind(wx.EVT_BUTTON, self.OnClickSaveButton, self.button_save)
		self.hbox_btn.Add(self.button_save)
		self.vbox.Add(self.hbox_btn, 0, wx.EXPAND)
		self.SetSizer(self.vbox)
		self.Fit()
		self.Show()
		self.data_poll_timer = wx.Timer(self)
		self.Bind(wx.EVT_TIMER, self.UpdateGraph, self.data_poll_timer)
	def OnClickPauseButton(self, event):
		self.paused = not self.paused
		label = "Resume" if self.paused else "Pause Graph"
		if self.paused == True:
			if IsNotWX4():
				self.canvas.SetEnableZoom(True)
			else:
				self.canvas.enableZoom = True
		else:
			if IsNotWX4():
				self.canvas.SetEnableZoom(False)
			else:
				self.canvas.enableZoom = False
		self.button_pause.SetLabel(label)
	def OnClickSaveButton(self, event):
		data_length = self.ancestor.GetPage(0).citer_flow[0]
		if data_length > 0:
			self.ancestor.GetPage(0).OnClickPause(self.ancestor.GetPage(0))
			x = numpy.arange(data_length)
			y = self.ancestor.GetPage(0).residual[:data_length]
			xy = numpy.vstack((x,y)).T
			datestr = strftime("%Y-%m-%d_%H.%M.%S")
			numpy.savetxt('Residual_'+datestr+'.csv', xy, delimiter=',')
			self.ancestor.GetPage(0).OnClickPause(self.ancestor.GetPage(0))
	def UpdateGraph(self,event):
		if self.ancestor.GetPage(0).citer_flow[1] == 2:
			self.data_poll_timer.Stop()
			return
		if self.ancestor.GetPage(0).pipeline_started == True and self.paused != True:
			try:
				data_length = self.ancestor.GetPage(0).citer_flow[0]
				x = numpy.arange(data_length)
				y = self.ancestor.GetPage(0).residual[:data_length]
				data = numpy.vstack((x,y)).T
				line = PolyLine(data, colour=self.colour, width=2.5)
				graphic = PlotGraphics([line],"Error Residual", " Iteration", "Residual")
				self.canvas.Draw(graphic, xAxis=(0, data_length), yAxis=(0.0, 1.2))
			except:
				pass
Пример #18
0
class Plot(wx.Frame):
    
    def __init__(self, parent, regname):
        wx.Frame.__init__(self, parent, wx.ID_ANY, regname, size=(400, 300))
        
        # Attributes
        self.__panel = wx.Panel(self, wx.ID_ANY)        
        self.__id = regname
        self.__data = []
        self.__first_time_point = -1
        
        # Layout attributes
        self.__toggle_grid   = wx.CheckBox(self.__panel, label="Show Grid")
        self.__main_sizer = None
        self.__check_sizer = None
        self.__canvas = None
        
        # Layout
        self.__do_layout()
        
        # Handlers
        self.Bind(wx.EVT_CHECKBOX, self.__on_toggle_grid, self.__toggle_grid)
       
    
    def __do_layout(self):
        
        self.__panel.SetBackgroundColour("Gray")
        
        self.__main_sizer  = wx.BoxSizer(wx.VERTICAL)
        self.__check_sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        self.__canvas = PlotCanvas(self.__panel)  
        
        self.__check_sizer.Add(self.__toggle_grid, 0, wx.ALL, 5)
        self.__main_sizer.Add(self.__canvas, 1, wx.EXPAND)
        self.__main_sizer.Add(self.__check_sizer)
        self.__panel.SetSizer(self.__main_sizer)
        self.__panel.SetAutoLayout(True)
        
        self.plot()
        
    
    def add_pair(self, y):
        
        x = int(time.time())
        if not self.__data:
            self.__first_time_point = x
                            
        # Restrict number of maximum plotted points to 100
        if len(self.__data) >= 100:
        	new_data = self.__data[2:]
        	self.__data = new_data
        	
        time_elapsed = x - self.__first_time_point   
        
        if self.__data:
            previous_y = self.__data[-1][1]
            print "previous y is %s" % previous_y            
            self.__data.append((time_elapsed, previous_y))         
        
        self.__data.append((time_elapsed, y))
              
        
    def plot(self):
        print "DEBUG: plotting with data", str(self.__data)
        self.__canvas.Draw(self.__draw_reg_plot())
    
    
    def __draw_reg_plot(self):
        
        plot_title = "REGISTER %s" % self.__id
        
        if not self.__data:
            plot_title = "NO DATA YET"
            
        x_axis_title = "Time (seconds since first sample)"
        y_axis_title = self.__id
              
        line1 = PolyLine(self.__data, colour='blue', width=3)       
                
        return PlotGraphics([line1],
                        plot_title, 
                        x_axis_title, 
                        y_axis_title)
    
    
    def __on_toggle_grid(self, event):
        self.__canvas.SetEnableGrid(event.IsChecked())
Пример #19
0
    def __init__(self, parent, title):
        super(Psat_finder, self).__init__(parent, title=title, size=(800, 700))
        self.ButtonPanel = wx.Panel(self)

        #Main window

        self.windowSizer = wx.BoxSizer(wx.VERTICAL)

        self.windowSizer.Add(self.ButtonPanel, 1, wx.EXPAND | wx.ALL, 1)

        # Input boxes

        self.ac_val = wx.StaticText(self.ButtonPanel, label="ac = ")

        self.b_val = wx.StaticText(self.ButtonPanel, label="b = ")

        self.m_val = wx.StaticText(self.ButtonPanel, label="m = ")

        self.P_sat = wx.StaticText(self.ButtonPanel, label="Psat = ")

        self.T_unit = wx.StaticText(self.ButtonPanel, label="Kelvin ")

        self.P_unit = wx.StaticText(self.ButtonPanel, label="Bar")

        self.Tc_input_label = wx.StaticText(self.ButtonPanel, label="Tc")
        self.Tc_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.Pc_input_label = wx.StaticText(self.ButtonPanel, label="Pc")
        self.Pc_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.m_input_label = wx.StaticText(self.ButtonPanel, label="m")
        self.m_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.T_slider = wx.Slider(self.ButtonPanel, -1, 273, 0, 1500,
                                  wx.DefaultPosition, (250, -1))
        self.T_slider_label = wx.StaticText(
            self.ButtonPanel, label="Isotherm Temperature = 273 K")

        self.Button_calc_and_plot = wx.Button(
            self.ButtonPanel, label='Calculate Parameters and Plot')

        self.PlotPanel = wx.Panel(self.ButtonPanel)

        self.canvas = PlotCanvas(self.PlotPanel)

        self.PlotPanelSizer = wx.BoxSizer()

        self.panelsizer = wx.GridBagSizer(9, 3)

        self.panelsizer.Add(self.Tc_input_label, (0, 0))
        self.panelsizer.Add(self.Tc_input, (1, 0))

        self.panelsizer.Add(self.Pc_input_label, (2, 0))
        self.panelsizer.Add(self.Pc_input, (3, 0))

        self.panelsizer.Add(self.m_input_label, (4, 0))
        self.panelsizer.Add(self.m_input, (5, 0))

        self.panelsizer.Add(self.ac_val, (0, 2))
        self.panelsizer.Add(self.T_unit, (1, 1))
        self.panelsizer.Add(self.b_val, (1, 2))
        self.panelsizer.Add(self.P_unit, (3, 1))
        self.panelsizer.Add(self.m_val, (2, 2))
        self.panelsizer.Add(self.P_sat, (4, 2))

        self.panelsizer.Add(self.Button_calc_and_plot, (5, 1))

        self.panelsizer.Add(self.T_slider_label, (6, 0), (1, 2), wx.EXPAND)
        self.panelsizer.Add(self.T_slider, (7, 0), (1, 3), wx.EXPAND)

        self.PlotPanelSizer.Add(self.canvas, 1, wx.EXPAND)

        self.panelsizer.Add(self.PlotPanel, (9, 0), (1, 3), wx.EXPAND)

        self.panelsizer.AddGrowableCol(2)
        self.panelsizer.AddGrowableRow(9)

        #initialize sizers
        self.PlotPanel.SetSizerAndFit(self.PlotPanelSizer)

        self.ButtonPanel.SetSizerAndFit(self.panelsizer)

        self.SetSizer(self.windowSizer)

        #Bind Events

        self.Button_calc_and_plot.Bind(wx.EVT_BUTTON, self.calculate_and_plot)
        self.T_slider.Bind(wx.EVT_SLIDER, self.calculate_and_plot)

        #Initialise Window
        self.Centre()
        self.Show()
Пример #20
0
class MyFrame(wx.Frame):
    """
    This is MyFrame.  It just shows a few controls on a wxPanel,
    and has a simple menu.
    """
    def __init__(self, parent, title):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          title,
                          pos=(150, 150),
                          size=(550, 400))

        # Create the menubar
        menuBar = wx.MenuBar()

        # and a menu
        menu = wx.Menu()

        # add an item to the menu, using \tKeyName automatically
        # creates an accelerator, the third param is some help text
        # that will show up in the statusbar
        menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")

        # bind the menu event to an event handler
        self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)

        # and put the menu on the menubar
        menuBar.Append(menu, "&File")
        self.SetMenuBar(menuBar)

        self.CreateStatusBar()

        # Now create the Panel to put the other controls on.
        #panel = wx.Panel(self)
        self.plot = PlotCanvas(self)
        self.fill_Plot()

    def OnTimeToClose(self, evt):
        """Event handler for the button click."""
        print "See ya later!"
        self.Close()

    def OnFunButton(self, evt):
        """Event handler for the button click."""
        print "Having fun yet?"

    def fill_Plot(self):

        # server = ServerProxy("http://localhost:8000") # local server "http://betty.userland.com"
        host = 'baco.cfn.ist.utl.pt'
        port = 8888
        client = SDASClient(host, port)
        #dS=client.getData('CENTRAL_OS9_ADC.IIGBT','0x0000', 11244)
        dS = client.getData('CENTRAL_OS9_ADC_VME_I8.IF0SN', '0x0000', 11244)
        isine = dS.getData()
        dS = client.getData('CENTRAL_OS9_ADC_VME_I8.IF0CS', '0x0000', 11244)
        cosine = dS.getData()
        ic = Density(cosine, isine)
        sze = ic.size()
        print sze
        #ic=_Numeric.arange(ic)
        # 25,000 point line
        data1 = _Numeric.arange(2 * sze)
        data2 = data1.astype(_Numeric.Float32)
        data2.shape = (-1, 2)
        data2[:, 1] = ic
        line1 = PolyLine(data2, legend='Wide Line', colour='green', width=2)
        self.plot.Draw(PlotGraphics([line1], "SDAS Plot", "Time", ""))
Пример #21
0
class MainFrame(wx.Frame):
    def __init__(self, engine, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.Centre()
        self.Engine = engine
        self.SelectedFromDeck = ''
        self.SelectedFromSide = False
        self.SortDeckBy = 'Name'
        self.Plotting = 'Level'

        #Variables
        self.panel = wx.Panel(self)
        self.vbox1 = wx.BoxSizer(wx.VERTICAL)
        self.vbox2 = wx.BoxSizer(wx.VERTICAL)
        self.vbox5 = wx.BoxSizer(wx.VERTICAL)
        self.hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.graphbox = wx.BoxSizer(wx.HORIZONTAL)
        self.hmbox1 = wx.BoxSizer(wx.HORIZONTAL)
        self.hmbox2 = wx.BoxSizer(wx.HORIZONTAL)
        self.hvbox1 = wx.BoxSizer(wx.HORIZONTAL)

        self.Bind(wx.EVT_CLOSE, self.OnClose)

        #Status Bar
        self.StatusBar = wx.StatusBar(self, -1)
        self.SetStatusBar(self.StatusBar)
        self.StatusBar.SetStatusText(self.Engine.GetNameVersion(), 0)

        #Card Search
        self.CardSearchCtrl = wx.TextCtrl(self.panel, -1, "")
        self.CardSearchCtrl.Bind(wx.EVT_TEXT, self.OnSearchInput,
                                 self.CardSearchCtrl)

        #Card List
        self.CardListCtrl = wx.ListCtrl(self.panel,
                                        -1,
                                        size=(300, -1),
                                        style=wx.LC_REPORT | wx.LC_SINGLE_SEL
                                        | wx.LC_NO_HEADER | wx.LC_HRULES)
        self.CardListCtrl.InsertColumn(0, 'Name')
        self.CardListCtrl.InsertColumn(1, 'CardID')
        n = 0
        for c in self.Engine.CardDict.GetSortedValues():
            idx = self.CardListCtrl.InsertStringItem(n, c.Name)
            self.CardListCtrl.SetStringItem(idx, 1, c.CardID)
            n += 1
        self.CardListCtrl.SetColumnWidth(0, 310)
        self.CardListCtrl.SetColumnWidth(1, 0)
        self.CardListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnCardSelected)
        self.CardListCtrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,
                               self.OnCardListItemRClick)
        self.CardListCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnAddCard)

        #Deck List
        self.DeckHeaderText = wx.StaticText(self.panel, -1, 'Cards in Deck: 0')
        self.DeckListCtrl = wx.ListCtrl(self.panel,
                                        -1,
                                        size=(-1, 520),
                                        style=wx.LC_REPORT | wx.LC_SINGLE_SEL
                                        | wx.LC_HRULES)
        self.DeckListCtrl.InsertColumn(0, 'Card Name')
        self.DeckListCtrl.SetColumnWidth(0, 350)
        self.DeckListCtrl.InsertColumn(1, 'Color')
        self.DeckListCtrl.SetColumnWidth(1, 50)
        self.DeckListCtrl.InsertColumn(2, 'Level')
        self.DeckListCtrl.SetColumnWidth(2, 50)
        self.DeckListCtrl.InsertColumn(3, 'Cost')
        self.DeckListCtrl.SetColumnWidth(3, 50)
        self.DeckListCtrl.InsertColumn(4, 'Power')
        self.DeckListCtrl.SetColumnWidth(4, 50)
        self.DeckListCtrl.InsertColumn(5, 'Soul')
        self.DeckListCtrl.SetColumnWidth(5, 50)
        self.DeckListCtrl.InsertColumn(6, 'Count')
        self.DeckListCtrl.SetColumnWidth(6, 50)
        self.DeckListCtrl.InsertColumn(7, 'CardID')
        self.DeckListCtrl.SetColumnWidth(7, 0)
        self.DeckListCtrl.Bind(wx.EVT_LIST_COL_CLICK, self.OnDeckColumnClick)
        self.DeckListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED,
                               self.OnDeckCardSelected)
        self.DeckListCtrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,
                               self.OnDeckListItemRClick)
        self.DeckListCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnRemoveCard)

        #Deck Graph
        self.DeckGraphCanvas = PlotCanvas(self.panel)
        self.DeckGraphCanvas.Draw(self.DrawGraph(), xAxis=(0, 4))

        #Card Info
        self.CardNameCtrl = wx.StaticText(self.panel,
                                          -1,
                                          style=wx.ALIGN_CENTRE)
        self.CardImageCtrl = wx.StaticBitmap(self.panel, -1, size=(300, 420))
        self.CardDescriptionCtrl = wx.TextCtrl(self.panel,
                                               -1,
                                               size=(300, 150),
                                               style=wx.TE_MULTILINE
                                               | wx.TE_READONLY | wx.TE_LEFT)

        #Build UI
        self.BuildUI()

        #Layout
        self.hvbox1.Add(self.CardSearchCtrl, 1, wx.ALL | wx.EXPAND, 2)
        self.hvbox1.Add(self.CardReloadCtrl, 0, wx.ALL | wx.EXPAND, 2)
        self.vbox1.Add(self.hvbox1, 0, wx.ALL | wx.EXPAND, 2)
        self.vbox1.Add(self.CardListCtrl, 1, wx.ALL | wx.EXPAND, 2)

        self.hmbox1.Add(self.DeckHeaderText, 1, wx.ALL | wx.EXPAND, 2)
        self.hmbox2.Add(self.DeckListCtrl, 1, wx.ALL | wx.EXPAND, 2)
        self.graphbox.Add(self.DeckGraphCanvas, 1, wx.ALL | wx.EXPAND, 2)
        self.vbox2.Add(self.hmbox1, 0, wx.ALL | wx.EXPAND, 2)
        self.vbox2.Add(self.hmbox2, 1, wx.ALL | wx.EXPAND, 2)
        self.vbox2.Add(self.graphbox, 1, wx.ALL | wx.EXPAND, 2)

        self.vbox5.Add(self.CardNameCtrl, 0, wx.ALL | wx.ALIGN_CENTER, 2)
        self.vbox5.Add(self.CardImageCtrl, 0, wx.ALL | wx.ALIGN_CENTER, 2)
        self.vbox5.Add(self.CardDescriptionCtrl, 1,
                       wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 2)

        self.hbox.Add(self.vbox1, 0, wx.EXPAND | wx.ALL, 2)
        self.hbox.Add(self.vbox2, 1, wx.EXPAND | wx.ALL, 2)
        self.hbox.Add(self.vbox5, 0, wx.EXPAND | wx.ALL, 2)
        self.panel.SetSizer(self.hbox)
        self.panel.Layout()

    def BuildUI(self, changes=0):
        if changes:
            self.CardReloadCtrl.Destroy()
            self.GetToolBar().Destroy()
            self.CardListPopupMenu.Destroy()
            self.DeckListPopupMenu.Destroy()

        #Menu
        self.Menu = wx.MenuBar()
        self.mFile = wx.Menu()
        self.mGame = wx.Menu()
        self.mTools = wx.Menu()
        self.mHelp = wx.Menu()

        #File Menu
        item = wx.MenuItem(self.mFile, ID_NEW, 'New')
        item.SetBitmap(self.Engine.GetImageSkin('New'))
        self.Bind(wx.EVT_MENU, self.OnNew, item)
        self.mFile.AppendItem(item)

        item = wx.MenuItem(self.mFile, ID_OPEN, 'Open')
        item.SetBitmap(self.Engine.GetImageSkin('Open'))
        self.Bind(wx.EVT_MENU, self.OnOpen, item)
        self.mFile.AppendItem(item)

        item = wx.MenuItem(self.mFile, ID_SAVE, 'Save')
        item.SetBitmap(self.Engine.GetImageSkin('Save'))
        self.Bind(wx.EVT_MENU, self.OnSave, item)
        self.mFile.AppendItem(item)

        item = wx.MenuItem(self.mFile, ID_SAVEAS, 'SaveAs')
        item.SetBitmap(self.Engine.GetImageSkin('SaveAs'))
        self.Bind(wx.EVT_MENU, self.OnSaveAs, item)
        self.mFile.AppendItem(item)

        item = wx.MenuItem(self.mFile, ID_CLOSE, 'Close')
        item.SetBitmap(self.Engine.GetImageSkin('Close'))
        self.Bind(wx.EVT_MENU, self.OnMenuClose, item)
        self.mFile.AppendItem(item)

        #Game Menu
        item = self.mGame.Append(ID_CONNECT, text='Connect')
        self.Bind(wx.EVT_MENU, self.OnConnectMenu, item)

        item = self.mGame.Append(ID_LISTEN, text='Listen')
        self.Bind(wx.EVT_MENU, self.OnListenMenu, item)

        item = self.mGame.Append(ID_PLAY, text='Test')
        self.Bind(wx.EVT_MENU, self.OnPlayMenu, item)

        #Create Menu
        self.Menu.Append(self.mFile, 'File')
        self.Menu.Append(self.mGame, 'Game')
        self.SetMenuBar(self.Menu)

        #Card Reload
        self.CardReloadCtrl = wx.BitmapButton(
            self.panel, -1, self.Engine.GetImageSkin('Reload'))
        self.CardReloadCtrl.SetToolTipString("Reload")
        self.CardReloadCtrl.Bind(wx.EVT_BUTTON, self.OnCardReload)

        #CardList Popup
        self.CardListPopupMenu = wx.Menu()
        item = wx.MenuItem(self.CardListPopupMenu, ID_POPUP_ADD, 'Add')
        item.SetBitmap(self.Engine.GetImageSkin('Todeck'))
        self.Bind(wx.EVT_MENU, self.OnAddCard, item)
        self.CardListPopupMenu.AppendItem(item)

        #DeckList Popup
        self.DeckListPopupMenu = wx.Menu()
        item = wx.MenuItem(self.DeckListPopupMenu, ID_POPUP_REMOVE, 'Remove')
        item.SetBitmap(self.Engine.GetImageSkin('Totrunk'))
        self.Bind(wx.EVT_MENU, self.OnRemoveCard, item)
        self.DeckListPopupMenu.AppendItem(item)

    def OnClose(self, event):
        if self.ShowDialog("Are you sure?", "Exit", wx.YES_NO | wx.NO_DEFAULT
                           | wx.ICON_QUESTION) == wx.ID_YES:
            sys.exit()

    def ShowDialog(self, message, title, style, parent=None):
        if parent == None:
            parent = self
        dialog = wx.MessageDialog(parent, message, title, style)
        return dialog.ShowModal()

    def OnSearchInput(self, event):
        input = self.CardSearchCtrl.GetValue()
        if len(input) < 3:
            return
        li = self.Engine.FindCardByNameLike(input)
        self.CardListCtrl.DeleteAllItems()
        n = 0
        for c in li:
            idx = self.CardListCtrl.InsertStringItem(n, c.Name)
            self.CardListCtrl.SetStringItem(idx, 1, c.CardID)
            n += 1

    def OnCardReload(self, event):
        self.CardListCtrl.DeleteAllItems()
        n = 0
        for c in self.Engine.CardDict.GetSortedValues():
            idx = self.CardListCtrl.InsertStringItem(n, c.Name)
            self.CardListCtrl.SetStringItem(idx, 1, c.CardID)
            n += 1
        self.CardSearchCtrl.SetValue('')

    def OnCardSelected(self, event):
        cardID = self.CardListCtrl.GetItem(event.m_itemIndex, 1).GetText()
        card = self.Engine.CardDict.GetCardByID(cardID)
        self.SelectedFromDeck = cardID
        self.ShowCardInfo(card)

    def OnDeckCardSelected(self, event):
        cardID = self.DeckListCtrl.GetItem(event.m_itemIndex, 7).GetText()
        card = self.Engine.CardDict.GetCardByID(cardID)
        self.SelectedFromDeck = cardID
        self.ShowCardInfo(card)

    def OnCardListItemRClick(self, event):
        self.panel.PopupMenu(self.CardListPopupMenu)

    def OnDeckListItemRClick(self, event):
        self.panel.PopupMenu(self.DeckListPopupMenu)

    def OnDeckColumnClick(self, event):
        col = event.m_col
        if col == 0:
            self.SortDeckBy = 'Name'
        elif col == 1:
            self.SortDeckBy = 'Color'
        elif col == 2:
            self.SortDeckBy = 'Level'
            self.Plotting = 'Level'
        elif col == 3:
            self.SortDeckBy = 'Cost'
            self.Plotting = 'Cost'
        elif col == 4:
            self.SortDeckBy = 'Power'
            self.Plotting = 'Power'
        elif col == 5:
            self.SortDeckBy = 'Soul'
            self.Plotting = 'Soul'
        elif col == 6:
            self.SortDeckBy = 'Count'
        self.RefreshCardList()

    def ShowCardInfo(self, card):
        self.CardNameCtrl.SetLabel(card.Name.replace('&', '&&'))
        self.CardImageCtrl.SetBitmap(self.Engine.GetImageBigCard(card))

        desc = 'Card No: ' + card.CardID + ' Rarity: ' + card.Rarity + '\n'
        desc += 'Color: ' + card.Color + ' (' + card.Side + ')\n'
        desc += 'Level: ' + str(card.Level) + ' Cost: ' + str(card.Cost)
        desc += ' Power: ' + str(card.Power) + ' Soul: ' + str(
            card.Soul) + '\n'
        desc += 'Traits: '
        for trait in card.Traits:
            desc += '[' + trait + '] '
        desc += '\nTriggers: '
        for trigger in card.Triggers:
            desc += '[' + trigger + '] '
        desc += '\n\nFlavor:\n' + card.Flavor + '\n'
        desc += '\nTEXT:\n' + card.Text + '\n'

        self.CardDescriptionCtrl.SetValue(desc)
        self.panel.SendSizeEvent()

    def OnAddCard(self, event):
        if self.SelectedFromDeck == '':
            return
        c = self.Engine.CardDict.GetCardByID(self.SelectedFromDeck)
        self.Engine.Deck.Add(c)
        self.RefreshCardList()

    def OnRemoveCard(self, event):
        if self.SelectedFromDeck == '':
            return
        self.Engine.Deck.RemoveCardByID(self.SelectedFromDeck)
        self.SelectedFromDeck = ''
        self.RefreshCardList()

    def RefreshCardList(self):
        self.DeckListCtrl.DeleteAllItems()
        for card, count in self.Engine.Deck.GetCardsAndCounts(self.SortDeckBy):
            idx = self.DeckListCtrl.InsertStringItem(
                self.DeckListCtrl.GetItemCount(), card.Name)
            self.DeckListCtrl.SetStringItem(idx, 1, card.Color)
            self.DeckListCtrl.SetStringItem(idx, 2, str(card.Level))
            self.DeckListCtrl.SetStringItem(idx, 3, str(card.Cost))
            self.DeckListCtrl.SetStringItem(idx, 4, str(card.Power))
            self.DeckListCtrl.SetStringItem(idx, 5, str(card.Soul))
            self.DeckListCtrl.SetStringItem(idx, 6, str(count))
            self.DeckListCtrl.SetStringItem(idx, 7, card.CardID)
        self.DeckHeaderText.SetLabel('Cards in Deck: ' +
                                     str(self.Engine.Deck.GetCardCount()))
        self.DeckGraphCanvas.Draw(self.DrawGraph())

    def OnNew(self, event):
        self.Engine.NewDeck()
        self.SelectedFromDeck = ''
        self.RefreshCardList()

    def OnOpen(self, event=None, path=''):
        if path == '':
            dialog = wx.FileDialog(self, 'Open...', "", "",
                                   "XML Deck files (*.xml)|*.xml", wx.FD_OPEN)
            dialog.SetPath(os.path.join(self.Engine.DecksDirectory,
                                        'deck.xml'))
            if dialog.ShowModal() != wx.ID_OK:
                dialog.Destroy()
                return
            else:
                name = dialog.GetFilename()
                dir = dialog.GetDirectory()
                path = os.path.join(dir, name)
                dialog.Destroy()
        self.Engine.OpenDeck(path)
        self.Engine.DeckPath = path
        self.RefreshCardList()

    def OnSave(self, event):
        if self.Engine.DeckPath != '':
            self.Engine.SaveDeck(self.Engine.Deck, self.Engine.DeckPath)
        else:
            self.OnSaveAs(event)

    def OnSaveAs(self, event):
        dialog = wx.FileDialog(self, "Save As...", "", "",
                               "XML Deck files (*.xml)|*.xml", wx.FD_SAVE)
        dialog.SetPath(os.path.join(self.Engine.DecksDirectory, 'deck.xml'))
        if dialog.ShowModal() == wx.ID_OK:
            name = dialog.GetFilename()
            dir = dialog.GetDirectory()
            path = os.path.join(dir, name)
            if not path.endswith('.xml'):
                path += '.xml'
            self.Engine.SaveDeck(self.Engine.Deck, path)
            self.Engine.DeckPath = path
        dialog.Destroy()

    def OnMenuClose(self, event):
        self.Close()

    def OnPlayMenu(self, event):
        self.Engine.GameFrame = gameframe.GameFrame(self.Engine)
        self.Engine.Game = self.Engine.GameFrame.Game
        self.Engine.Network = network.Network(self.Engine.Game)
        #self.Engine.Game._nick = self.Engine.GetSetting('Nick')
        self.Engine.Game.Shuffle()
        self.Engine.GameFrame.Show()

    def OnListenMenu(self, event):
        self.Engine.GameFrame = gameframe.GameFrame(self.Engine)
        self.Engine.Game = self.Engine.GameFrame.Game
        self.Engine.Network = network.Network(self.Engine.Game)
        dialog = dialogs.ListenDialog(self)
        dialog.ShowModal()

    def OnConnectMenu(self, event):
        self.Engine.GameFrame = gameframe.GameFrame(self.Engine)
        self.Engine.Game = self.Engine.GameFrame.Game
        self.Engine.Network = network.Network(self.Engine.Game)
        dialog = dialogs.ConnectionDialog(self)
        dialog.ShowModal()

    def DrawGraph(self):
        lines = []
        last_point = (-1, 0)
        for x, y in self.Engine.Deck.GetAttrsAndCounts(self.Plotting):
            lines.append(PolyLine([last_point, (x, y)], width=5))
            last_point = (x, y)
        if not lines:
            lines.append(PolyLine([(0, 0), (0, 0)]))
        return PlotGraphics(lines, self.Plotting, self.Plotting, 'Count')
Пример #22
0
    def build(self, panel):
        hboxMain = wx.BoxSizer(wx.HORIZONTAL)

        vboxInput = wx.BoxSizer(wx.VERTICAL)

        # horizontal box containing labels for index including date (from-to)
        hboxIndexLabel = wx.BoxSizer(wx.HORIZONTAL)
        hboxIndexLabel.Add(wx.StaticText(panel, label='Index'),
                           flag=wx.RIGHT,
                           border=81)
        hboxIndexLabel.Add(wx.StaticText(panel, label='Begin'),
                           flag=wx.RIGHT,
                           border=70)
        hboxIndexLabel.Add(wx.StaticText(panel, label='Ende'))

        vboxInput.Add(hboxIndexLabel,
                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP,
                      border=10)

        # horizontal box containing value-fields for index including date (from-to)
        hboxIndexValue = wx.BoxSizer(wx.HORIZONTAL)

        self.ctrl_stock_name = wx.TextCtrl(panel)
        hboxIndexValue.Add(self.ctrl_stock_name, flag=wx.RIGHT, border=8)
        self.ctrl_stock_start = wx.DatePickerCtrl(panel,
                                                  -1,
                                                  style=wx.DP_DROPDOWN
                                                  | wx.DP_SHOWCENTURY)
        hboxIndexValue.Add(self.ctrl_stock_start)
        self.ctrl_stock_end = wx.DatePickerCtrl(panel,
                                                -1,
                                                style=wx.DP_DROPDOWN
                                                | wx.DP_SHOWCENTURY)
        hboxIndexValue.Add(self.ctrl_stock_end)

        vboxInput.Add(hboxIndexValue,
                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
                      border=10)

        # fetch button
        self.btn_update_index = wx.Button(panel, label="Fetch Index")
        vboxInput.Add(self.btn_update_index, flag=wx.ALL, border=5)
        self.btn_process = wx.Button(panel, label="Process")
        vboxInput.Add(self.btn_process, flag=wx.ALL, border=5)

        vboxInput.Add((-1, 10))  # space between index and trader

        # trader options
        vboxTraderLeft = wx.BoxSizer(wx.VERTICAL)
        self.ctrl_trader_mode = wx.ComboBox(panel,
                                            choices=TRADER_MODES,
                                            style=wx.CB_READONLY)
        vboxTraderLeft.Add(wx.StaticText(panel, label='Trader'),
                           flag=wx.ALL,
                           border=5)
        vboxTraderLeft.Add(self.ctrl_trader_mode, flag=wx.ALL, border=5)

        vboxTraderRight = wx.BoxSizer(wx.VERTICAL)

        hboxTraderToggles = wx.BoxSizer(wx.HORIZONTAL)
        self.ctrl_dynamic = wx.CheckBox(panel, label="dynamic")
        self.ctrl_reverse = wx.CheckBox(panel, label="reverse")
        self.ctrl_initial_funds = wx.lib.intctrl.IntCtrl(panel)
        hboxTraderToggles.Add(self.ctrl_dynamic, flag=wx.ALL, border=5)
        hboxTraderToggles.Add(self.ctrl_reverse, flag=wx.ALL, border=5)
        vboxTraderRight.Add(hboxTraderToggles, flag=wx.ALL, border=5)
        vboxTraderRight.Add(self.ctrl_initial_funds, flag=wx.ALL, border=5)

        vboxTraderOptions = wx.BoxSizer(wx.HORIZONTAL)
        vboxTraderOptions.Add(vboxTraderLeft)
        vboxTraderOptions.Add(vboxTraderRight)

        vboxInput.Add(vboxTraderOptions,
                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
                      border=10)

        # horizontal box containing labels for trendindicator
        vboxInput.Add(self.indicator1,
                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP,
                      border=10)
        vboxInput.Add(self.indicator2,
                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP,
                      border=10)

        # panel for plotting the graph
        vboxOutput = wx.BoxSizer(wx.VERTICAL)
        canvas = PlotCanvas(panel)
        canvas.SetEnableLegend(True)
        canvas.SetEnableDrag(True)
        canvas.SetShowScrollbars(True)
        canvas.SetEnableZoom(True)
        canvas.SetEnableAntiAliasing(True)
        self.canvas = canvas
        self.text_out = wx.StaticText(panel, label="no text")

        vboxOutput.Add(self.canvas, 3, flag=wx.EXPAND)
        vboxOutput.Add(self.text_out, 1)

        # sizer for entire frame
        hboxMain.Add(vboxInput)
        hboxMain.Add(vboxOutput, 1, flag=wx.EXPAND)

        panel.SetSizer(hboxMain)
Пример #23
0
class SolverStats(wx.Panel):
    """Displays solver statistics.
    """
    def __init__(self, parent):
        super(SolverStats, self).__init__(parent)

        # Solver states to plot
        self.results = []

        self._init_ui()

    def _init_ui(self):
        """Builds GUI.
        """

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.best_canvas = PlotCanvas(self)
        self.best_canvas.useScientificNotation = True
        self.current_canvas = PlotCanvas(self)
        self.current_canvas.useScientificNotation = True
        sizer.Add(self.best_canvas, 1, wx.EXPAND)
        sizer.Add(self.current_canvas, 1, wx.EXPAND)
        self._plot()

        self.SetSizer(sizer)

        pub.subscribe(self._on_solver_state_end, 'SOLVER_STATE_END')
        pub.subscribe(self._on_solver_state_reset, 'SOLVER_STATE_RESET')

    def _plot(self):
        """Plots best and current paths data.
        """

        self.best_canvas.Clear()
        self.current_canvas.Clear()

        if len(self.results) > 0:
            x_max = self.results[-1].time
            self.best_canvas.xSpec = (0, x_max)
            self.current_canvas.xSpec = (0, x_max)

        best_points = [
            (r.time, r.best.distance) for r in self.results
            if r.best is not None and isinstance(r.best.distance, int)
        ]
        best_line = PolyLine(best_points)
        best_plot = PlotGraphics([best_line],
                                 title='Best path distance over time',
                                 xLabel='Time [ns]',
                                 yLabel='Distance')

        current_points = [
            (r.time, r.current.distance) for r in self.results
            if r.current is not None and isinstance(r.current.distance, int)
        ]
        current_line = PolyLine(current_points)
        current_plot = PlotGraphics([current_line],
                                    title='Current path distance over time',
                                    xLabel='Time [ns]',
                                    yLabel='Distance')

        self.best_canvas.Draw(best_plot)
        self.current_canvas.Draw(current_plot)

    def reset(self):
        """Resets this control to its initial state.
        """

        self.results = []
        self._plot()

    def _on_solver_state_end(self, results):
        """Handles end of solving message.
        """

        self.results = results
        self._plot()

    def _on_solver_state_reset(self):
        """Handles SOLVER_STATE_RESET message.
        """

        self.reset()
Пример #24
0
class Psat_finder(wx.Frame):

    def __init__(self, parent, title):
        super(Psat_finder, self).__init__(parent, title=title, size=(800, 700))
        self.ButtonPanel = wx.Panel(self)


#Main window

        self.windowSizer = wx.BoxSizer(wx.VERTICAL)

        self.windowSizer.Add(self.ButtonPanel, 1, wx.EXPAND | wx.ALL , 1)

# Input boxes

        self.ac_val = wx.StaticText(self.ButtonPanel, label="ac = ")

        self.b_val = wx.StaticText(self.ButtonPanel, label="b = ")

        self.m_val = wx.StaticText(self.ButtonPanel, label="m = ")
        
        self.P_sat = wx.StaticText(self.ButtonPanel, label="Psat = ")
        
        
        self.T_unit = wx.StaticText(self.ButtonPanel, label="Kelvin ")
        
        self.P_unit = wx.StaticText(self.ButtonPanel, label="Bar")

        self.Tc_input_label = wx.StaticText(self.ButtonPanel, label="Tc")
        self.Tc_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.Pc_input_label = wx.StaticText(self.ButtonPanel, label="Pc")
        self.Pc_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.m_input_label = wx.StaticText(self.ButtonPanel, label="m")
        self.m_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.T_slider = wx.Slider(self.ButtonPanel, -1, 273, 0, 1500, wx.DefaultPosition, (250,-1))
        self.T_slider_label = wx.StaticText(self.ButtonPanel, label="Isotherm Temperature = 273 K")

        self.Button_calc_and_plot = wx.Button(self.ButtonPanel, label='Calculate Parameters and Plot')

        self.PlotPanel = wx.Panel(self.ButtonPanel)
        
        self.canvas = PlotCanvas(self.PlotPanel)
        
        self.PlotPanelSizer = wx.BoxSizer()

        self.panelsizer = wx.GridBagSizer(9, 3)

        self.panelsizer.Add(self.Tc_input_label, (0, 0))
        self.panelsizer.Add(self.Tc_input, (1, 0))

        self.panelsizer.Add(self.Pc_input_label, (2, 0))
        self.panelsizer.Add(self.Pc_input, (3, 0))

        self.panelsizer.Add(self.m_input_label, (4, 0))
        self.panelsizer.Add(self.m_input, (5, 0))


        self.panelsizer.Add(self.ac_val, (0, 2))
        self.panelsizer.Add(self.T_unit, (1, 1))
        self.panelsizer.Add(self.b_val, (1, 2))
        self.panelsizer.Add(self.P_unit, (3, 1))
        self.panelsizer.Add(self.m_val, (2, 2))
        self.panelsizer.Add(self.P_sat, (4, 2))

        self.panelsizer.Add(self.Button_calc_and_plot, (5, 1))
        
        self.panelsizer.Add(self.T_slider_label, (6, 0), (1, 2), wx.EXPAND)
        self.panelsizer.Add(self.T_slider, (7, 0), (1, 3), wx.EXPAND)

        self.PlotPanelSizer.Add(self.canvas, 1, wx.EXPAND)

        self.panelsizer.Add(self.PlotPanel,(9, 0), (1, 3), wx.EXPAND)

        self.panelsizer.AddGrowableCol(2)
        self.panelsizer.AddGrowableRow(9)

#initialize sizers
        self.PlotPanel.SetSizerAndFit(self.PlotPanelSizer)

        self.ButtonPanel.SetSizerAndFit(self.panelsizer)

        self.SetSizer(self.windowSizer)

#Bind Events

        self.Button_calc_and_plot.Bind(wx.EVT_BUTTON, self.calculate_and_plot)
        self.T_slider.Bind(wx.EVT_SLIDER, self.calculate_and_plot)
        
#Initialise Window
        self.Centre()
        self.Show()
        

    def calculate_and_plot(self, event):
        self.T_slider_label.SetLabel('Isotherm Temperature = ' + str(self.T_slider.GetValue()) + ' K')
        Tc = 0
        Pc = 0
        m = 0
        T = float(self.T_slider.GetValue())
        T_Text = str(self.T_slider.GetValue())       

        Tc_text = self.Tc_input.GetValue()
        Pc_text = self.Pc_input.GetValue()
        m_text = self.m_input.GetValue()

        if (Tc_text != '') and (Pc_text != '') and (m_text != ''):
            Tc = float(Tc_text)
            Pc = float(Pc_text)*100
            m = float(m_text)

# Bereken aCrit
        if (Tc != 0) and (Pc != 0) and (m != 0):
            R = Psat.R
            ac = (27*R*R*Tc*Tc)/(64*Pc)
            b = (R*Tc)/(8*Pc)
            
            calc = Psat.Psat(T, Tc, Pc/100, m)
            Psatval = calc[0]

            self.ac_label = str(round(ac,4))
            self.b_label = str(round(b,4))
            if np.isreal(Psatval):
                self.Psat_label = str(round(Psatval,4))
            else:
                self.Psat_label = Psatval

            self.ac_val.SetLabel('ac = ' + self.ac_label)
            self.b_val.SetLabel('b = ' + self.b_label)
            self.m_val.SetLabel('m = ' + m_text)
            self.P_sat.SetLabel('Psat = '+ self.Psat_label)

#Calculate datapoints for vdw EOS 
            Data = np.zeros((1001))
            Line_Data = np.zeros((1001))
            
            for k in range(0,1001):
                Data[k] = 100000*((0.1**(10-0.01*k))) + b+0.01
                Value = max([min([Psat.vdw(T,Psat.a(T, Tc, Pc, m),b , Data[k],0)/100, 100]), -1000])
                V_l = calc[1]
                V_v = calc[2]
                if Data[k] < V_l or Data[k] > V_v:
                    Line_Data[k] = Value
                else:
                    Line_Data[k] = Psatval
            Plot_Data1 = np.vstack((Data, Line_Data)).T
            
            
            Isotherm = PolyLine(Plot_Data1, legend= 'Isotherm, T = ' + T_Text, colour='blue')  
            
            self.canvas.Draw(PlotGraphics([Isotherm], '', ' V', 'P'))
            self.canvas.setLogScale((True, False))
Пример #25
0
    def __init__(self, engine, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.Centre()
        self.Engine = engine
        self.SelectedFromDeck = ''
        self.SelectedFromSide = False
        self.SortDeckBy = 'Name'
        self.Plotting = 'Level'

        #Variables
        self.panel = wx.Panel(self)
        self.vbox1 = wx.BoxSizer(wx.VERTICAL)
        self.vbox2 = wx.BoxSizer(wx.VERTICAL)
        self.vbox5 = wx.BoxSizer(wx.VERTICAL)
        self.hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.graphbox = wx.BoxSizer(wx.HORIZONTAL)
        self.hmbox1 = wx.BoxSizer(wx.HORIZONTAL)
        self.hmbox2 = wx.BoxSizer(wx.HORIZONTAL)
        self.hvbox1 = wx.BoxSizer(wx.HORIZONTAL)

        self.Bind(wx.EVT_CLOSE, self.OnClose)

        #Status Bar
        self.StatusBar = wx.StatusBar(self, -1)
        self.SetStatusBar(self.StatusBar)
        self.StatusBar.SetStatusText(self.Engine.GetNameVersion(), 0)

        #Card Search
        self.CardSearchCtrl = wx.TextCtrl(self.panel, -1, "")
        self.CardSearchCtrl.Bind(wx.EVT_TEXT, self.OnSearchInput,
                                 self.CardSearchCtrl)

        #Card List
        self.CardListCtrl = wx.ListCtrl(self.panel,
                                        -1,
                                        size=(300, -1),
                                        style=wx.LC_REPORT | wx.LC_SINGLE_SEL
                                        | wx.LC_NO_HEADER | wx.LC_HRULES)
        self.CardListCtrl.InsertColumn(0, 'Name')
        self.CardListCtrl.InsertColumn(1, 'CardID')
        n = 0
        for c in self.Engine.CardDict.GetSortedValues():
            idx = self.CardListCtrl.InsertStringItem(n, c.Name)
            self.CardListCtrl.SetStringItem(idx, 1, c.CardID)
            n += 1
        self.CardListCtrl.SetColumnWidth(0, 310)
        self.CardListCtrl.SetColumnWidth(1, 0)
        self.CardListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnCardSelected)
        self.CardListCtrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,
                               self.OnCardListItemRClick)
        self.CardListCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnAddCard)

        #Deck List
        self.DeckHeaderText = wx.StaticText(self.panel, -1, 'Cards in Deck: 0')
        self.DeckListCtrl = wx.ListCtrl(self.panel,
                                        -1,
                                        size=(-1, 520),
                                        style=wx.LC_REPORT | wx.LC_SINGLE_SEL
                                        | wx.LC_HRULES)
        self.DeckListCtrl.InsertColumn(0, 'Card Name')
        self.DeckListCtrl.SetColumnWidth(0, 350)
        self.DeckListCtrl.InsertColumn(1, 'Color')
        self.DeckListCtrl.SetColumnWidth(1, 50)
        self.DeckListCtrl.InsertColumn(2, 'Level')
        self.DeckListCtrl.SetColumnWidth(2, 50)
        self.DeckListCtrl.InsertColumn(3, 'Cost')
        self.DeckListCtrl.SetColumnWidth(3, 50)
        self.DeckListCtrl.InsertColumn(4, 'Power')
        self.DeckListCtrl.SetColumnWidth(4, 50)
        self.DeckListCtrl.InsertColumn(5, 'Soul')
        self.DeckListCtrl.SetColumnWidth(5, 50)
        self.DeckListCtrl.InsertColumn(6, 'Count')
        self.DeckListCtrl.SetColumnWidth(6, 50)
        self.DeckListCtrl.InsertColumn(7, 'CardID')
        self.DeckListCtrl.SetColumnWidth(7, 0)
        self.DeckListCtrl.Bind(wx.EVT_LIST_COL_CLICK, self.OnDeckColumnClick)
        self.DeckListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED,
                               self.OnDeckCardSelected)
        self.DeckListCtrl.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,
                               self.OnDeckListItemRClick)
        self.DeckListCtrl.Bind(wx.EVT_LEFT_DCLICK, self.OnRemoveCard)

        #Deck Graph
        self.DeckGraphCanvas = PlotCanvas(self.panel)
        self.DeckGraphCanvas.Draw(self.DrawGraph(), xAxis=(0, 4))

        #Card Info
        self.CardNameCtrl = wx.StaticText(self.panel,
                                          -1,
                                          style=wx.ALIGN_CENTRE)
        self.CardImageCtrl = wx.StaticBitmap(self.panel, -1, size=(300, 420))
        self.CardDescriptionCtrl = wx.TextCtrl(self.panel,
                                               -1,
                                               size=(300, 150),
                                               style=wx.TE_MULTILINE
                                               | wx.TE_READONLY | wx.TE_LEFT)

        #Build UI
        self.BuildUI()

        #Layout
        self.hvbox1.Add(self.CardSearchCtrl, 1, wx.ALL | wx.EXPAND, 2)
        self.hvbox1.Add(self.CardReloadCtrl, 0, wx.ALL | wx.EXPAND, 2)
        self.vbox1.Add(self.hvbox1, 0, wx.ALL | wx.EXPAND, 2)
        self.vbox1.Add(self.CardListCtrl, 1, wx.ALL | wx.EXPAND, 2)

        self.hmbox1.Add(self.DeckHeaderText, 1, wx.ALL | wx.EXPAND, 2)
        self.hmbox2.Add(self.DeckListCtrl, 1, wx.ALL | wx.EXPAND, 2)
        self.graphbox.Add(self.DeckGraphCanvas, 1, wx.ALL | wx.EXPAND, 2)
        self.vbox2.Add(self.hmbox1, 0, wx.ALL | wx.EXPAND, 2)
        self.vbox2.Add(self.hmbox2, 1, wx.ALL | wx.EXPAND, 2)
        self.vbox2.Add(self.graphbox, 1, wx.ALL | wx.EXPAND, 2)

        self.vbox5.Add(self.CardNameCtrl, 0, wx.ALL | wx.ALIGN_CENTER, 2)
        self.vbox5.Add(self.CardImageCtrl, 0, wx.ALL | wx.ALIGN_CENTER, 2)
        self.vbox5.Add(self.CardDescriptionCtrl, 1,
                       wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 2)

        self.hbox.Add(self.vbox1, 0, wx.EXPAND | wx.ALL, 2)
        self.hbox.Add(self.vbox2, 1, wx.EXPAND | wx.ALL, 2)
        self.hbox.Add(self.vbox5, 0, wx.EXPAND | wx.ALL, 2)
        self.panel.SetSizer(self.hbox)
        self.panel.Layout()
Пример #26
0
    def __init__(self, parent, title):
        super(Psat_finder, self).__init__(parent, title=title, size=(800, 700))
        self.ButtonPanel = wx.Panel(self)


#Main window

        self.windowSizer = wx.BoxSizer(wx.VERTICAL)

        self.windowSizer.Add(self.ButtonPanel, 1, wx.EXPAND | wx.ALL , 1)

# Input boxes

        self.ac_val = wx.StaticText(self.ButtonPanel, label="ac = ")

        self.b_val = wx.StaticText(self.ButtonPanel, label="b = ")

        self.m_val = wx.StaticText(self.ButtonPanel, label="m = ")
        
        self.P_sat = wx.StaticText(self.ButtonPanel, label="Psat = ")
        
        
        self.T_unit = wx.StaticText(self.ButtonPanel, label="Kelvin ")
        
        self.P_unit = wx.StaticText(self.ButtonPanel, label="Bar")

        self.Tc_input_label = wx.StaticText(self.ButtonPanel, label="Tc")
        self.Tc_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.Pc_input_label = wx.StaticText(self.ButtonPanel, label="Pc")
        self.Pc_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.m_input_label = wx.StaticText(self.ButtonPanel, label="m")
        self.m_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.T_slider = wx.Slider(self.ButtonPanel, -1, 273, 0, 1500, wx.DefaultPosition, (250,-1))
        self.T_slider_label = wx.StaticText(self.ButtonPanel, label="Isotherm Temperature = 273 K")

        self.Button_calc_and_plot = wx.Button(self.ButtonPanel, label='Calculate Parameters and Plot')

        self.PlotPanel = wx.Panel(self.ButtonPanel)
        
        self.canvas = PlotCanvas(self.PlotPanel)
        
        self.PlotPanelSizer = wx.BoxSizer()

        self.panelsizer = wx.GridBagSizer(9, 3)

        self.panelsizer.Add(self.Tc_input_label, (0, 0))
        self.panelsizer.Add(self.Tc_input, (1, 0))

        self.panelsizer.Add(self.Pc_input_label, (2, 0))
        self.panelsizer.Add(self.Pc_input, (3, 0))

        self.panelsizer.Add(self.m_input_label, (4, 0))
        self.panelsizer.Add(self.m_input, (5, 0))


        self.panelsizer.Add(self.ac_val, (0, 2))
        self.panelsizer.Add(self.T_unit, (1, 1))
        self.panelsizer.Add(self.b_val, (1, 2))
        self.panelsizer.Add(self.P_unit, (3, 1))
        self.panelsizer.Add(self.m_val, (2, 2))
        self.panelsizer.Add(self.P_sat, (4, 2))

        self.panelsizer.Add(self.Button_calc_and_plot, (5, 1))
        
        self.panelsizer.Add(self.T_slider_label, (6, 0), (1, 2), wx.EXPAND)
        self.panelsizer.Add(self.T_slider, (7, 0), (1, 3), wx.EXPAND)

        self.PlotPanelSizer.Add(self.canvas, 1, wx.EXPAND)

        self.panelsizer.Add(self.PlotPanel,(9, 0), (1, 3), wx.EXPAND)

        self.panelsizer.AddGrowableCol(2)
        self.panelsizer.AddGrowableRow(9)

#initialize sizers
        self.PlotPanel.SetSizerAndFit(self.PlotPanelSizer)

        self.ButtonPanel.SetSizerAndFit(self.panelsizer)

        self.SetSizer(self.windowSizer)

#Bind Events

        self.Button_calc_and_plot.Bind(wx.EVT_BUTTON, self.calculate_and_plot)
        self.T_slider.Bind(wx.EVT_SLIDER, self.calculate_and_plot)
        
#Initialise Window
        self.Centre()
        self.Show()
Пример #27
0
class Psat_finder(wx.Frame):
    def __init__(self, parent, title):
        super(Psat_finder, self).__init__(parent, title=title, size=(800, 700))
        self.ButtonPanel = wx.Panel(self)

        #Main window

        self.windowSizer = wx.BoxSizer(wx.VERTICAL)

        self.windowSizer.Add(self.ButtonPanel, 1, wx.EXPAND | wx.ALL, 1)

        # Input boxes

        self.ac_val = wx.StaticText(self.ButtonPanel, label="ac = ")

        self.b_val = wx.StaticText(self.ButtonPanel, label="b = ")

        self.m_val = wx.StaticText(self.ButtonPanel, label="m = ")

        self.P_sat = wx.StaticText(self.ButtonPanel, label="Psat = ")

        self.T_unit = wx.StaticText(self.ButtonPanel, label="Kelvin ")

        self.P_unit = wx.StaticText(self.ButtonPanel, label="Bar")

        self.Tc_input_label = wx.StaticText(self.ButtonPanel, label="Tc")
        self.Tc_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.Pc_input_label = wx.StaticText(self.ButtonPanel, label="Pc")
        self.Pc_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.m_input_label = wx.StaticText(self.ButtonPanel, label="m")
        self.m_input = wx.TextCtrl(self.ButtonPanel, size=(70, -1))

        self.T_slider = wx.Slider(self.ButtonPanel, -1, 273, 0, 1500,
                                  wx.DefaultPosition, (250, -1))
        self.T_slider_label = wx.StaticText(
            self.ButtonPanel, label="Isotherm Temperature = 273 K")

        self.Button_calc_and_plot = wx.Button(
            self.ButtonPanel, label='Calculate Parameters and Plot')

        self.PlotPanel = wx.Panel(self.ButtonPanel)

        self.canvas = PlotCanvas(self.PlotPanel)

        self.PlotPanelSizer = wx.BoxSizer()

        self.panelsizer = wx.GridBagSizer(9, 3)

        self.panelsizer.Add(self.Tc_input_label, (0, 0))
        self.panelsizer.Add(self.Tc_input, (1, 0))

        self.panelsizer.Add(self.Pc_input_label, (2, 0))
        self.panelsizer.Add(self.Pc_input, (3, 0))

        self.panelsizer.Add(self.m_input_label, (4, 0))
        self.panelsizer.Add(self.m_input, (5, 0))

        self.panelsizer.Add(self.ac_val, (0, 2))
        self.panelsizer.Add(self.T_unit, (1, 1))
        self.panelsizer.Add(self.b_val, (1, 2))
        self.panelsizer.Add(self.P_unit, (3, 1))
        self.panelsizer.Add(self.m_val, (2, 2))
        self.panelsizer.Add(self.P_sat, (4, 2))

        self.panelsizer.Add(self.Button_calc_and_plot, (5, 1))

        self.panelsizer.Add(self.T_slider_label, (6, 0), (1, 2), wx.EXPAND)
        self.panelsizer.Add(self.T_slider, (7, 0), (1, 3), wx.EXPAND)

        self.PlotPanelSizer.Add(self.canvas, 1, wx.EXPAND)

        self.panelsizer.Add(self.PlotPanel, (9, 0), (1, 3), wx.EXPAND)

        self.panelsizer.AddGrowableCol(2)
        self.panelsizer.AddGrowableRow(9)

        #initialize sizers
        self.PlotPanel.SetSizerAndFit(self.PlotPanelSizer)

        self.ButtonPanel.SetSizerAndFit(self.panelsizer)

        self.SetSizer(self.windowSizer)

        #Bind Events

        self.Button_calc_and_plot.Bind(wx.EVT_BUTTON, self.calculate_and_plot)
        self.T_slider.Bind(wx.EVT_SLIDER, self.calculate_and_plot)

        #Initialise Window
        self.Centre()
        self.Show()

    def calculate_and_plot(self, event):
        self.T_slider_label.SetLabel('Isotherm Temperature = ' +
                                     str(self.T_slider.GetValue()) + ' K')
        Tc = 0
        Pc = 0
        m = 0
        T = float(self.T_slider.GetValue())
        T_Text = str(self.T_slider.GetValue())

        Tc_text = self.Tc_input.GetValue()
        Pc_text = self.Pc_input.GetValue()
        m_text = self.m_input.GetValue()

        if (Tc_text != '') and (Pc_text != '') and (m_text != ''):
            Tc = float(Tc_text)
            Pc = float(Pc_text) * 100
            m = float(m_text)


# Bereken aCrit
        if (Tc != 0) and (Pc != 0) and (m != 0):
            R = Psat.R
            ac = (27 * R * R * Tc * Tc) / (64 * Pc)
            b = (R * Tc) / (8 * Pc)

            calc = Psat.Psat(T, Tc, Pc / 100, m)
            Psatval = calc[0]

            self.ac_label = str(round(ac, 4))
            self.b_label = str(round(b, 4))
            if np.isreal(Psatval):
                self.Psat_label = str(round(Psatval, 4))
            else:
                self.Psat_label = Psatval

            self.ac_val.SetLabel('ac = ' + self.ac_label)
            self.b_val.SetLabel('b = ' + self.b_label)
            self.m_val.SetLabel('m = ' + m_text)
            self.P_sat.SetLabel('Psat = ' + self.Psat_label)

            #Calculate datapoints for vdw EOS
            Data = np.zeros((1001))
            Line_Data = np.zeros((1001))

            for k in range(0, 1001):
                Data[k] = 100000 * ((0.1**(10 - 0.01 * k))) + b + 0.01
                Value = max([
                    min([
                        Psat.vdw(T, Psat.a(T, Tc, Pc, m), b, Data[k], 0) / 100,
                        100
                    ]), -1000
                ])
                V_l = calc[1]
                V_v = calc[2]
                if Data[k] < V_l or Data[k] > V_v:
                    Line_Data[k] = Value
                else:
                    Line_Data[k] = Psatval
            Plot_Data1 = np.vstack((Data, Line_Data)).T

            Isotherm = PolyLine(Plot_Data1,
                                legend='Isotherm, T = ' + T_Text,
                                colour='blue')

            self.canvas.Draw(PlotGraphics([Isotherm], '', ' V', 'P'))
            self.canvas.setLogScale((True, False))