# HG changeset patch # User laurent # Date 1332111051 -3600 # Node ID 2f7b3d1de278d74110be2b4f96212d3163250a8c # Parent 01f5e63568591405bee9b5a40ec4755168277cf2 Adding support for selecting plugin parameter value from a tree of available values diff -r 01f5e6356859 -r 2f7b3d1de278 Beremiz.py --- a/Beremiz.py Sun Mar 18 19:17:54 2012 +0100 +++ b/Beremiz.py Sun Mar 18 23:50:51 2012 +0100 @@ -144,6 +144,7 @@ import wx.lib.buttons, wx.lib.statbmp import TextCtrlAutoComplete, cPickle +from BrowseValuesLibraryDialog import BrowseValuesLibraryDialog import types, time, re, platform, time, traceback, commands from plugger import PluginsRoot, MATIEC_ERROR_MODEL from wxPopen import ProcessLogger @@ -933,7 +934,7 @@ paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1)) paramswindow.SetBackgroundColour(bkgdclr) - psizer = wx.BoxSizer(wx.HORIZONTAL) + psizer = wx.BoxSizer(wx.VERTICAL) paramswindow.SetSizer(psizer) self.PluginInfos[plugin]["params"] = paramswindow @@ -1004,7 +1005,7 @@ for child in self.PluginInfos[plugin]["children"]: self.PluginInfos[child]["left"].Show() self.PluginInfos[child]["right"].Show() - if force or not self.PluginInfos[child]["expanded"]: + if force or self.PluginInfos[child]["expanded"]: self.ExpandPlugin(child, force) if force: self.PluginInfos[child]["expanded"] = True @@ -1406,6 +1407,18 @@ event.Skip() return OnCheckBoxChanged + def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, plugin, path): + infos = [value_infos] + def OnBrowseButton(event): + dialog = BrowseValuesLibraryDialog(self, name, library, infos[0]) + if dialog.ShowModal() == wx.ID_OK: + value, value_infos = self.SetPluginParamsAttribute(plugin, path, dialog.GetValueInfos()) + textctrl.ChangeValue(value) + infos[0] = value_infos + dialog.Destroy() + event.Skip() + return OnBrowseButton + def ClearSizer(self, sizer): staticboxes = [] for item in sizer.GetChildren(): @@ -1459,32 +1472,53 @@ boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT) id = wx.NewId() if isinstance(element_infos["type"], types.ListType): - combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent, - pos=wx.Point(0, 0), size=wx.Size(300, 28), style=wx.CB_READONLY) - boxsizer.AddWindow(combobox, 0, border=0, flag=0) - if element_infos["use"] == "optional": - combobox.Append("") - if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): - for choice, xsdclass in element_infos["type"]: - combobox.Append(choice) - name = element_infos["name"] - value = element_infos["value"] - staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), - name='%s_staticbox'%element_infos["name"], parent=parent, - pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0) - staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) - sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM) - self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path) - callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, plugin, element_path) + if isinstance(element_infos["value"], types.TupleType): + browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL) + boxsizer.AddSizer(browse_boxsizer, 0, border=0, flag=0) + + textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=parent, + pos=wx.Point(0, 0), size=wx.Size(275, 25), style=wx.TE_READONLY) + if element_infos["value"] is not None: + textctrl.SetValue(element_infos["value"][0]) + value_infos = element_infos["value"][1] + else: + value_infos = None + browse_boxsizer.AddWindow(textctrl, 0, border=0, flag=0) + button_id = wx.NewId() + button = wx.Button(id=button_id, name="browse_%s" % element_infos["name"], parent=parent, + label="...", pos=wx.Point(0, 0), size=wx.Size(25, 25)) + browse_boxsizer.AddWindow(button, 0, border=0, flag=0) + button.Bind(wx.EVT_BUTTON, + self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], + value_infos, plugin, element_path), + id=button_id) else: - for choice in element_infos["type"]: - combobox.Append(choice) - callback = self.GetChoiceCallBackFunction(combobox, plugin, element_path) - if element_infos["value"] is None: - combobox.SetStringSelection("") - else: - combobox.SetStringSelection(element_infos["value"]) - combobox.Bind(wx.EVT_COMBOBOX, callback, id=id) + combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent, + pos=wx.Point(0, 0), size=wx.Size(300, 28), style=wx.CB_READONLY) + boxsizer.AddWindow(combobox, 0, border=0, flag=0) + if element_infos["use"] == "optional": + combobox.Append("") + if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): + for choice, xsdclass in element_infos["type"]: + combobox.Append(choice) + name = element_infos["name"] + value = element_infos["value"] + staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), + name='%s_staticbox'%element_infos["name"], parent=parent, + pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0) + staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) + sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM) + self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path) + callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, plugin, element_path) + else: + for choice in element_infos["type"]: + combobox.Append(choice) + callback = self.GetChoiceCallBackFunction(combobox, plugin, element_path) + if element_infos["value"] is None: + combobox.SetStringSelection("") + else: + combobox.SetStringSelection(element_infos["value"]) + combobox.Bind(wx.EVT_COMBOBOX, callback, id=id) elif isinstance(element_infos["type"], types.DictType): scmin = -(2**31) scmax = 2**31-1 @@ -1496,14 +1530,16 @@ pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) spinctrl.SetRange(scmin,scmax) boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) - spinctrl.SetValue(element_infos["value"]) + if element_infos["value"] is not None: + spinctrl.SetValue(element_infos["value"]) spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id) else: if element_infos["type"] == "boolean": checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0) boxsizer.AddWindow(checkbox, 0, border=0, flag=0) - checkbox.SetValue(element_infos["value"]) + if element_infos["value"] is not None: + checkbox.SetValue(element_infos["value"]) checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id) elif element_infos["type"] in ["unsignedLong", "long","integer"]: if element_infos["type"].startswith("unsigned"): @@ -1515,7 +1551,8 @@ pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) spinctrl.SetRange(scmin, scmax) boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) - spinctrl.SetValue(element_infos["value"]) + if element_infos["value"] is not None: + spinctrl.SetValue(element_infos["value"]) spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id) else: choices = cPickle.loads(str(self.Config.Read(element_path, cPickle.dumps([""])))) @@ -1530,7 +1567,8 @@ style=0) boxsizer.AddWindow(textctrl, 0, border=0, flag=0) - textctrl.ChangeValue(str(element_infos["value"])) + if element_infos["value"] is not None: + textctrl.ChangeValue(str(element_infos["value"])) textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path)) first = False diff -r 01f5e6356859 -r 2f7b3d1de278 BrowseValuesLibraryDialog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BrowseValuesLibraryDialog.py Sun Mar 18 23:50:51 2012 +0100 @@ -0,0 +1,107 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +#This file is part of Beremiz, a Integrated Development Environment for +#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. +# +#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD +# +#See COPYING file for copyrights details. +# +#This library is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public +#License as published by the Free Software Foundation; either +#version 2.1 of the License, or (at your option) any later version. +# +#This library is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +#General Public License for more details. +# +#You should have received a copy of the GNU General Public +#License along with this library; if not, write to the Free Software +#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import wx + +[ID_BROWSEVALUESLIBRARYDIALOG, ID_BROWSEVALUESLIBRARYDIALOGSTATICTEXT1, + ID_BROWSEVALUESLIBRARYDIALOGVALUESLIBRARY +] = [wx.NewId() for _init_ctrls in range(3)] + +class BrowseValuesLibraryDialog(wx.Dialog): + + if wx.VERSION < (2, 6, 0): + def Bind(self, event, function, id = None): + if id is not None: + event(self, id, function) + else: + event(self, function) + + def _init_coll_flexGridSizer1_Items(self, parent): + parent.AddWindow(self.staticText1, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) + parent.AddWindow(self.ValuesLibrary, 0, border=20, flag=wx.GROW|wx.LEFT|wx.RIGHT) + parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) + + def _init_coll_flexGridSizer1_Growables(self, parent): + parent.AddGrowableCol(0) + parent.AddGrowableRow(1) + + def _init_sizers(self): + self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) + + self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) + self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) + + self.SetSizer(self.flexGridSizer1) + + def _init_ctrls(self, prnt, name): + wx.Dialog.__init__(self, id=ID_BROWSEVALUESLIBRARYDIALOG, + name='BrowseValueDialog', parent=prnt, + size=wx.Size(600, 400), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, + title=_('Browse %s library') % name) + self.SetClientSize(wx.Size(600, 400)) + + self.staticText1 = wx.StaticText(id=ID_BROWSEVALUESLIBRARYDIALOGSTATICTEXT1, + label=_('Choose a %s:') % name, name='staticText1', parent=self, + pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) + + self.ValuesLibrary = wx.TreeCtrl(id=ID_BROWSEVALUESLIBRARYDIALOGVALUESLIBRARY, + name='ValuesLibrary', parent=self, pos=wx.Point(0, 0), + size=wx.Size(0, 0), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT) + + self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) + if wx.VERSION >= (2, 5, 0): + self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) + else: + self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) + + self._init_sizers() + + def __init__(self, parent, name, library, default=None): + self._init_ctrls(parent, name) + + root = self.ValuesLibrary.AddRoot("") + self.GenerateValuesLibraryBranch(root, library, default) + + def GenerateValuesLibraryBranch(self, root, children, default): + for infos in children: + item = self.ValuesLibrary.AppendItem(root, infos["name"]) + self.ValuesLibrary.SetPyData(item, infos["infos"]) + if infos["infos"] is not None and infos["infos"] == default: + self.ValuesLibrary.SelectItem(item) + self.ValuesLibrary.EnsureVisible(item) + self.GenerateValuesLibraryBranch(item, infos["children"], default) + + def GetValueInfos(self): + selected = self.ValuesLibrary.GetSelection() + return self.ValuesLibrary.GetPyData(selected) + + def OnOK(self, event): + selected = self.ValuesLibrary.GetSelection() + if not selected.IsOk() or self.ValuesLibrary.GetPyData(selected) is None: + message = wx.MessageDialog(self, _("No valid value selected!"), _("Error"), wx.OK|wx.ICON_ERROR) + message.ShowModal() + message.Destroy() + else: + self.EndModal(wx.ID_OK) + diff -r 01f5e6356859 -r 2f7b3d1de278 plugger.py --- a/plugger.py Sun Mar 18 19:17:54 2012 +0100 +++ b/plugger.py Sun Mar 18 23:50:51 2012 +0100 @@ -1781,7 +1781,7 @@ def RemoteExec(self, script, **kwargs): if self._connector is None: - return -1, "No runtime connected" + return -1, "No runtime connected!" return self._connector.RemoteExec(script, **kwargs) def DebugThreadProc(self): @@ -1823,11 +1823,12 @@ self.DebugThread = None def KillDebugThread(self): + tmp_debugthread = self.DebugThread self.debug_break = True - if self.DebugThread is not None: + if tmp_debugthread is not None: self.logger.writeyield(_("Stopping debugger...\n")) - self.DebugThread.join(timeout=5) - if self.DebugThread.isAlive() and self.logger: + tmp_debugthread.join(timeout=5) + if tmp_debugthread.isAlive() and self.logger: self.logger.write_warning(_("Couldn't stop debugger.\n")) else: self.logger.write(_("Debugger stopped.\n"))