--- a/editors/ConfTreeNodeEditor.py Wed Mar 13 12:34:55 2013 +0900
+++ b/editors/ConfTreeNodeEditor.py Wed Jul 31 10:45:07 2013 +0900
@@ -29,24 +29,12 @@
}
SCROLLBAR_UNIT = 10
-WINDOW_COLOUR = wx.Colour(240, 240, 240)
CWD = os.path.split(os.path.realpath(__file__))[0]
def Bpath(*args):
return os.path.join(CWD,*args)
-# Some helpers to tweak GenBitmapTextButtons
-# TODO: declare customized classes instead.
-gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.GetParent().GetBackgroundColour(), wx.SOLID)
-gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,))
-
-def make_genbitmaptogglebutton_flat(button):
- button.GetBackgroundBrush = gen_mini_GetBackgroundBrush(button)
- button.labelDelta = 0
- button.SetBezelWidth(0)
- button.SetUseFocusIndicator(False)
-
# Patch wx.lib.imageutils so that gray is supported on alpha images
import wx.lib.imageutils
from wx.lib.imageutils import grayOut as old_grayOut
@@ -116,7 +104,7 @@
dc.DrawText(label, pos_x, pos_y) # draw the text
-class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap):
+class GenStaticBitmap(wx.StaticBitmap):
""" Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32,
and accept image name as __init__ parameter, fail silently if file do not exist"""
def __init__(self, parent, ID, bitmapname,
@@ -124,20 +112,15 @@
style = 0,
name = "genstatbmp"):
- wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID,
- GetBitmap(bitmapname),
+ bitmap = GetBitmap(bitmapname)
+ if bitmap is None:
+ bitmap = wx.EmptyBitmap(0, 0)
+
+ wx.StaticBitmap.__init__(self, parent, ID,
+ bitmap,
pos, size,
style,
name)
-
- def OnPaint(self, event):
- dc = wx.PaintDC(self)
- colour = self.GetParent().GetBackgroundColour()
- dc.SetPen(wx.Pen(colour))
- dc.SetBrush(wx.Brush(colour ))
- dc.DrawRectangle(0, 0, *dc.GetSizeTuple())
- if self._bitmap:
- dc.DrawBitmap(self._bitmap, 0, 0, True)
class ConfTreeNodeEditor(EditorPanel):
@@ -147,57 +130,21 @@
def _init_Editor(self, parent):
tabs_num = len(self.CONFNODEEDITOR_TABS)
- if self.SHOW_PARAMS:
+ if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0:
tabs_num += 1
- if tabs_num > 1:
+ if tabs_num > 1 or self.SHOW_BASE_PARAMS:
self.Editor = wx.Panel(parent,
style=wx.SUNKEN_BORDER|wx.SP_3D)
- main_sizer = wx.BoxSizer(wx.VERTICAL)
-
- self.ConfNodeNoteBook = wx.Notebook(self.Editor)
- parent = self.ConfNodeNoteBook
- main_sizer.AddWindow(self.ConfNodeNoteBook, 1, flag=wx.GROW)
-
- self.Editor.SetSizer(main_sizer)
- else:
- self.ConfNodeNoteBook = None
- self.Editor = None
-
- for title, create_func_name in self.CONFNODEEDITOR_TABS:
- editor = getattr(self, create_func_name)(parent)
- if self.ConfNodeNoteBook is not None:
- self.ConfNodeNoteBook.AddPage(editor, title)
- else:
- self.Editor = editor
-
- if self.SHOW_PARAMS:
-
- panel_style = wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL
- if self.ConfNodeNoteBook is None:
- panel_style |= wx.SUNKEN_BORDER
- self.ParamsEditor = wx.ScrolledWindow(parent,
- style=panel_style)
- self.ParamsEditor.SetBackgroundColour(WINDOW_COLOUR)
- self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnWindowResize)
- self.ParamsEditor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
-
- # Variable allowing disabling of ParamsEditor scroll when Popup shown
- self.ScrollingEnabled = True
+ self.MainSizer = wx.BoxSizer(wx.VERTICAL)
if self.SHOW_BASE_PARAMS:
- self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
- self.ParamsEditorSizer.AddGrowableCol(0)
- self.ParamsEditorSizer.AddGrowableRow(1)
-
- self.ParamsEditor.SetSizer(self.ParamsEditorSizer)
-
baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL)
- self.ParamsEditorSizer.AddSizer(baseparamseditor_sizer, border=5,
- flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP)
-
- self.FullIECChannel = wx.StaticText(self.ParamsEditor, -1)
+ self.MainSizer.AddSizer(baseparamseditor_sizer, border=5,
+ flag=wx.GROW|wx.ALL)
+
+ self.FullIECChannel = wx.StaticText(self.Editor, -1)
self.FullIECChannel.SetFont(
wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL,
wx.BOLD, faceName = faces["helv"]))
@@ -208,20 +155,20 @@
baseparamseditor_sizer.AddSizer(updownsizer, border=5,
flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
- self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(self.ParamsEditor,
+ self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(self.Editor,
bitmap=GetBitmap('IECCDown'), size=wx.Size(16, 16), style=wx.NO_BORDER)
self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1),
self.IECCUpButton)
updownsizer.AddWindow(self.IECCUpButton, flag=wx.ALIGN_LEFT)
- self.IECCDownButton = wx.lib.buttons.GenBitmapButton(self.ParamsEditor,
+ self.IECCDownButton = wx.lib.buttons.GenBitmapButton(self.Editor,
bitmap=GetBitmap('IECCUp'), size=wx.Size(16, 16), style=wx.NO_BORDER)
self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1),
self.IECCDownButton)
updownsizer.AddWindow(self.IECCDownButton, flag=wx.ALIGN_LEFT)
- self.ConfNodeName = wx.TextCtrl(self.ParamsEditor,
- size=wx.Size(150, 25), style=wx.NO_BORDER)
+ self.ConfNodeName = wx.TextCtrl(self.Editor,
+ size=wx.Size(150, 25))
self.ConfNodeName.SetFont(
wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL,
wx.BOLD, faceName = faces["helv"]))
@@ -234,10 +181,42 @@
buttons_sizer = self.GenerateMethodButtonSizer()
baseparamseditor_sizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER)
+ if tabs_num > 1:
+ self.ConfNodeNoteBook = wx.Notebook(self.Editor)
+ parent = self.ConfNodeNoteBook
+ self.MainSizer.AddWindow(self.ConfNodeNoteBook, 1, flag=wx.GROW)
else:
- self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=5)
- self.ParamsEditorSizer.AddGrowableCol(0)
- self.ParamsEditorSizer.AddGrowableRow(0)
+ parent = self.Editor
+ self.ConfNodeNoteBook = None
+
+ self.Editor.SetSizer(self.MainSizer)
+ else:
+ self.ConfNodeNoteBook = None
+ self.Editor = None
+
+ for title, create_func_name in self.CONFNODEEDITOR_TABS:
+ editor = getattr(self, create_func_name)(parent)
+ if self.ConfNodeNoteBook is not None:
+ self.ConfNodeNoteBook.AddPage(editor, title)
+ elif self.SHOW_BASE_PARAMS:
+ self.MainSizer.AddWindow(editor, 1, flag=wx.GROW)
+ else:
+ self.Editor = editor
+
+ if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0:
+
+ panel_style = wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL
+ if self.ConfNodeNoteBook is None and parent != self.Editor:
+ panel_style |= wx.SUNKEN_BORDER
+ self.ParamsEditor = wx.ScrolledWindow(parent,
+ style=panel_style)
+ self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnParamsEditorResize)
+ self.ParamsEditor.Bind(wx.EVT_SCROLLWIN, self.OnParamsEditorScroll)
+
+ self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=5)
+ self.ParamsEditorSizer.AddGrowableCol(0)
+ self.ParamsEditorSizer.AddGrowableRow(0)
+ self.ParamsEditor.SetSizer(self.ParamsEditorSizer)
self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, border=5,
@@ -247,6 +226,8 @@
if self.ConfNodeNoteBook is not None:
self.ConfNodeNoteBook.AddPage(self.ParamsEditor, _("Config"))
+ elif self.SHOW_BASE_PARAMS:
+ self.MainSizer.AddWindow(self.ParamsEditor, 1, flag=wx.GROW)
else:
self.Editor = self.ParamsEditor
else:
@@ -287,19 +268,17 @@
def RefreshView(self):
EditorPanel.RefreshView(self)
+ if self.SHOW_BASE_PARAMS:
+ self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName())
+ self.RefreshIECChannelControlsState()
if self.ParamsEditor is not None:
- if self.SHOW_BASE_PARAMS:
- self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName())
- self.RefreshIECChannelControlsState()
self.RefreshConfNodeParamsSizer()
self.RefreshScrollbars()
- def EnableScrolling(self, enable):
- self.ScrollingEnabled = enable
-
def RefreshIECChannelControlsState(self):
self.FullIECChannel.SetLabel(self.Controler.GetFullIEC_Channel())
self.IECCDownButton.Enable(self.Controler.BaseParams.getIEC_Channel() > 0)
+ self.MainSizer.Layout()
def RefreshConfNodeParamsSizer(self):
self.Freeze()
@@ -320,7 +299,7 @@
for confnode_method in self.Controler.ConfNodeMethods:
if "method" in confnode_method and confnode_method.get("shown",True):
- button = GenBitmapTextButton(self.ParamsEditor,
+ button = GenBitmapTextButton(self.Editor,
bitmap=GetBitmap(confnode_method.get("bitmap", "Unknown")),
label=confnode_method["name"], style=wx.NO_BORDER)
button.SetFont(normal_bt_font)
@@ -484,7 +463,6 @@
choices = self.ParentWindow.GetConfigEntry(element_path, [""])
textctrl = TextCtrlAutoComplete(name=element_infos["name"],
parent=self.ParamsEditor,
- appframe=self,
choices=choices,
element_path=element_path,
size=wx.Size(300, -1))
@@ -492,7 +470,9 @@
boxsizer.AddWindow(textctrl)
if element_infos["value"] is not None:
textctrl.ChangeValue(str(element_infos["value"]))
- textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, element_path))
+ callback = self.GetTextCtrlCallBackFunction(textctrl, element_path)
+ textctrl.Bind(wx.EVT_TEXT_ENTER, callback)
+ textctrl.Bind(wx.EVT_KILL_FOCUS, callback)
first = False
@@ -502,13 +482,12 @@
res = self.SetConfNodeParamsAttribute("BaseParams.IEC_Channel", confnode_IECChannel + dir)
wx.CallAfter(self.RefreshIECChannelControlsState)
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE)
- wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName())
event.Skip()
return OnConfNodeTreeItemChannelChanged
def SetConfNodeParamsAttribute(self, *args, **kwargs):
res, StructChanged = self.Controler.SetParamsAttribute(*args, **kwargs)
- if StructChanged:
+ if StructChanged and self.ParamsEditor is not None:
wx.CallAfter(self.RefreshConfNodeParamsSizer)
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU)
return res
@@ -547,8 +526,8 @@
if res != textctrl.GetValue():
if isinstance(textctrl, wx.SpinCtrl):
textctrl.SetValue(res)
- else:
- textctrl.ChangeValue(res)
+ elif res is not None:
+ textctrl.ChangeValue(str(res))
if refresh:
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE, PAGETITLES)
wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName())
@@ -585,11 +564,14 @@
self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
- def OnWindowResize(self, event):
+ def OnParamsEditorResize(self, event):
self.RefreshScrollbars()
event.Skip()
- def OnMouseWheel(self, event):
- if self.ScrollingEnabled:
- event.Skip()
-
+ def OnParamsEditorScroll(self, event):
+ control = self.ParamsEditor.FindFocus()
+ if isinstance(control, TextCtrlAutoComplete):
+ control.DismissListBox()
+ self.Refresh()
+ event.Skip()
+