def __init__(self, dock, parent, Real_Time=False): _PlotCanvas_Base.__init__(self, dock, parent, Real_Time) #print 'REAL_TIME ??',Real_Time,self.Real_Time self.parent = parent # some initial values SHOULD NOT BE HERE !! self.grid_x = 10 self.grid_y = 10 # ************************************************************* # popup menus # ************************************************************* pre = [ _(0, 'Remove Cursors'), _(0, 'Memo Visible'), _(0, 'Move Memo Here'), _(0, 'Copy to Clipboard'), '-', _(0, 'Linear Expansion'), _(0, 'Not Transparent'), _(0, 'Transparency 200'), _(0, 'Transparency 150'), _(0, 'Transparency 100'), _(0, 'Transparency 50') ] self.Popup_Menu = My_Popup_Menu(self._OnPopupItemSelected, None, pre=pre) self.Transparancy = 0 # At this point we can do all actions that really draw !! # call OnSize, to make sure the dc-buffer is initialized. self.Set_Canvas(self.BG_Color, self.Grid_Color) self._On_Size(None)
def BP_Display_Vars(self, After=False): if not (self.BP_Form): self.BP_Form = _BP_Form() self.BP_Form.Show(True) HL = wx.TextAttr("RED", "YELLOW") if After: Txt = self.BP_Form.L31 else: Txt = self.BP_Form.L21 # Display Inputs #start = Txt.GetLastPosition() Txt.Clear() start = 0 Txt.AppendText(_(14, 'Inputs\n')) Txt.SetStyle(0, start + 6, HL) for input in self.Inputs: #Txt.AppendText ( str(input) + ' = ' + str ( self.Input_Value[input] ) +'\n') Txt.AppendText(str(input) + ' = ' + str(self.In[input]) + '\n') #start = 1 + Txt.GetLastPosition() if After: Txt = self.BP_Form.L32 else: Txt = self.BP_Form.L22 # Display Inputs Txt.Clear() start = 0 Txt.AppendText(_(15, 'Outputs\n')) Txt.SetStyle(start, start + 7, HL) # ********************************************** # ********************************************** def Disp(value): if isinstance(value, list): line = 'List' for item in value: line += '\n' + str(item) return line elif isinstance(value, tuple): line = 'Tuple' for item in value: line += '\n' + str(item) return line elif isinstance(value, dict): line = '{dict}' for key in value: line += '\n ' + str(key) + ' = ' + str(value[key]) return line else: return str(value) + '\n' # ********************************************** for output in self.Outputs: start = Txt.GetLastPosition() Txt.AppendText(str(output) + ': ') Txt.SetStyle(start, start + 2, HL) Txt.AppendText(Disp(self.Out[output]))
def After_Init (self): self.Caption = _(8,'Oscilloscope\nHistory') # Define the input pins # <Pin-Name>, <Data_Type>, <Required>, <Description> for i in range ( 1, self.I + 1 ) : self.Inputs [i] = [ _(3,'Signals ') + str(i), TIO_ARRAY, (i==1), _(5, 'Signals to be displayed on the Scope Display' )] # we want this image-window to be centered self.Center = True # Create the GUI controls CD = self.Create_Control ( t_C_Scope_Plot )
class t_Input_Selector ( tLWB_Brick ): Description = _(16, """Select an input signal.""") I = 5 def After_Init (self): self.Caption = _(19, 'Input Selector') # Define the input pins # <Pin-Name>, <Data_Type>, <Required>, <Description> for i in range ( 1, self.I+1 ) : self.Inputs [i] = ['IN['+ str(i)+']', TIO_ARRAY, i==1 ] # Define the output pins # <Pin-Name>, <Data_Type>, <Description> self.Outputs [1] = \ [ _(17, 'Output'), TIO_ARRAY, _(18, 'Data from selected Input' ) ] # Create the GUI controls CD = self.Create_Control ( t_C_Spin_Button, 'Input' ) CD.Range = [ 1, self.I ] # ********************************************************************** # this procedure is only called when inputs (or parameters) have changed # ********************************************************************** def Generate_Output_Signals ( self, In, Out, Par, XIn, XOut, XPar ) : if XIn [0] or XPar [0] : Out [1] = In [ Par [ self.I + 1 ] ]
def _Create_Channel(self, chan): self.Signal_Name.append(_(0, 'Signal-' + str(chan + 1))) self.Signal_Gain.append(None) self.Signal_Offset.append(None) self.Signal_Color.append(self.Colors[chan]) self.Signal_Top.append(100) self.Signal_Bottom.append(-100)
def After_Init (self): self.Caption = _(19, 'Input Selector') # Define the input pins # <Pin-Name>, <Data_Type>, <Required>, <Description> for i in range ( 1, self.I+1 ) : self.Inputs [i] = ['IN['+ str(i)+']', TIO_ARRAY, i==1 ] # Define the output pins # <Pin-Name>, <Data_Type>, <Description> self.Outputs [1] = \ [ _(17, 'Output'), TIO_ARRAY, _(18, 'Data from selected Input' ) ] # Create the GUI controls CD = self.Create_Control ( t_C_Spin_Button, 'Input' ) CD.Range = [ 1, self.I ]
def After_Init (self): self.Caption = _(2,'Oscilloscope') # Define the input pins # <Pin-Name>, <Data_Type>, <Required>, <Description> for i in range ( 1, self.I + 1 ) : self.Inputs [i] = ['Signals ' + str(i), TIO_ARRAY, (i==1), _(5, 'Signals to be displayed on the Scope Display' )] # Define the output pins # <Pin-Name>, <Data_Type>, <Description> self.Outputs [1] = [ _(6,'Start / Stop'), TIO_NUMBER, _(1,'Can be used to control an AD-Converter.') ] # we want this image-window to be centered self.Center = True # Create the GUI controls CD = self.Create_Control ( t_C_Scope_Display )
def After_Init (self): self.Caption = 'VPython' #self.Diagnostic_Mode = True # This device wants to be executed every loop self.Continuous = True # Define the input pins self.Inputs [1] = [ _(0, 'Python Code') , TIO_STRING, REQUIRED ] #self.Inputs [1] = [ _(0, 'Python Code') , TIO_INTERACTION, REQUIRED ] self.Inputs [2] = [ _(0, 'Python Controls') , TIO_INTERACTION ] # we want this image-window to be centered self.Center = True # Create VPython CD = self.Create_Control ( t_C_VPython ) CD.Input_Channel = 1 self.Scene = None
def _Create_Channel_Labels(self, chan, Label_Top, Label_Bottom): Label_Top.SetBackgroundColour(self.Scope_Normal.BG_Color) Label_Top.SetForegroundColour(self.Signal_Color[chan]) Label_Top.SetToolTip(_(2, 'Click to Set Margins')) Label_Top.Bind(wx.EVT_LEFT_DOWN, self._OnLabel_Top_Click) self.Top_Labels.append(Label_Top) self.Labels_IDs.append(Label_Top.GetId()) Label_Bottom.SetBackgroundColour(self.Scope_Normal.BG_Color) Label_Bottom.SetForegroundColour(self.Signal_Color[chan]) Label_Bottom.SetToolTip(_(2, 'Click to Set Margins')) Label_Bottom.Bind(wx.EVT_LEFT_DOWN, self._OnLabel_Top_Click) self.Bottom_Labels.append(Label_Bottom) self.Labels_IDs.append(Label_Bottom.GetId()) self._Update_Channel(chan) # After changing a label, it's resized, # So we need to call the containers resizer self.Panel_Top.SendSizeEvent() self.Panel_Bottom.SendSizeEvent()
def After_Init (self): self.Caption = _(15, 'Load SoundFile') # Define the output pins # <Pin-Name>, <Data_Type>, <Description> self.Outputs [1] = \ [ _(11, 'FileName'), TIO_STRING, _(12, 'Filename of the Sound File.' ) ] self.Outputs [2] = \ [ _(13, 'Sound'), TIO_ARRAY, _(14, 'Data from the Sound File' ) ] # ************************************************* # Create File Select # Range = one of the constants definied in # ../support/dialog_support.py # or # a general file dialog mask, e.g. # 'dBase Files(*.db)|*.db|All Files(*.*)|*.*' CD = self.Create_Control ( t_C_File_Open, 'Read Sound File', Default = '' ) CD.Range = '*.wav'
def After_Init (self): self.Caption = _(1, 'Play SoundFile') self.Inputs [1] = ['FileName or Stream', TIO_ARRAY, True ] # Create the GUI controls CD = self.Create_Control ( t_C_Slider, 'Volume', 20 ) CD.Range = [ 1, 100 ] CD = self.Create_Control ( t_C_Buttons, '', 20 ) CD.Caption = [ 'RePlay', 'Stop' ] self.soundfile = None
def _On_Show_Popup(self, event): # ************************************************************* # Create popup menu # ************************************************************* menu_items = [] menu_items.append(_(0, 'Remove Cursors')) menu_items.append(_(0, 'Dual Cursor')) menu_items.append(_(0, 'Single Expand 1')) menu_items.append(_(0, 'Single Expand 2')) menu_items.append(_(0, 'Single Expand 4')) menu_items.append(_(0, 'Single Expand 8')) menu_items.append('-') menu_items += self.Signal_Names self.Popup_Menu = My_Popup_Menu(self._OnPopupItemSelected, None, pre=menu_items) for i in range(5): self.Popup_Menu.SetChecked(1 + i, False) self.Popup_Menu.SetChecked(1 + self.CursorType, True) for i in range(len(self.Signal_Names)): self.Popup_Menu.SetChecked(i + 6, self.Selected_Signal == i) self.Hit_Pos = self.ScreenToClient(event.GetPosition()) self.PopupMenu(self.Popup_Menu, pos=self.Hit_Pos) self.Popup_Menu.Destroy()
def After_Init(self): self.Caption = 'Visual_SQL' #self.Diagnostic_Mode = True # Define the input pins self.Inputs[1] = [_(0, 'Table Info'), TIO_TREE, REQUIRED] # we want this image-window to be centered self.Center = True # Create the GUI controls CD = self.Create_Control(t_C_Visual_SQL) CD.Input_Channel = 1
def After_Init (self): self.Caption = '2D Scene' #self.Diagnostic_Mode = True # This device wants to be executed every loop self.Continuous = True # Define the input pins self.Inputs [1] = [ _(4, 'Signal 1') , TIO_STRING, REQUIRED ] # we want this image-window to be centered self.Center = True # Create the GUI controls CD = self.Create_Control ( t_C_2D_Scene ) CD.Input_Channel = 1
def After_Init (self): self.Caption =_(0, 'BTC Sound' ) # Define the input pins # <Pin-Name>, <Data_Type>, <Required>, <Description> self.Inputs [1] = ['Input Stream', TIO_ARRAY, True ] # Define the output pins # <Pin-Name>, <Data_Type>, <Description> self.Outputs [1] = ['Output_Stream', TIO_ARRAY ] # Create the GUI controls CD = self.Create_Control ( t_C_Text_Control, 'Btc' ) CD = self.Create_Control ( t_C_Text_Control, 'R [kOhm]' ) CD = self.Create_Control ( t_C_Text_Control, 'C [nF]' ) CD = self.Create_Control ( t_C_Text_Control, 'Freq. [Hz]' ) CD = self.Create_Control ( t_C_Buttons, 'Knopje' )
class t_HTML ( tLWB_Brick ): Description = _(7,"""Shows an html page, that can be used for - course material - instructions - to store answers of students""") def After_Init (self): self.Caption = 'HTML' # we want this image-window to be centered self.Center = False # we want to let this window float, # so it can be extracted from the application self.Float = True # Create the GUI controls CD = self.Create_Control ( t_C_Html )
class t_Signal_Workbench ( tLWB_Brick ): Description = _(10, """Signal WorkBench. bla bla ... """ ) def After_Init (self): self.Caption = 'Signal WorkBench' # we want this image-window to be centered self.Center = True # Create the GUI controls CD = self.Create_Control ( t_C_Signal_WorkBench ) # ********************************************************************* # Procedure only called when inputs and/or parameters have changed # ********************************************************************* def Generate_Output_Signals ( self, In, Out, Par, XIn, XOut, XPar ) : pass """
class t_MatPlot_2D( tLWB_Brick ): Description = _(0, """Shows the image at input[1]""") I = 5 def After_Init (self): self.Caption = 'MatPlot-2D' # Define the input pins # <Pin-Name>, <Data_Type>, <Required>, <Description> for i in range ( 1, self.I + 1 ) : self.Inputs [i] = ['Signal ' + str(i), TIO_ARRAY, (i==1) ] # we want this image-window to be centered self.Center = True # Create the GUI controls CD = self.Create_Control ( t_C_MatPlot ) def Generate_Output_Signals ( self, In, Out, Par, XIn, XOut, XPar ) : C = self.GUI_Controls [0] C.Calculate ()
def Prepare_Scope_Signals(self): self._Copy_Grid_2_Vars() count = self.Display_NChan #print 'PrepSS 1',self.Scope.Scope_Normal.Get_NCurve(),count h = 16 base = 60 # be sure there are enough data storages and labels while self.Scope.Scope_Normal.Get_NCurve() < count: self.Scope.Scope_Normal.Add_Channel() while len(self.Values_Value) < count + 2: i = len(self.Values_Value) - 2 name = wx.StaticText(self.Panel_Left, -1, '', (5, i * (h + 17) + 5 + base)) name.SetToolTip(_(1, 'Click to Select')) self.Values_Label.append(name) self.Values_ID.append(name.GetId()) name.Bind(wx.EVT_LEFT_DOWN, self._OnLabelClick) value = wx.StaticText(self.Panel_Left, -1, '', (5, i * (h + 17) + 2 + h + base)) value.SetToolTip(_(1, 'Click to Select')) value.SetFont(wx.FFont(h, wx.ROMAN)) self.Values_Value.append(value) self.Values_ID.append(value.GetId()) value.Bind(wx.EVT_LEFT_DOWN, self._OnLabelClick) # but not too many N = self.Scope.Scope_Normal.Get_NCurve() #print 'PrepSS 2',N,count if N > count + 1: nd = count + 1 - N del self.Scope.Scope_Normal.curves[nd:] for i in range(-nd): self.Values_Value[-i - 1].Destroy() self.Values_Label[-i - 1].Destroy() self.Top_Sizer.Remove(N - i - 1) self.Bottom_Sizer.Detach(N - i - 1) self.Top_Labels[-i - 1].Destroy() self.Bottom_Labels[-i - 1].Destroy() del self.Values_Value[nd:] del self.Values_Label[nd:] del self.Values_ID[2 * nd:] # Set and create (if necessary) the polylines for chan in range(count): self.Values_Label[chan + 2].SetForegroundColour( self.Scope.Signal_Color[chan]) self.Values_Label[chan + 2].SetLabel(self.Scope.Signal_Name[chan]) self.Values_Value[chan + 2].SetForegroundColour( self.Scope.Signal_Color[chan]) #self.Values_Value [chan].SetLabel ( '6.84') #self.signal_range = range ( self.Scope.Scope_Normal.Get_NCurve() ) ## ??self.Refresh_Value_Labels () self.Refresh_Value_Labels()
def __init__(self, *args, **kwargs): My_Control_Class.__init__(self, *args, **kwargs) ''' import copy import wx import wx.grid as gridlib from grid_support import * ''' data_values = [[ 'Name', 'On', 'NumOn', 'Lower', 'Upper', 'AC', 'AC[s]', 'Delay[s]', 'LineColor', 'LineWidth', 'World-1', 'Cal-1', 'World-2', 'Cal-2' ]] data_values_default = [ 'Signal i', False, True, -10, 10, False, 1, 0, (200, 0, 0), 2, 0, 0, 1, 1 ] for i in range(16): default = copy.copy(data_values_default) default[0] = ' Signal ' + str(i + 1) + ' [Volt]' A, B = 100, 255 if i < 3: default[1] = True default[8] = ((i * A) % B, ((i + 1) * A) % B, ((i + 2) * A) % B) data_values.append(default) #14*['']) #print data_values data_types = [ gridlib.GRID_VALUE_STRING, gridlib.GRID_VALUE_BOOL, gridlib.GRID_VALUE_BOOL, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_BOOL, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, MY_GRID_TYPE_COLOR, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER ] data_defs = (MY_GRID_ROW_FIXED, MY_GRID_COL_TYPED) Image_List = Get_Image_List() bmp_Pause = Image_List.GetBitmap(49) bmp_Run = Image_List.GetBitmap(50) bmp_Plus = Image_List.GetBitmap(56) bmp_Minus = Image_List.GetBitmap(57) bmp_Up = Image_List.GetBitmap(45) bmp_Down = Image_List.GetBitmap(44) bmp_Color = Image_List.GetBitmap(48) b_size = (22, 22) GUI = """ self.NB ,wx.Notebook ,style = wx.BK_LEFT self.Splitter ,SplitterHor ,name = 'Scope' ,style = wx.NO_BORDER self.Panel_Left ,wx.Panel B_Pause ,BmpBut ,bitmap = bmp_Pause ,pos = (2,2) ,size = b_size B_Run ,BmpBut ,bitmap = bmp_Run ,pos = (2,27) ,size = b_size B_Plus ,BmpBut ,bitmap = bmp_Plus ,pos = (27,2) ,size = b_size B_Minus ,BmpBut ,bitmap = bmp_Minus ,pos = (27,27) ,size = b_size B_Up ,BmpBut ,bitmap = bmp_Up ,pos = (52,2) ,size = b_size B_Down ,BmpBut ,bitmap = bmp_Down ,pos = (52,27) ,size = b_size B_Color ,BmpBut ,bitmap = bmp_Color ,pos = (77,2) ,size = b_size self.Sel_Signal ,wx.StaticText, label = '--', pos = ( 77, 27 ) self.BG ,wx.StaticText ,label = _(0, 'BackGround') ,pos = (2, 52) self.GR ,wx.StaticText ,label = _(0, 'Grid') ,pos = (70, 52) self.Panel_Right ,wx.Panel self.Scope ,tBase_Scope_with_History ,Real_Time = True self.grid ,Base_Table_Grid ,data_values, data_types, data_defs, name='Settings' """ self.wxGUI = Create_wxGUI(GUI, my_parent='self.Dock') self.Panel_Left.SetBackgroundColour(wx.BLACK) B_Pause.SetToolTip(_(0, 'Pause Recording')) B_Run.SetToolTip(_(0, 'Start Recording')) B_Plus.SetToolTip(_(0, 'Increase selected signal Amplitude')) B_Minus.SetToolTip(_(0, 'Decrease selected signal Amplitude')) B_Up.SetToolTip(_(0, 'Shift selected signal Up')) B_Down.SetToolTip(_(0, 'Shift selected signal Down')) B_Color.SetToolTip(_(0, 'Set Color of selected signal')) self.Button_IDs = [] self.Button_IDs.append(B_Pause.GetId()) self.Button_IDs.append(B_Run.GetId()) self.Button_IDs.append(B_Plus.GetId()) self.Button_IDs.append(B_Minus.GetId()) self.Button_IDs.append(B_Up.GetId()) self.Button_IDs.append(B_Down.GetId()) self.Button_IDs.append(B_Color.GetId()) self.Sel_Signal.SetForegroundColour(wx.WHITE) self.Sel_Signal.SetToolTip(_(0, 'Selected Signal')) self.BG.SetForegroundColour(wx.WHITE) self.BG.Bind(wx.EVT_LEFT_DOWN, self._OnLabelClick) self.GR.SetForegroundColour(wx.RED) self.GR.Bind(wx.EVT_LEFT_DOWN, self._OnLabelClick) Set_NoteBook_Images(self.NB, (47, 76)) wx.CallLater(wxGUI_Delay, self.Splitter.SetSashPosition, 102) self.New_Data = False self.Ny = 100 # 200 self.Nx = 600 # gives 10 divisions self.Display_NChan = 0 self.Values_Value = [0, 0] self.Values_Label = [self.BG, self.GR] self.Values_ID = [self.BG.GetId(), self.GR.GetId()] self.Selected_Signal = None self.Num_Value_Timer = wx.Timer(self.Dock) # reload previous settings #if self.Test : if self.Ini: self.Ini.Section = self.IniSection self.Load_Settings(self.Ini) #self.Dock.Bind ( wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged ) self.Dock.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self._OnPageChanging) self.Dock.Bind(wx.EVT_CLOSE, self._OnCloseWindow) self.Dock.Bind(wx.EVT_TIMER, self._OnTimer, self.Num_Value_Timer) self.Dock.Bind(wx.EVT_BUTTON, self._OnButtonClick) self.Scope.Parent_Notify_Chan_Params = self.Notify_Chan_Params self.Prepare_Scope_Signals() self.Num_Value_Timer.Start(500) # for testpurposes self.Timer_Test = None # NOTEBOOK resizes wrong, # too much space for tabs, # this will correct it wx.CallAfter(self.NB.SendSizeEvent)
def __init__(self, inifile=None): # Create the Main_Window # Main_Form # |____ Splitter # |____ Panel_Left # | |____ Button_1 # | |____ Slider # | # |____ Shape_Container # |____ Shape # # ************************************************************* wx.Frame.__init__(self, None, -1, PG.Program_Name + ' (V ' + PG.Version_Nr + ') no active project ', pos=(0, 0), size=(800, 600)) self.closed = False #self.inifile = inifile self.Modal_Open = False self.Custom_Colors = [] self._printData = wx.PrintData() # ************************************************************* # Define the base menu structure # ************************************************************* menus = [[ '&File', [('&New/Open\tCtrl+O', 'Open'), ('&Save\tCtrl+S', 'Save'), ('Save &As ...', 'Save_As'), ('-'), ('&Print\tCtrl+P', 'Print'), ('Pr&int Preview', 'Print_Preview'), ('Page Setup', 'Page_Setup'), ('-'), ('&Export', 'Export'), ('-'), ('&Close', 'Close')] ], ['&Edit', [('&ToDo', 'ToDo'), ('&Edit', 'Edit')]], ['&Settings', [('&ToDo', 'ToDo'), ('&Test', 'Test')]], ['&View', [('&Hor Layout', 'Dir_Layout'), ('&View', 'View')]], [ '&Help', [('PyLab_&Works', 'Prog_Help'), ('&Python', 'Python_Help'), ('-'), ('&Check For New Version', 'Check_New_Version'), ('Send &Bug Report', 'Send_Bug_Report'), ('Ask &OnLine Assistance', 'Ask_Assistance'), ('&About', 'About')] ]] # Add a dynamic menu to the menubar menu_dynamic_items = [] for i in range(10): menu_dynamic_items.append(('Demo ' + str(i), 'Demo' + str(i))) menus.insert(1, ['Demos', menu_dynamic_items]) # Create the menu My_Menus = Class_Menus(self, My_Menus=menus) # Bind events, for the dymanic menu-items, through the whole range self.Bind(wx.EVT_MENU, self.OnMenu_Demos, id=self.ID_Demo0, id2=self.ID_Demo9) self.Bind(wx.EVT_MENU, self.OnMenu_Dir_Layout, id=self.ID_Dir_Layout) self.Bind(wx.EVT_MENU, self.OnMenu_Test, id=self.ID_Test) # ************************************************************* self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.Bind(wx.EVT_SIZE, self.OnResize) #self.Bind(wx.EVT_IDLE, self.OnIdle) #self.SetIcon(wx.Icon('ph_32.ico',wx.BITMAP_TYPE_ICO)) Path = sys._getframe().f_code.co_filename Path = os.path.split(Path)[0] self.SetIcon( wx.Icon(Joined_Paths(Path, '../pictures/vippi_bricks_323.ico'), wx.BITMAP_TYPE_ICO)) self.StatusBar = self.CreateStatusBar() self.StatusBar.SetFieldsCount(3) self.StatusBar.SetStatusWidths([-2, -1, -2]) self.StatusBar.SetStatusText(' Edit', 0) self.StatusBar.SetStatusText(' aap', 2) # ************************************************************* # ************************************************************* # first splitter # ************************************************************* self.Splitter = wx.SplitterWindow(self, 11, style=wx.SP_LIVE_UPDATE) self.Splitter_Left = \ wx.SplitterWindow ( self.Splitter, 11, style = wx.SP_LIVE_UPDATE) #self.Tree = MyCustomTreeCtrl (self.Splitter, self,'TREE ROOT') self.Shape_Container = tPyLabWorks_ShapeCanvas(self.Splitter, self, pos=(0, 0), size=(500, 500)) self.Splitter.SetMinimumPaneSize(20) #self.Splitter.SplitVertically( self.Tree, self.Shape_Container, -400) self.Splitter.SplitVertically(self.Splitter_Left, self.Shape_Container, -400) # ************************************************************* Panel_Left = wx.Window(self.Splitter_Left, style=wx.BORDER_SUNKEN) Panel_Left.SetBackgroundColour(PG.General_BackGround_Color) self.Tree = MyCustomTreeCtrl(self.Splitter_Left, self, 'TREE ROOT') self.Splitter_Left.SetMinimumPaneSize(20) self.Splitter_Left.SplitHorizontally(Panel_Left, self.Tree, 26) # ************************************************************* # buttons for simulation control, start at halt # ************************************************************* bw = 50 bh = 22 self.B_Edit = wx.ToggleButton(Panel_Left, wx.ID_ANY, "Edit", pos=(0 * bw, 0), size=(bw, bh)) PG.SS_Edit = self.B_Edit.GetId() self.B_Run = wx.ToggleButton(Panel_Left, wx.ID_ANY, "Run-F9", pos=(1 * bw, 0), size=(bw, bh)) PG.SS_Run = self.B_Run.GetId() self.B_Step = wx.ToggleButton(Panel_Left, wx.ID_ANY, "Step-F5", pos=(2 * bw, 0), size=(bw, bh)) PG.SS_Step = self.B_Step.GetId() PG.SS_Stop = PG.SS_Step + 20 self.B_HighLight = wx.ToggleButton(Panel_Left, wx.ID_ANY, "HighLight", pos=(3 * bw, 0), size=(bw, bh)) PG.SS_HighLight = self.B_HighLight.GetId() Panel_Left.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle_B, self.B_Edit) Panel_Left.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle_B, self.B_Run) Panel_Left.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle_B, self.B_Step) Panel_Left.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle_HighLight, self.B_HighLight) # Accelerators, these tools are not visisble # but we need them for the accelerator shortcut Panel_Left.Bind(wx.EVT_TOOL, self.OnToggle_B, self.B_Step) Panel_Left.Bind(wx.EVT_TOOL, self.OnToggle_B, self.B_Run) aTable = wx.AcceleratorTable([\ ( wx.ACCEL_NORMAL, wx.WXK_F5, PG.SS_Step ), ( wx.ACCEL_NORMAL, wx.WXK_F9, PG.SS_Run ) ]) Panel_Left.SetAcceleratorTable(aTable) # ************************************************************* drop_target = MyDropTarget(self.Shape_Container) self.Shape_Container.SetDropTarget(drop_target) # Finally show the mainform ##if not (PG.Standalone) : if Application.Design_Mode: self.Show() #self.t1 = wx.Timer(self.Shape_Container) # the third parameter is essential to allow other timers #self.Shape_Container.Bind(wx.EVT_TIMER, self.OnTimer, self.t1) #self.t1.Start(4000) self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSplitter) #self.Bind ( wx.EVT_SIZE, self.OnResize ) #from JALsPy_netlist_form import EVT_JALSPY_NETLIST_WATCHES_CHANGED PG.State = PG.SS_Edit PG.Execution_HighLight = False #True self.B_HighLight.SetValue(PG.Execution_HighLight) self.Update_Buttons() # ************************************************************* # popup menus # ************************************************************* self.Popup_Menu_Tree = My_Popup_Menu( self.OnPopupItemSelected, 1, pre=[_(0, 'Set Active Project'), _(0, 'Insert New')]) #self.Tree.Bind ( wx.EVT_CONTEXT_MENU, self.OnShowPopup ) #self.Tree.Bind ( wx.EVT_RIGHT_UP, self.OnShowPopup ) self.Tree.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnShowPopup2)
class t_Code_Editor ( tLWB_Brick ): Description = _(9, """Scintilla Code Editor. Can be used to test small pieces of Python code, or to make something like a graphical calculator. This Brick contains a number of input and output nodes, so it can communicate with other Bricks, through the variables IN[] and OUT[]. The last output just outputs the whole code as a string.""" ) def After_Init (self): self.Caption = 'Code Editor' # Define the output pins # <Pin-Name>, <Data_Type>, <Description> self.Outputs [1] = [ 'Code', TIO_STRING, 'Contains Selected Code, All Code' ] self.Outputs [2] = [ 'CMD Shell', TIO_INTERACTION, 'Communication with CMD-Shell' ] self.Outputs [3] = [ 'Data Array', TIO_ARRAY, """ When Input[1] is not connected, code will be executed and Array Data will be connected this Output[3].""" ] # Create the GUI controls # ************************************************* # Create the Scintilla editor # Parameters # 1 = output, ( <complete code>, <selected code> ) # 2 = IO_Interaction # FileName = output, the loaded code file # CMD Shell = input, the local Help Browser CD = self.Create_Control ( t_C_Code_Editor ) # ************************************************* # Create a separate Namespace for the code in the editor self.Code_Globals = {'aap':33} self.Code_Locals = {} # For TIO_INTERACTION create an empty dictionary #self.Params [0] = TIO_Dict () #{} print ('*********************&&&&&&&&&&&&') # ********************************************************************* # Procedure only called when inputs and/or parameters have changed # ********************************************************************* def Generate_Output_Signals ( self, In, Out, Par, XIn, XOut, XPar ) : #print 'CodeEditor-EXEC', Par,XIn,XOut,XPar # ******************************************* # Test Loading of new code file # ******************************************* if XOut [2] : if 'CodeFile_To_Open' in XOut[2] : FileName = Out [2] ['CodeFile_To_Open'] self.GUI_Controls [0].STC.Change_File ( FileName ) # ******************************************* # Test Loading of new code file # ******************************************* if XPar [1] : Out [1] = Par [1] # ******************************************* # If Output[1] is connected, # we don't execute the code, # but leave that task to the receiver # ******************************************* Code = self.Par[1] if Out.Receivers[1] or not ( Code ): return if not ( isinstance ( Code, str ) ) : Code = Code [0] """ Error in Simulation File YYYY <type 'unicode'> x = arange ( 0.0, 3.0, 0.01 ) y = 15*cos ( IN1 * pi * x ) y2 = 10*sin ( IN2 * pi * x ) OUT1 = x,y,y2,\ ('cosine', 'sine') """ # only \n is allowed !! (see "compile") Code = Code.replace('\r\n','\n') # remove line continuation, not accepted by exec-statement Code = Code.replace('\\\n','') # and last line must end with \n (see "compile") Code = Code + '\n' #for i in range ( 1, 3 ) : # Code = Code.replace('OUT'+str(i),'self.Output_Value['+str(i)+']') Code = Code.replace ( 'OUT1', 'self.Out[3]' ) try : exec ( Code ) #, self.Code_Globals, self.Code_Locals ) #self.Output_Changed[1] = True except : import traceback traceback.print_exc () print ('******** Code Editor, ERROR: *********') print (Code)
def __init__(self, parent, Brick, Ini, Title='Edit Values Below', Help=''): #import _images wx.Panel.__init__(self, parent) self.parent = parent # watch out: section not set, therfor don't make it a self-var if Ini: Ini.Section = 'Device ' + Brick.Name # counter for none value. to force a parameter change self.None_Counter = 0 self.y = 5 #w, h = self.GetClientSize() #GetSize() w = self.GetClientSize()[0] w = w - 10 ##self.GUI_Controls_Weg = [] self.GUI_Controls = [] self.Brick = Brick #for self.i, self.C in enumerate ( Brick.Control_Defs ) : self.x = 0 for self.i, Brick_CD in enumerate(self.Brick.Control_Defs): #self.x = 0 #10 self.CD = Brick_CD # ******************************************************** # Create the control # ******************************************************** #print '*********** AAAA', Brick.Name, Brick.Caption, Brick_CD.Type #print Control_Classes #if Brick_CD.Type in Control_Classes and \ #if not (isinstance ( Brick_CD.Type, int ) ) and \ # issubclass ( Brick_CD.Type, My_Control_Class ) : #print 'UIOYPKL',self.Brick.Name, self.Brick.Control_Defs,Brick_CD Control = Brick_CD.Type(self, self.Brick, Brick_CD, Ini) #self.y += Control.GetSize()[1] #self.y += Control.Y w = Control.GetSize()[0] if Brick_CD.NewLine or (w <= 0): self.x = 0 self.y += Control.GetSize()[1] + 3 else: self.x += w + 3 Brick_CD.GUI_Control = Control self.GUI_Controls.append(Control) if 'Hint' in dir(Brick_CD): Control.SetToolTip(Brick_CD.Hint) odd = self.i % 2 if odd: ## and ( 'SetForegroundColour' in dir ( Control ) ) : Control.SetForegroundColour(AC) """ Maybe these have to be added Control_Pars [ 'X-Pos' ] = self.x Control_Pars [ 'Y-Pos' ] = self.y Control_Pars [ 'Height' ] = -1 """ # ******************************************************** # Call Bricks completions # ******************************************************** self.Brick.After_Control_Create() # ******************************************************** # Diagnostic Information # ******************************************************** if self.Brick.Diagnostic_Mode: line = '-- Set_Control_Params --' + '\n' ##line += ' Input_Index = ' + str ( self.C.Input_Channel ) + '\n' line += ' Input_Index = ' + str( Brick_CD.Input_Channel) + '\n' #Control_Pars [ 'Control_Index'] = self.i + '\n' line += ' X / Y = ' + str( Control.X_Pos) + ' / ' + str(Control.Y_Pos) + '\n' line += ' Scalable = ' + str(Control.Scalable) + '\n' line += ' Save_Settings = ' + str( Control.Save_Settings) + '\n' line += ' Load_Settings = ' + str( Control.Load_Settings) + '\n' line += ' GetValue = ' + str(Control.GetValue) + '\n' line += ' SetValue = ' + str(Control.SetValue) + '\n' if 'Calculate' in dir(Control): line += ' Calculate = ' + str( Control.Calculate) + '\n' if 'Add_Data' in dir(Control): line += ' Add_Data = ' + str( Control.Add_Data) + '\n' if 'Kill' in dir(Control): line += ' Kill = ' + str(Control.Kill) + '\n' if 'Hint' in dir(Control): line += ' Hint = ' + str(Brick_CD.Hint) + '\n' line += '\n' #PG.wbd ( self.Brick, line ) #line = '' line += _(0, 'Creating Control\n') for item in Control_Pars: s = str(Control_Pars[item]) if len(s) > 60: s = s[:60] line += ' ' + item + ' = ' + s line += '\n' # Here test some function call evaluations line += '\n' line += _(0, 'Function Evaluation: \n') item = 'Control_GetValue' if item in Control_Pars and Control_Pars[item] != None: line += ' ' + item + ' = ' + str(Control_Pars[item]()) line += '\n' PG.wbd(self.Brick, line) if Brick.Main_Description: self.SetToolTip(Brick.Description) # For an easy access of the Controls from within the Brick Brick.GUI_Controls = self.GUI_Controls
def Generate_HTML_Library_Overview(lang='US', Technical_Info=False): ##from brick import Control_Names #Technical_Info = False Set_Language(lang) print('PITY') # *********************************************************************** # *********************************************************************** HTML_Frame_1 = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>GUI Controls</title> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- body { margin: 5px 5px 5px 5px; background-color: #ffffd4; ) } --></style> <link type="text/css" href="rvf.css" rel="stylesheet"> <body> <p><span class=rvts1>""" + _(1, 'Library Overview') + """ </span> <img width=32 height=32 alt="" src="vippi_bricks_323.png"></p> <p>""" + _(13, 'Generated on') HTML_Frame_2 = """</p> <p>""" + _(2, """This Library overview is automatically generated by Pylab_Works, from the local available source files.""") + """</p> <p><br></p> <hr noshade size=1> <p><span class=rvts2>"""+ _(3, 'Library Files') + '</span> ' +\ _(4, '(available languages)') + '</p>' HTML_Frame_3 = """<p><br></p> <p><span class=rvts2>""" HTML_Frame_5 = """<p><br></p> <p><span class=rvts2>""" HTML_Frame_99 = '</body></html>' # *********************************************************************** file = open ( 'd:/data_www/pylab_works/pw_lib_overview_'+\ lang.lower()+'.html', 'w') import datetime line = HTML_Frame_1 + ' ' + str(datetime.date.today()) +\ ', ' + _(5, 'language') + ' = ' + lang if Technical_Info: line += ', ' + _(6, 'switches') + ' = Technical' file.write(line) # List of Library Files ( and available translations ) file.write(HTML_Frame_2) Libraries = Get_PyLabWorks_Bricks_All_Dict() lib_list = sorted(Libraries.keys()) from language_support import Language_IDs for Lib in lib_list: line = '<p> ' + Lib +\ ' ( US, ' for Language in Language_IDs: #code = 'lang.' + Lib + '_' + Language code = Lib + '_' + Language try: #print '******** 222',line exec('from ' + code + ' import LT') line += Language + ', ' except: pass #print 'File not found:',code # remove the last comma line = line[:-2] line += ' )</p>\n' file.write(line) if Technical_Info: # List of IO_Types file.write('<p><br></p>') line = '<hr noshade size=1> <p><span class=rvts2>' +\ _(7, 'IO-Types') + '</span></p>' file.write(line) file.write( '<p>Number must still be changed to real type "TIO_NUMBER" ' + '</p>') for IO_type in TIO_NAMES: line = str(IO_type) + ' : ' + TIO_NAMES[IO_type] file.write('<p> ' + line + '</p>') # List of Controls file.write('<p><br></p>') line = '<hr noshade size=1> <p><span class=rvts2>' +\ _(8, 'GUI Controls') + '</span></p>' file.write(line) file.write('<p> - Still to Implement' + '</p>') for Lib in lib_list: file.write(HTML_Frame_3 + '<hr noshade size=1>' + Lib + '</span></p>') exec('import ' + Lib) # display the latest version + date try: version_line = eval(Lib + '._Version_Text') if not (Technical_Info): file.write('<p>' + _(0, 'version: ') + str(version_line[0][0]) + ' ' + _(0, 'date: ') + version_line[0][1] + '</p>') except: file.write('<p>' + _(0, 'version unknown') + '</p>') version_line = None # find the description for the library as a whole try: line = eval(Lib + '.Description') file.write('<p>' + line + '</p>') #print LIB + ' : ' + line except: pass if Technical_Info: # find the ICON-file of the library try: line = eval(Lib + '.Library_Icon') file.write('<p> Icon = ' + line + '</p>') except: pass # find the Brick color of the library try: line = eval(Lib + '.Library_Color') file.write('<p> Color = ' + str(line) + '</p>') except: #print 'lkop',line pass # display the history information if Technical_Info and version_line: try: for version in version_line: file.write('<br>') #file.write ( '<p><span class=rvts3>' + _(9, 'Inputs' ) + ' : </span></p>' ) file.write('<p><span class=rvts3>' + _(0, 'version: ') + str(version[0]) + '</span>' + ' ' + _(0, 'date: ') + version[1] + ' ' + _(0, 'author: ') + version[2] + '</p>') # test conditions header = '<p>' + _(0, 'Test Conditions:') + '</p>' for TC in version[4]: if header: file.write(header) header = None file.write('<p> ' + Test_Conditions[TC] + '</p>') line = version[5].lstrip().replace('\n', '<br>') file.write('<p>' + line + ' </p>') except: pass # display the technical description if Technical_Info: try: line = eval(Lib + '.__doc__') if line: file.write('<br><p><span class=rvts3>' + _(0, 'Technical Description') + '</span></p>') line = line.lstrip().replace('\n', '<br>') file.write('<p>' + line + ' </p>') except: pass # Display the Bricks for Brick in Libraries[Lib]: file.write(HTML_Frame_5 + Brick + '</span></p>\n') line = eval(Lib + '.t_' + Brick + '.Description') file.write('<p>' + line + '</p>') #file.write ( '<p><br></p>' ) if Technical_Info: # now create the brick, to evaluate IO's line = 'Brick = ' + Lib + '.t_' + Brick + '( None )' exec(line) exec('Inputs = Brick.Inputs') header = False for S in Inputs: if not (header): file.write('<p><span class=rvts3>' + _(9, 'Inputs') + ' : </span></p>') header = True # Name, type, required, helptext Input = Inputs[S] line = Input[0] if Input[3] != '': line += ', (' + Input[3] + ')' line += ', type = ' + TIO_NAMES[Input[1]] if Input[2]: line += ', Required' file.write('<p> - ' + line + '</p>') exec('Outputs = Brick.Outputs') header = False for S in Outputs: if not (header): file.write('<p><span class=rvts3>' + _(10, 'Outputs') + ' : </span></p>') header = True # Name, type, required, helptext Output = Outputs[S] line = Output[0] if (len(Output) > 2) and (Output[2] != ''): line += ', (' + Output[2] + ')' line += ', ' + TIO_NAMES[Output[1]] file.write('<p> - ' + line + '</p>') exec('Controls = Brick.Control_Defs') header = False for S in Controls: if not (header): file.write('<p><span class=rvts3>' + _(11, 'GUI Controls') + ' : </span></p>') header = True # Name, type, required, helptext ##line = Control_Names [ S ['Type'] ] line = 'UUUUUUUU', ##Control_Names [ S.Type ] #line = str ( S ['Type'] ) file.write('<p> - ' + line + '</p>') #file.write ( '<p><span class=rvts3>Parameters : </span></p>' ) methods = ['Generate_Output_Signals'] header = False for line in methods: exec('result = "' + line + '" in dir ( Brick ) ') if result: if not (header): file.write('<p><span class=rvts3>' + _(12, 'Methods') + ' : </span></p>') header = True file.write('<p> - ' + line + '</p>') file.write(HTML_Frame_99) file.close()
def Prepare_Scope_Signals(self): self._Copy_Grid_2_Vars() count = len(self.Scope_Signal_Names) h = 16 base = 60 name = wx.StaticText(self.Panel_Left, -1, _(0, 'BackGround/Grid'), (5, base - 8)) name.SetForegroundColour(wx.WHITE) name.Bind(wx.EVT_LEFT_DOWN, self.OnLabelClick) # be sure there are enough data storages and labels while self.Scope_Canvas.Get_NCurve() < count: i = len(self.Values) self.Scope_Canvas.Add_Channel() name = wx.StaticText(self.Panel_Left, -1, '', (5, i * (h + 17) + 5 + base)) name.SetToolTipString(_(1, 'Click to Select')) self.Values_Labels.append(name) self.Values_IDs.append(name.GetId()) name.Bind(wx.EVT_LEFT_DOWN, self.OnLabelClick) value = wx.StaticText(self.Panel_Left, -1, '', (5, i * (h + 17) + 2 + h + base)) value.SetToolTipString(_(1, 'Click to Select')) value.SetFont(wx.FFont(h, wx.ROMAN)) self.Values.append(value) self.Values_IDs.append(value.GetId()) value.Bind(wx.EVT_LEFT_DOWN, self.OnLabelClick) # Create top and bottom labels label = wx.StaticText(self.Panel_Top, -1, 'S' + str(i)) label.SetToolTipString(_(2, 'Click to Set Margins')) label.Bind(wx.EVT_LEFT_DOWN, self._OnLabel_Top_Click) self.Top_Labels.append(label) self.Labels_IDs.append(label.GetId()) self.Top_Sizer.Add(label, 1, wx.EXPAND) label = wx.StaticText(self.Panel_Bottom, -1, 'S' + str(i)) label.SetToolTipString(_(2, 'Click to Set Margins')) label.Bind(wx.EVT_LEFT_DOWN, self._OnLabel_Top_Click) self.Bottom_Labels.append(label) self.Labels_IDs.append(label.GetId()) self.Bottom_Sizer.Add(label, 1, wx.EXPAND) # but not too many N = self.Scope_Canvas.Get_NCurve() if N > count: nd = count - N del self.Scope_Canvas.curves[nd:] for i in range(-nd): self.Values[-i - 1].Destroy() self.Values_Labels[-i - 1].Destroy() self.Top_Sizer.Remove(N - i - 1) self.Bottom_Sizer.Detach(N - i - 1) self.Top_Labels[-i - 1].Destroy() self.Bottom_Labels[-i - 1].Destroy() del self.Values[nd:] del self.Values_Labels[nd:] del self.Top_Labels[nd:] del self.Bottom_Labels[nd:] del self.Values_IDs[2 * nd:] del self.Labels_IDs[2 * nd:] # Set and create (if necessary) the polylines #print 'TOP',self.Top_Labels #print 'NUM',self.Values for chan in range(count): self.Values_Labels[chan].SetForegroundColour( self.Scope_Signal_Color[chan]) self.Values_Labels[chan].SetLabel(self.Scope_Signal_Names[chan]) self.Top_Labels[chan].SetForegroundColour( self.Scope_Signal_Color[chan]) self.Top_Labels[chan].SetBackgroundColour( self.Scope_Canvas.Brush.GetColour()) self.Bottom_Labels[chan].SetForegroundColour( self.Scope_Signal_Color[chan]) self.Bottom_Labels[chan].SetBackgroundColour( self.Scope_Canvas.Brush.GetColour()) self._Update_Border_Labels(chan) self.Values[chan].SetForegroundColour( self.Scope_Signal_Color[chan]) self._Update_Channel(chan) #print 'HIST',self.Scope_History.Get_NCurve(), #print self.Scope_Signal_Gain [0], #print self.Scope_Signal_Offset [0] if count > 0: self.Scope_History.Set_Channel(self.Scope_Signal_Color[0]) #self.signal_range = range ( self.Scope_Canvas.Get_NCurve() ) self.Refresh_Value_Labels() self.Panel_Top.SendSizeEvent() self.Panel_Bottom.SendSizeEvent()
def __init__(self, *args, **kwargs): My_Control_Class.__init__(self, *args, **kwargs) print('piep1') # to prevent maximizing of the form, this doesn't work perfect !! # Maybe it's better to use another window instead of the miniframe. self.Dock.SetSizeHints(100, 100, maxH=1050, maxW=1680) # Be sure to make it large enough self.NB = wx.Notebook(self.Dock, -1, size=(2000, 1200), style=wx.BK_LEFT) # ***************************************************************** # make an image list (needed for notebook) # ***************************************************************** Set_NoteBook_Images(self.NB, (47, 76)) # ***************************************************************** # create the notebook tabs and put images on the tabs # ***************************************************************** p1 = wx.Panel(self.NB) self.NB.AddPage(p1, "Scope", imageId=il1) #self.panel_2 = wx.Panel ( NB ) #NB.AddPage ( self.panel_2, "Setting", imageId=il2 ) # ***************************************************************** self.Splitter = wx.SplitterWindow(p1, style=wx.SP_LIVE_UPDATE) self.Panel_Left = wx.Panel(self.Splitter, style=wx.BORDER_SUNKEN) self.Panel_Left.SetBackgroundColour(wx.BLACK) #self.Panel_Right = wx.Panel ( self.Splitter, style = wx.BORDER_SUNKEN ) self.Splitter_Plots = wx.SplitterWindow(self.Splitter, style=wx.SP_LIVE_UPDATE) self.Splitter.SplitVertically(self.Panel_Left, self.Splitter_Plots, 105) self.Splitter.SetMinimumPaneSize(20) # ***************************************************************** box = wx.BoxSizer(wx.HORIZONTAL) box.Add(self.Splitter, 1, wx.EXPAND) self.Dock.SetSizer(box) # ***************************************************************** # ***************************************************************** self.Panel_Right = wx.Panel(self.Splitter_Plots, style=wx.BORDER_SUNKEN) self.Scope_History = _PlotCanvas_History(self.Splitter_Plots, self, True) self.Splitter_Plots.SplitHorizontally(self.Panel_Right, self.Scope_History, 105) self.Splitter_Plots.SetMinimumPaneSize(20) # ***************************************************************** box = wx.BoxSizer(wx.VERTICAL) box.Add(self.Splitter_Plots, 1, wx.EXPAND) self.Splitter.SetSizer(box) # ***************************************************************** print('piep1') self.Panel_Top = wx.Panel(self.Panel_Right, style=wx.NO_BORDER) self.Panel_Bottom = wx.Panel(self.Panel_Right, style=wx.NO_BORDER) self.Scope_Canvas = _PlotCanvas(self.Panel_Right, self) Sizer = wx.BoxSizer(wx.VERTICAL) self.Panel_Right.SetSizer(Sizer) Sizer.Add(self.Panel_Top, 0, wx.EXPAND) Sizer.Add(self.Scope_Canvas, 1, wx.EXPAND) Sizer.Add(self.Panel_Bottom, 0, wx.EXPAND) #self.Panel_Top.SetBackgroundColour ( self.Scope_Canvas.Brush.GetColour () ) #self.Panel_Bottom.SetBackgroundColour ( self.Scope_Canvas.Brush.GetColour () ) self.Top_Sizer = wx.BoxSizer(wx.HORIZONTAL) self.Panel_Top.SetSizer(self.Top_Sizer) self.Bottom_Sizer = wx.BoxSizer(wx.HORIZONTAL) self.Panel_Bottom.SetSizer(self.Bottom_Sizer) data_values = [[ 'Name', 'On', 'NumOn', 'Lower', 'Upper', 'AC', 'AC[s]', 'Delay[s]', 'LineColor', 'LineWidth', 'World-1', 'Cal-1', 'World-2', 'Cal-2' ]] data_values_default = [ 'Signal i', False, True, -10, 10, False, 1, 0, (200, 0, 0), 2, 0, 0, 1, 1 ] for i in range(16): default = copy.copy(data_values_default) default[0] = ' Signal ' + str(i + 1) + ' [Volt]' A, B = 100, 255 if i < 3: default[1] = True default[8] = ((i * A) % B, ((i + 1) * A) % B, ((i + 2) * A) % B) data_values.append(default) #14*['']) #print data_values data_types = [ gridlib.GRID_VALUE_STRING, gridlib.GRID_VALUE_BOOL, gridlib.GRID_VALUE_BOOL, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_BOOL, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, MY_GRID_TYPE_COLOR, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER, gridlib.GRID_VALUE_NUMBER ] data_defs = (MY_GRID_ROW_FIXED, MY_GRID_COL_TYPED) # Frame, Device, Parent self.Grid = Base_Table_Grid( self.NB, None, data_values, data_types, data_defs, None, #Program_Custom_Colors, None, #self.Set_Modal_Open, None #self.Notify_Params_Changed ) # ***************************************************************** # we don't use a boxer sizer here, it's done in pagechange # otherwise it won't work in an AUI pane !! self.NB.AddPage(self.Grid, "Setting", imageId=il2) #box = wx.BoxSizer ( wx.VERTICAL ) #box.Add ( self.Grid, 1, wx.GROW | wx.ALL, 0 ) #self.panel_2.SetSizer ( box ) # ***************************************************************** print('piep3') """ color_bg = wx.Color( 249, 249, 217 ) gc = 200 self.Scope_Canvas.Set_Canvas ( color_bg, wx.Color( gc, gc, gc ) ) self.Scope_History.Set_Canvas ( color_bg ) """ # ***************************************************************** # Create some fast control buttons # ***************************************************************** x = 2 w = 25 bmp = Get_Image_16('control_pause_blue.png') button = wx.BitmapButton(self.Panel_Left, -1, bmp, pos=(x, x)) button.SetToolTipString(_(0, 'Pause Recording')) self.buttons_ID = button.GetId() bmp = Get_Image_16('control_play_blue.png') button = wx.BitmapButton(self.Panel_Left, -1, bmp, pos=(x, x + w)) button.SetToolTipString(_(0, 'Start Recording')) bmp = Get_Image_16('list-add.png') button = wx.BitmapButton(self.Panel_Left, -1, bmp, pos=(x + w, x)) button.SetToolTipString(_(0, 'Increase selected signal Amplitude')) bmp = Get_Image_16('list-remove.png') button = wx.BitmapButton(self.Panel_Left, -1, bmp, pos=(x + w, x + w)) button.SetToolTipString(_(0, 'Decrease selected signal Amplitude')) bmp = Get_Image_16('arrow_up.png') button = wx.BitmapButton(self.Panel_Left, -1, bmp, pos=(x + 2 * w, x)) button.SetToolTipString(_(0, 'Shift selected signal Up')) bmp = Get_Image_16('arrow_down.png') button = wx.BitmapButton(self.Panel_Left, -1, bmp, pos=(x + 2 * w, x + w)) button.SetToolTipString(_(0, 'Shift selected signal Down')) bmp = Get_Image_16('color_wheel.png') button = wx.BitmapButton(self.Panel_Left, -1, bmp, pos=(x + 3 * w, x)) button.SetToolTipString(_(0, 'Set Color of selected signal')) self.Selected_Signalname = wx.StaticText(self.Panel_Left, -1, '--', (x + 3 * w, x + w + 5)) self.Selected_Signalname.SetForegroundColour(wx.WHITE) self.Selected_Signalname.SetToolTipString(_(0, 'Selected Signal')) self.New_Data = False self.Ny = 100 # 200 self.Nx = 600 # gives 10 divisions self.Values = [] self.Values_Labels = [] self.Values_IDs = [] self.Top_Labels = [] self.Bottom_Labels = [] self.Labels_IDs = [] self.Selected_Signal = None self.Scope_Signal_Names = [] self.Scope_Signal_Gain = [] self.Scope_Signal_Offset = [] self.Scope_Delay_Len = [] self.Scope_Top = [] self.Scope_Bottom = [] self.Scope_Signal_Color = [] self.My_Signals = [] self.timer = wx.Timer(self.TopFrame) self.sub_timer = 0 # reload previous settings #if self.Test : self.Ini.Section = self.IniSection self.Load_Settings(self.Ini) #Frame.Bind ( wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged ) #Frame.Bind ( wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging ) #Frame.Bind ( wx.EVT_CLOSE, self._OnCloseWindow ) #Frame.Bind ( wx.EVT_TIMER, self.OnTimer, self.timer) #Frame.Bind ( wx.EVT_BUTTON, self.OnButtonClick ) #Frame.Bind ( wx.EVT_SIZE, self._OnSize ) self.Dock.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged) self.Dock.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging) self.Dock.Bind(wx.EVT_CLOSE, self._OnCloseWindow) self.Dock.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.Dock.Bind(wx.EVT_BUTTON, self.OnButtonClick) self.Dock.Bind(wx.EVT_SIZE, self._OnSize) self.Splitter_Plots.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self._OnSize) # ***************************************************************** # History Trace # ***************************************************************** #timebase_bufmax = zeros ( MAX_SCREEN_WIDTH ) #timebase_bufmin = zeros ( MAX_SCREEN_WIDTH ) #timebase_p = 0 # ***************************************************************** print('piep4') #self.Dock.SendSizeEvent () self.Prepare_Scope_Signals() # Doking in AUI panel, doesn't generate an OnShowEvent if self.Test: self.Dock.Bind(wx.EVT_SHOW, self._OnShowWindow) else: self.timer.Start(100) print('piep5')
class t_BTC ( tLWB_Brick ): Description = _(20, """Scintilla Code Editor. Can be used to test small pieces of Python code, or to make something like a graphical calculator. This Brick contains a number of input and output nodes, so it can communicate with other Bricks, through the variables IN[] and OUT[]""" ) def After_Init (self): self.Caption =_(0, 'BTC Sound' ) # Define the input pins # <Pin-Name>, <Data_Type>, <Required>, <Description> self.Inputs [1] = ['Input Stream', TIO_ARRAY, True ] # Define the output pins # <Pin-Name>, <Data_Type>, <Description> self.Outputs [1] = ['Output_Stream', TIO_ARRAY ] # Create the GUI controls CD = self.Create_Control ( t_C_Text_Control, 'Btc' ) CD = self.Create_Control ( t_C_Text_Control, 'R [kOhm]' ) CD = self.Create_Control ( t_C_Text_Control, 'C [nF]' ) CD = self.Create_Control ( t_C_Text_Control, 'Freq. [Hz]' ) CD = self.Create_Control ( t_C_Buttons, 'Knopje' ) # ********************************************************************** # this procedure is only called when inputs (or parameters) have changed # ********************************************************************** def Generate_Output_Signals ( self, In, Out, Par, XIn, XOut, XPar ) : if In[1]==None: return C = self.GUI_Controls #??? from numpy import array #Moet niet nodig zijn, PyLab_Works moet hier voor zorgen data, MetaData = Analyze_TIO_Array(In[1]) data = data[0] MetaData = MetaData[0] # Maybe scaling needs to be done only once... Just change Vmax & Vmin (Danger Vmin assumed 0) # Scale to 0..5 V range Bits = MetaData.Get('ByteWidth',1)*8 if Bits == 8: data = data.astype(float64) * 5.0 / 2.0**8 else: data = data.astype(float64) data = (data + 2.0**(Bits-1))/ 2.0**Bits * 5.0 Vmax = 5.0 # Maximum voltage Vmin = 0.0 # Minimum voltage Vold = 0.0 # Start voltage Btc = 36 # The Btc (Binair time constant) # Bert's method bert_bitlist = [] # List of bits bert_list = [] # List of voltages for frame in data: hi = Vold + (Vmax - Vold) / Btc lo = Vold + (Vmin - Vold) / Btc if abs(frame - hi) < abs(frame - lo): bert_bitlist.append(1) # High bit Vold = hi else: bert_bitlist.append(0) # Low bit Vold = lo bert_list.append(Vold) # Transform back to original range, for easy comparison if Bits == 8: data = array(bert_list) * 256.0 / 5.0 else: data = array(bert_list) * 2.0**Bits / 5.0 - 2.0**(Bits-1) Out [1] = data, MetaData
def Exec(self): try: PG.Debug_Table.Write(self.Nr, Row=True) XIn = copy.copy(self.In_Modified) XOut = copy.copy(self.Out_Modified) """XIn = copy.copy ( self.In. Modified ) XOut = copy.copy ( self.Out.Modified ) self.In. Clear_Modified () self.Out.Clear_Modified () """ #print 'Exec_CHANGE? Name, Xin, Xout, Xpar =', \ # self.Caption, XIn[0],XOut[0],self.Par.Modified[0] #if self.Caption == 'Code Editor' : # print 'Exec_CHANGE? XOut, Out =', \ # self.Caption, self.Out_Modified, self.Out #if self.Caption == 'Code Editor' : # print 'Exec_CHANGE? XOut, Out =', \ # self.Caption, self.Out_Modified, self.Out #print 'Exec_CHANGE? XPar, Par =', \ # self.Caption, self.Par_Modified, self.Par # Transport Input Parameters to the control if XIn[0] and (len(self.Control_Defs) > 0): #print 'Test_For_Changes: call Brick_2_Control',self.In,self.Par self.Control_Pane.Brick_2_Control(self.In) #print self.Params # Check for changes # and Generate output signals #if self.Par.Modified [0]: #print '*********************^^^^^^^^^^^^^^^^' #print ' kqkqk',self.Par_Modified,self.Par.Modified if XIn[0] or XOut[0] or self.Par_Modified[0]: #print 'Generate Name, Xin, Xout, Xpar ****', self.Caption, XIn[0],XOut[0],self.Par.Modified[0] self.Generate_Output_Signals(self.In, self.Out, self.Par, XIn, XOut, self.Par.Modified) #print ' ********** PIEP-33' self.Par.Clear_Modified() #print ' ********** PIEP-4' if self.Continuous: if self.Diagnostic_Mode: PG.wbd(self, _(16, ' ... Run Loop')) self.Run_Loop() #print ' ********** PIEP-77' except: import sys # the third (last) element of exc_info # contains the traceback object # and might be different each time __line = self.Caption + ': ' + str(sys.exc_info()[:-1]) if not (__line in PG.Brick_Errors): PG.Brick_Errors[__line] = 0 PG.Brick_Errors[__line] += 1 if (PG.Brick_Errors[__line] % 5) == 1: print( '***** Error Count =', PG.Brick_Errors[__line], ) print('in:', __line) import traceback traceback.print_exc(5) #from General_Globals import Debug_From #Debug_From () # In case of an error we want to be sure # to clear the modify flag of PAR self.Par.Clear_Modified() self.In.Clear_Modified() self.Out.Clear_Modified() """ else : print '************ OLD DOLD EXEC *******', self.Name, type(self) # Set highlighting and record starttime of this Brick #if PG.Execution_HighLight: self.Execute_Pre () # reset Output_Changed for i,item in enumerate ( self.Out_Modified ) : self.Out_Modified [i] = False # If all required inputs available and # an input or parameter changed then # let the brick recalculate it's output signals try: if self.Test_For_Changes () : #print 'Generate_Output_Signals:',self.Name,self.__class__.__name__ try : if self.Diagnostic_Mode : PG.wbd ( self, _(17, 'Generating Output Signals ...') ) PG.wbd ( None, _(18, ' INPUT_VALUES ',) + str (self.In) ) self.Generate_Output_Signals () if self.Diagnostic_Mode : pass PG.wbd ( None, _(19, ' OUTPUT_VALUES ',) + str (self.Out) ) PG.wbd ( None, _(20, ' OUTPUT_CHANGE ',) + str (self.Out_Modified) ) PG.wbd ( None, _(21, ' ... Succeeded\n') ) except : if self.Diagnostic_Mode : PG.wbd ( None, _(22, ' ... Failed\n') ) PG.em ( _(23, 'Generate_Output_Signals in ') + self.__class__.__name__ ) # keep the actual values #self.Params_Old = copy.copy ( self.Params ) self.Params_Old = copy.deepcopy ( self.Params ) except: pass if self.Continuous : if self.Diagnostic_Mode : PG.wbd ( self, _(24, ' ... Run Loop' )) self.Run_Loop () #print ' outputs: ',self.Output_Value """ # insert some time for GUI processes while PG.app.My_EventLoop.Pending(): PG.app.My_EventLoop.Dispatch() PG.app.My_EventLoop.ProcessIdle()
def __init__(self, Container, Name='', _Dummy_Control=None, _Dummy_Filename=None, Pos=(-1, -1)): """ Volgens mij wordt dit niet meer gebruikt Color = (220,220,220), Pos = (-1,-1), Size = (-1,-1), Value = '' ): Vervangen door """ #zelfs deze moeten weg kunnen Size = (-1, -1) ##Pos = (-1,-1) self._Dummy_Control = _Dummy_Control self._Dummy_Filename = _Dummy_Filename #v3print ( '' ) #exprint ( '********* Create Brick *********', Name ) # make the container available for descendants self.my_Container = Container if Name == '': if Container: Name = 'Brick_' + str(len(Container.Devices)) else: Name = 'Unknown' self.Name = Name self.Caption = Name # This device wants to be executed every loop self.Continuous = False # if True, extra diagnostic info is printed self.Diagnostic_Mode = False self.Control_Defs = [] # to prevent that messages of not implemented methods appear only once self.firsttime_Execute = True #self.my_nr = 0 #if Container : # self.my_nr = Container.diagram.GetCount() self.Nr = 0 # in the execution it's used first on the right of an assigment # so we've to ensure that it exists self.On = True #False self.BP_Flag = False self.BP_State = 0 self.BP_Form = None # IO-pin definitions self.Inputs = {} self.Outputs = {} self.N_Inputs = 0 self.N_Outputs = 0 self.Center = False self.Float = False self.Control_Pane = None self.Main_Description = True ##self.Params = [None] ##self.Params_Old = [None] # Size must be a list, but default values must be a tupple (immutable) self.Size = list(Size) # if size negative, give it a normal value if self.Size[0] < 0: self.Size[0] = 50 if self.Size[1] < 0: self.Size[1] = 50 self.Pos = list(Pos) self.Changed = True # Here get the Library Color from the global of the library file module = __import__(self.__module__) try: self.Library_Color = module.Library_Color except: self.Library_Color = wx.RED # ********************************* # here the extra initalisation # ********************************* #self.PDiag ( 'before "After_Init"') self.After_Init() # ********************************* # ********************************* # for NEW bricks that don't call After_Init_Default # we use temporary this trick ##self.After_Init_Default ( self.Caption ) # ***************************************************** # Code below must not be placed in After_Control_Create # ***************************************************** NI = self.N_Inputs = 1 + len(self.Inputs) NO = self.N_Outputs = 1 + len(self.Outputs) self.In_Modified = NI * [False] self.Out_Modified = NO * [False] self.Par_Modified = NI * [False] #self.In = tIOP_List ( self, self.In_Modified , 'In' , NI, Null ) #self.Out = tIOP_List ( self, self.Out_Modified, 'Out', NO, Null ) #self.Par = tIOP_List ( self, self.Par_Modified, 'Par', NI, Null ) self.In = tIOP_List(self, self.In_Modified, 'In', NI, None) self.Out = tIOP_List(self, self.Out_Modified, 'Out', NO, None) self.Par = tIOP_List(self, self.Par_Modified, 'Par', NI, None) # ***************************************************** #self.PDiag ( 'after "After_Init"') self.Movable = True # ********************************* try: if self.shape: pass except: self.shape = ogl.Rectangle(Container, self, self.Pos, self.Caption) self.shape.fill = [self.Library_Color] #print 'SCOPE',self.Name,self.Pos # check and correct Inputs for input in self.Inputs: temp = self.Inputs[input] if len(temp) < 3: temp.append(False) if len(temp) < 4: temp.append('') """ # Create Output_Values, always ??? try: if self.Out : pass except : # Element 0 is not used self.Out = [ None ] self.Out_Modified = [ False ] Output_Copy = False for i in range ( 1, self.N_Outputs ) : if self.Outputs [i][1] == PG.TIO_INTERACTION : self.Out.append ( {} ) if not ( Output_Copy ) : self.Output_Value_Old = {} Output_Copy = True self.Output_Value_Old [i] = None else : self.Out.append ( None ) self.Out_Modified.append ( False ) #self.PDiag ( 'after "Create Output Values"') """ # and create a shallow !! copy to detect input changes ##self.Params_Old = copy.deepcopy ( self.Params ) if self.Description == '': self.Description = self.Name + ' for more details, see the manual' # for devices imported from a schematic: (re-)define the IO-pins # position is calculated from previous defined elements if self.Pos[0] < 0: self.Pos[0] = 50 if self.Pos[1] < 0: self.Pos[1] = 50 # add the shape to the canvas container if Container: Container.MyAddShape(self) self.Load_Properties_from_File_to_Device() # if components are created dynamically, they are not always shown # so we explictly redraw the component here #self._Redraw() Container.Refresh() # if Brick is in Diagnostic Mode, display extra information if self.Diagnostic_Mode: line = '' line += _(1, 'Brick Running in Diagnostic Mode\n') line += _(2, '*** Creating Brick ***\n') line += _(3, ' <Name> <Type> <Required>\n') for input in self.Inputs: try: line += _(4, 'Input ') + str(input) + ' = ' + str( self.Inputs[input][:-1]) #line += _(5, ', Value = ') + str ( self.Input_Value[input] ) line += _(6, ', Value = ') + str(self.In[input]) except: line += _(7, 'Input ERRROR\n') line += '\n' line += '\n' for output in self.Outputs: try: line += _(8, 'Output ') + str(output) + ' = ' + str( self.Outputs[output]) line += _(9, ', Value = ') + str(self.Out[output]) line += _(10, ', Changed = ') + str( self.Out_Modified[output]) except: line += _(11, 'Output ERRROR') line += '\n' line += '\n' for i, par in enumerate(self.Par): #Params ) : line += _(12, 'Par ') + str(i) + ' = ' + str(par) line += '\n' line += '\n' for i, Control in enumerate(self.Control_Defs): line += 'Control ' + str(i + 1) + '\n' for param in Control: try: line += ' ' + str(param) + ' = ' + str(Control[param]) except: line += _(13, 'Control ERRROR') line += '\n' line += '\n' line += '\n' PG.wbd(self, line)