57 |
57 |
58 CWD = os.path.split(os.path.realpath(__file__))[0] |
58 CWD = os.path.split(os.path.realpath(__file__))[0] |
59 |
59 |
60 gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.faceDnClr, wx.SOLID) |
60 gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.faceDnClr, wx.SOLID) |
61 gen_mini_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenBitmapTextButton._GetLabelSize(obj)[:-1] + (False,)) |
61 gen_mini_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenBitmapTextButton._GetLabelSize(obj)[:-1] + (False,)) |
62 |
62 gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,)) |
63 def GenerateEmptyBitmap(): |
63 |
64 bitmap = wx.EmptyBitmap(24, 24) |
64 def GenerateEmptyBitmap(width, height): |
|
65 bitmap = wx.EmptyBitmap(width, height) |
65 dc = wx.MemoryDC(bitmap) |
66 dc = wx.MemoryDC(bitmap) |
66 dc.SetPen(wx.Pen(WINDOW_COLOUR)) |
67 dc.SetPen(wx.Pen(WINDOW_COLOUR)) |
67 dc.SetBrush(wx.Brush(WINDOW_COLOUR)) |
68 dc.SetBrush(wx.Brush(WINDOW_COLOUR)) |
68 dc.DrawRectangle(0, 0, 24, 24) |
69 dc.DrawRectangle(0, 0, width, height) |
69 return bitmap |
70 return bitmap |
70 |
71 |
71 class LogPseudoFile: |
72 class LogPseudoFile: |
72 """ Base class for file like objects to facilitate StdOut for the Shell.""" |
73 """ Base class for file like objects to facilitate StdOut for the Shell.""" |
73 def __init__(self, output = None): |
74 def __init__(self, output = None): |
375 if self.PluginRoot.HasProjectOpened(): |
376 if self.PluginRoot.HasProjectOpened(): |
376 plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
377 plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
377 plcwindow.SetBackgroundColour(WINDOW_COLOUR) |
378 plcwindow.SetBackgroundColour(WINDOW_COLOUR) |
378 self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) |
379 self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) |
379 |
380 |
380 plcwindowsizer = wx.BoxSizer(wx.VERTICAL) |
381 plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
381 plcwindow.SetSizer(plcwindowsizer) |
382 plcwindow.SetSizer(plcwindowsizer) |
382 |
383 |
383 titlesizer = wx.BoxSizer(wx.HORIZONTAL) |
|
384 plcwindowsizer.AddSizer(titlesizer, 0, border=0, flag=wx.ALIGN_CENTER) |
|
385 |
|
386 st = wx.StaticText(plcwindow, -1) |
384 st = wx.StaticText(plcwindow, -1) |
387 st.SetFont(wx.Font(faces["size"] * 2, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
385 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
388 st.SetLabel("PLC (%s)"%self.PluginRoot.GetProjectName()) |
386 st.SetLabel(self.PluginRoot.GetProjectName()) |
389 titlesizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
387 plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
390 |
388 |
391 if len(self.PluginRoot.PlugChildsTypes) > 0: |
389 plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
392 addbutton_id = wx.NewId() |
390 plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL) |
393 addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'AddPlugin.png')), |
391 |
394 name='AddBusButton', parent=plcwindow, pos=wx.Point(0, 0), |
392 plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
395 size=wx.Size(24, 24), style=wx.NO_BORDER) |
393 plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) |
396 addbutton.GetBackgroundBrush = gen_mini_GetBackgroundBrush(addbutton) |
394 |
397 addbutton.SetToolTipString("Add a plugin to this one") |
395 msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow) |
398 addbutton.Bind(wx.EVT_BUTTON, self.GetAddButtonFunction(self.PluginRoot, plcwindow), id=addbutton_id) |
396 plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
399 titlesizer.AddWindow(addbutton, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
|
400 |
|
401 plcwindowmainsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
402 plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=0, flag=wx.ALIGN_CENTER) |
|
403 |
|
404 msizer = wx.FlexGridSizer(cols=len(self.PluginRoot.PluginMethods)) |
|
405 plcwindowmainsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
|
406 if len(self.PluginRoot.PluginMethods) > 0: |
|
407 for plugin_method in self.PluginRoot.PluginMethods: |
|
408 if "method" in plugin_method: |
|
409 id = wx.NewId() |
|
410 button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=plcwindow, |
|
411 bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=plugin_method["name"], |
|
412 name=plugin_method["name"], pos=wx.DefaultPosition, style=wx.NO_BORDER) |
|
413 button.SetToolTipString(plugin_method["tooltip"]) |
|
414 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(self.PluginRoot, plugin_method["method"]), id=id) |
|
415 #hack to force size to mini |
|
416 button._GetLabelSize = gen_mini_GetLabelSize(button) |
|
417 #button._GetLabelSize = lambda :(-1,-1,False) |
|
418 msizer.AddWindow(button, 0, border=0, flag=0) |
|
419 |
397 |
420 paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1)) |
398 paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1)) |
421 paramswindow.SetBackgroundColour(WINDOW_COLOUR) |
399 paramswindow.SetBackgroundColour(WINDOW_COLOUR) |
422 plcwindowmainsizer.AddWindow(paramswindow, 0, border=0, flag=0) |
400 plcwindowbuttonsizer.AddWindow(paramswindow, 0, border=0, flag=0) |
423 |
401 |
424 psizer = wx.BoxSizer(wx.HORIZONTAL) |
402 psizer = wx.BoxSizer(wx.HORIZONTAL) |
425 paramswindow.SetSizer(psizer) |
403 paramswindow.SetSizer(psizer) |
426 |
404 |
427 plugin_infos = self.PluginRoot.GetParamsAttributes() |
405 plugin_infos = self.PluginRoot.GetParamsAttributes() |
448 msizer.SetCols(len(self.PluginRoot.PluginMethods)) |
426 msizer.SetCols(len(self.PluginRoot.PluginMethods)) |
449 self.PLCConfigMainSizer.Layout() |
427 self.PLCConfigMainSizer.Layout() |
450 self.RefreshScrollBars() |
428 self.RefreshScrollBars() |
451 event.Skip() |
429 event.Skip() |
452 minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id) |
430 minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id) |
453 plcwindowmainsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL) |
431 plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL) |
454 |
432 |
455 self.PLCConfigMainSizer.Layout() |
433 self.PLCConfigMainSizer.Layout() |
456 self.RefreshScrollBars() |
434 self.RefreshScrollBars() |
|
435 |
|
436 if len(self.PluginRoot.PlugChildsTypes) > 0: |
|
437 plcwindowmainsizer.AddSizer(self.GenerateAddButtonSizer(self.PluginRoot, plcwindow), 0, border=0, flag=wx.ALIGN_CENTER) |
|
438 |
|
439 def GenerateAddButtonSizer(self, plugin, parent): |
|
440 addsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
441 for name, XSDClass in plugin.PlugChildsTypes: |
|
442 addbutton_id = wx.NewId() |
|
443 addbutton = wx.lib.buttons.GenButton(id=addbutton_id, label="Add %s"%name, |
|
444 name='AddBusButton', parent=parent, pos=wx.Point(0, 0), |
|
445 style=wx.NO_BORDER) |
|
446 font = addbutton.GetFont() |
|
447 font.SetUnderlined(True) |
|
448 addbutton.SetFont(font) |
|
449 addbutton._GetLabelSize = gen_textbutton_GetLabelSize(addbutton) |
|
450 addbutton.SetForegroundColour(wx.BLUE) |
|
451 addbutton.SetToolTipString("Add a %s plugin to this one"%name) |
|
452 addbutton.Bind(wx.EVT_BUTTON, self._GetAddPluginFunction(name, plugin), id=addbutton_id) |
|
453 addsizer.AddWindow(addbutton, 0, border=0, flag=wx.ALIGN_CENTER) |
|
454 return addsizer |
|
455 |
|
456 def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True): |
|
457 if horizontal: |
|
458 msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods)) |
|
459 else: |
|
460 msizer = wx.FlexGridSizer(cols=1) |
|
461 for plugin_method in plugin.PluginMethods: |
|
462 if "method" in plugin_method: |
|
463 id = wx.NewId() |
|
464 button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=parent, |
|
465 bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=plugin_method["name"], |
|
466 name=plugin_method["name"], pos=wx.DefaultPosition, style=wx.NO_BORDER) |
|
467 button.SetToolTipString(plugin_method["tooltip"]) |
|
468 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id) |
|
469 #hack to force size to mini |
|
470 button._GetLabelSize = gen_mini_GetLabelSize(button) |
|
471 #button._GetLabelSize = lambda :(-1,-1,False) |
|
472 msizer.AddWindow(button, 0, border=0, flag=0) |
|
473 return msizer |
457 |
474 |
458 def RefreshPluginTree(self): |
475 def RefreshPluginTree(self): |
459 self.ClearSizer(self.PluginTreeSizer) |
476 self.ClearSizer(self.PluginTreeSizer) |
460 if self.PluginRoot.HasProjectOpened(): |
477 if self.PluginRoot.HasProjectOpened(): |
461 index = [0] |
478 index = [0] |
500 leftwindowsizer.AddGrowableRow(1) |
517 leftwindowsizer.AddGrowableRow(1) |
501 leftwindow.SetSizer(leftwindowsizer) |
518 leftwindow.SetSizer(leftwindowsizer) |
502 |
519 |
503 leftbuttonmainsizer = wx.FlexGridSizer(cols=3, rows=1) |
520 leftbuttonmainsizer = wx.FlexGridSizer(cols=3, rows=1) |
504 leftbuttonmainsizer.AddGrowableCol(0) |
521 leftbuttonmainsizer.AddGrowableCol(0) |
505 leftwindowsizer.AddSizer(leftbuttonmainsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
522 leftwindowsizer.AddSizer(leftbuttonmainsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP) |
506 |
523 |
507 leftbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
524 leftbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
508 leftbuttonmainsizer.AddSizer(leftbuttonsizer, 0, border=15, flag=wx.GROW|wx.RIGHT) |
525 leftbuttonmainsizer.AddSizer(leftbuttonsizer, 0, border=15, flag=wx.GROW|wx.RIGHT) |
509 |
526 |
510 ieccsizer = wx.BoxSizer(wx.VERTICAL) |
527 ieccsizer = wx.BoxSizer(wx.VERTICAL) |
511 leftbuttonsizer.AddSizer(ieccsizer, 0, border=15, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
528 leftbuttonsizer.AddSizer(ieccsizer, 0, border=15, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
512 |
529 |
513 plugin_IECChannel = plugin.BaseParams.getIEC_Channel() |
530 plugin_IECChannel = plugin.BaseParams.getIEC_Channel() |
514 |
531 |
515 ieccdownbutton_id = wx.NewId() |
|
516 ieccdownbutton = wx.lib.buttons.GenBitmapButton(id=ieccdownbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'IECCDown.png')), |
|
517 name='IECCDownButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
518 size=wx.Size(16, 16), style=wx.NO_BORDER) |
|
519 if plugin_IECChannel > 0: |
532 if plugin_IECChannel > 0: |
|
533 ieccdownbutton_id = wx.NewId() |
|
534 ieccdownbutton = wx.lib.buttons.GenBitmapButton(id=ieccdownbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'IECCDown.png')), |
|
535 name='IECCDownButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
536 size=wx.Size(16, 16), style=wx.NO_BORDER) |
520 ieccdownbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel - 1), id=ieccdownbutton_id) |
537 ieccdownbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel - 1), id=ieccdownbutton_id) |
|
538 ieccsizer.AddWindow(ieccdownbutton, 0, border=0, flag=wx.ALIGN_CENTER) |
521 else: |
539 else: |
522 ieccdownbutton.Enable(False) |
540 staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(16, 16), |
523 ieccsizer.AddWindow(ieccdownbutton, 0, border=0, flag=wx.ALIGN_CENTER) |
541 name="staticBitmap", parent=leftwindow, |
|
542 pos=wx.Point(0, 0), size=wx.Size(16, 16), style=0) |
|
543 ieccsizer.AddWindow(staticbitmap, 0, border=0, flag=wx.ALIGN_CENTER) |
524 |
544 |
525 st = wx.StaticText(leftwindow, -1) |
545 st = wx.StaticText(leftwindow, -1) |
526 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
546 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
527 st.SetLabel(plugin.GetFullIEC_Channel()) |
547 st.SetLabel(plugin.GetFullIEC_Channel()) |
528 ieccsizer.AddWindow(st, 0, border=0, flag=0) |
548 ieccsizer.AddWindow(st, 0, border=0, flag=0) |
573 enablebutton.labelDelta = 0 |
593 enablebutton.labelDelta = 0 |
574 enablebutton.SetBezelWidth(0) |
594 enablebutton.SetBezelWidth(0) |
575 enablebutton.SetUseFocusIndicator(False) |
595 enablebutton.SetUseFocusIndicator(False) |
576 enablebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Enabled.png'))) |
596 enablebutton.SetBitmapSelected(wx.Bitmap(os.path.join(CWD, 'images', 'Enabled.png'))) |
577 enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled()) |
597 enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled()) |
578 |
|
579 def toggleenablebutton(event): |
598 def toggleenablebutton(event): |
580 res, StructChanged = plugin.SetParamsAttribute("BaseParams.Enabled", enablebutton.GetToggle(), self.Log) |
599 res, StructChanged = plugin.SetParamsAttribute("BaseParams.Enabled", enablebutton.GetToggle(), self.Log) |
581 if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
600 if StructChanged: wx.CallAfter(self.RefreshPluginTree) |
582 enablebutton.SetToggle(res) |
601 enablebutton.SetToggle(res) |
583 event.Skip() |
602 event.Skip() |
584 enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id) |
603 enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id) |
585 leftbuttonsizer.AddWindow(enablebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
604 leftbuttonsizer.AddWindow(enablebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
586 |
|
587 if len(plugin.PlugChildsTypes) > 0: |
|
588 addbutton_id = wx.NewId() |
|
589 addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'AddPlugin.png')), |
|
590 name='AddBusButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
591 size=wx.Size(24, 24), style=wx.NO_BORDER) |
|
592 addbutton.GetBackgroundBrush = gen_mini_GetBackgroundBrush(addbutton) |
|
593 addbutton.SetToolTipString("Add a plugin to this one") |
|
594 addbutton.Bind(wx.EVT_BUTTON, self.GetAddButtonFunction(plugin, leftwindow), id=addbutton_id) |
|
595 leftbuttonsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
|
596 |
605 |
597 leftminimizebutton_id = wx.NewId() |
606 leftminimizebutton_id = wx.NewId() |
598 leftminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=leftminimizebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Maximize.png')), |
607 leftminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=leftminimizebutton_id, bitmap=wx.Bitmap(os.path.join(CWD, 'images', 'Maximize.png')), |
599 name='MinimizeButton', parent=leftwindow, pos=wx.Point(0, 0), |
608 name='MinimizeButton', parent=leftwindow, pos=wx.Point(0, 0), |
600 size=wx.Size(24, 24), style=wx.NO_BORDER) |
609 size=wx.Size(24, 24), style=wx.NO_BORDER) |
623 size=wx.Size(24, 24), style=wx.NO_BORDER) |
632 size=wx.Size(24, 24), style=wx.NO_BORDER) |
624 deletebutton.SetToolTipString("Delete this plugin") |
633 deletebutton.SetToolTipString("Delete this plugin") |
625 deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id) |
634 deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id) |
626 leftbuttonmainsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
635 leftbuttonmainsizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) |
627 |
636 |
628 lb = wx.ListBox(leftwindow, -1, size=wx.Size(-1, 100), style=wx.NO_BORDER) |
637 locations = plugin.GetLocations() |
629 for location in plugin.GetLocations(): |
638 lb = wx.ListBox(leftwindow, -1, size=wx.Size(-1, max(1, min(len(locations), 4)) * 25), style=wx.NO_BORDER) |
|
639 for location in locations: |
630 lb.Append(location["NAME"].replace("__", "%").replace("_", ".")) |
640 lb.Append(location["NAME"].replace("__", "%").replace("_", ".")) |
631 if not self.PluginInfos[plugin]["left_visible"]: |
641 if not self.PluginInfos[plugin]["left_visible"]: |
632 lb.Hide() |
642 lb.Hide() |
633 leftwindowsizer.AddWindow(lb, 0, border=5, flag=wx.GROW|wx.ALL) |
643 self.PluginInfos[plugin]["variable_list"] = lb |
|
644 if len(plugin.PlugChildsTypes) > 0: |
|
645 leftwindowsizer.AddWindow(lb, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT) |
|
646 leftwindowsizer.AddSizer(self.GenerateAddButtonSizer(plugin, leftwindow), 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM) |
|
647 else: |
|
648 leftwindowsizer.AddWindow(lb, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
634 |
649 |
635 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
650 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
636 rightwindow.SetBackgroundColour(wx.Colour(240,240,240)) |
651 rightwindow.SetBackgroundColour(wx.Colour(240,240,240)) |
637 |
652 |
638 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
653 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
643 rightwindowsizer = wx.FlexGridSizer(cols=2, rows=1) |
658 rightwindowsizer = wx.FlexGridSizer(cols=2, rows=1) |
644 rightwindowsizer.AddGrowableCol(1) |
659 rightwindowsizer.AddGrowableCol(1) |
645 rightwindowsizer.AddGrowableRow(0) |
660 rightwindowsizer.AddGrowableRow(0) |
646 rightwindowmainsizer.AddSizer(rightwindowsizer, 0, border=17, flag=wx.TOP|wx.GROW) |
661 rightwindowmainsizer.AddSizer(rightwindowsizer, 0, border=17, flag=wx.TOP|wx.GROW) |
647 |
662 |
648 if self.PluginInfos[plugin]["right_visible"]: |
663 msizer = self.GenerateMethodButtonSizer(plugin, rightwindow, not self.PluginInfos[plugin]["right_visible"]) |
649 msizer = wx.FlexGridSizer(cols=1) |
|
650 else: |
|
651 msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods)) |
|
652 rightwindowsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
664 rightwindowsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
653 if len(plugin.PluginMethods) > 0: |
|
654 for plugin_method in plugin.PluginMethods: |
|
655 if "method" in plugin_method: |
|
656 id = wx.NewId() |
|
657 button = wx.lib.buttons.GenBitmapTextButton(id=id, parent=rightwindow, |
|
658 bitmap=wx.Bitmap(os.path.join(CWD, "%s24x24.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=plugin_method["name"], |
|
659 name=plugin_method["name"], pos=wx.DefaultPosition, style=wx.NO_BORDER) |
|
660 button.SetToolTipString(plugin_method["tooltip"]) |
|
661 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id) |
|
662 #hack to force size to mini |
|
663 button._GetLabelSize = gen_mini_GetLabelSize(button) |
|
664 #button._GetLabelSize = lambda :(-1,-1,False) |
|
665 msizer.AddWindow(button, 0, border=0, flag=0) |
|
666 |
665 |
667 rightparamssizer = wx.BoxSizer(wx.HORIZONTAL) |
666 rightparamssizer = wx.BoxSizer(wx.HORIZONTAL) |
668 rightwindowsizer.AddSizer(rightparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT) |
667 rightwindowsizer.AddSizer(rightparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT) |
669 |
668 |
670 paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1)) |
669 paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1)) |
712 for child in self.PluginInfos[plugin]["children"]: |
711 for child in self.PluginInfos[plugin]["children"]: |
713 self.GenerateTreeBranch(child, index) |
712 self.GenerateTreeBranch(child, index) |
714 if not self.PluginInfos[child]["expanded"]: |
713 if not self.PluginInfos[child]["expanded"]: |
715 self.CollapsePlugin(child) |
714 self.CollapsePlugin(child) |
716 |
715 |
|
716 def RefreshVariableLists(self): |
|
717 for plugin, infos in self.PluginInfos.items(): |
|
718 locations = plugin.GetLocations() |
|
719 infos["variable_list"].SetSize(wx.Size(-1, max(1, min(len(locations), 4)) * 25)) |
|
720 infos["variable_list"].Clear() |
|
721 for location in locations: |
|
722 infos["variable_list"].Append(location["NAME"].replace("__", "%").replace("_", ".")) |
|
723 self.PLCConfigMainSizer.Layout() |
|
724 self.RefreshScrollBars() |
|
725 |
717 def GetItemChannelChangedFunction(self, plugin, value): |
726 def GetItemChannelChangedFunction(self, plugin, value): |
718 def OnPluginTreeItemChannelChanged(event): |
727 def OnPluginTreeItemChannelChanged(event): |
719 res, StructChanged = plugin.SetParamsAttribute("BaseParams.IEC_Channel", value, self.Log) |
728 res, StructChanged = plugin.SetParamsAttribute("BaseParams.IEC_Channel", value, self.Log) |
720 wx.CallAfter(self.RefreshPluginTree) |
729 wx.CallAfter(self.RefreshPluginTree) |
721 event.Skip() |
730 event.Skip() |
722 return OnPluginTreeItemChannelChanged |
731 return OnPluginTreeItemChannelChanged |
723 |
732 |
724 def _GetAddPluginFunction(self, name, plugin): |
733 def _GetAddPluginFunction(self, name, plugin): |
725 def OnPluginMenu(event): |
734 def OnPluginMenu(event): |
726 self.AddPlugin(name, plugin) |
735 wx.CallAfter(self.AddPlugin, name, plugin) |
727 event.Skip() |
736 event.Skip() |
728 return OnPluginMenu |
737 return OnPluginMenu |
729 |
738 |
730 def OnPluginTreeRightUp(self, event): |
739 def OnPluginTreeRightUp(self, event): |
731 plugin = self.GetSelectedPlugin() |
740 plugin = self.GetSelectedPlugin() |
829 staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
839 staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
830 name="%s_bitmap"%element_infos["name"], parent=parent, |
840 name="%s_bitmap"%element_infos["name"], parent=parent, |
831 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
841 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
832 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
842 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
833 else: |
843 else: |
834 staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(), |
844 staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(24, 24), |
835 name="%s_bitmap"%element_infos["name"], parent=parent, |
845 name="%s_bitmap"%element_infos["name"], parent=parent, |
836 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
846 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
837 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
847 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
838 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
848 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
839 name="%s_label"%element_infos["name"], parent=parent, |
849 name="%s_label"%element_infos["name"], parent=parent, |
872 staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
882 staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
873 name="%s_bitmap"%element_infos["name"], parent=parent, |
883 name="%s_bitmap"%element_infos["name"], parent=parent, |
874 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
884 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
875 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
885 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
876 else: |
886 else: |
877 staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(), |
887 staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(24, 24), |
878 name="%s_bitmap"%element_infos["name"], parent=parent, |
888 name="%s_bitmap"%element_infos["name"], parent=parent, |
879 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
889 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
880 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
890 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
881 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
891 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
882 name="%s_label"%element_infos["name"], parent=parent, |
892 name="%s_label"%element_infos["name"], parent=parent, |
916 staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
926 staticbitmap = wx.StaticBitmap(id=-1, bitmap=wx.Bitmap(bitmappath), |
917 name="%s_bitmap"%element_infos["name"], parent=parent, |
927 name="%s_bitmap"%element_infos["name"], parent=parent, |
918 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
928 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
919 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
929 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
920 else: |
930 else: |
921 staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(), |
931 staticbitmap = wx.StaticBitmap(id=-1, bitmap=GenerateEmptyBitmap(24, 24), |
922 name="%s_bitmap"%element_infos["name"], parent=parent, |
932 name="%s_bitmap"%element_infos["name"], parent=parent, |
923 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
933 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
924 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
934 boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
925 |
935 |
926 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |
936 statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], |