From: W. Trevor King Date: Thu, 29 Jul 2010 16:43:56 +0000 (-0400) Subject: Added simple PathProperty (same as StringProperty). X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=da3aeb05ff12366f3b7b5464e1cde8e0864f8e84;p=hooke.git Added simple PathProperty (same as StringProperty). Outstanding types: 3 object 3 dict 1 function --- diff --git a/hooke/ui/gui/panel/propertyeditor2.py b/hooke/ui/gui/panel/propertyeditor2.py index 7af1175..9ff7736 100644 --- a/hooke/ui/gui/panel/propertyeditor2.py +++ b/hooke/ui/gui/panel/propertyeditor2.py @@ -158,247 +158,15 @@ class ChoiceProperty (Property): return None #return wx.grid.GridCellChoiceRenderer() -#class PyFilesProperty(wxpg.PyArrayStringProperty): -# def __init__(self, label, name = wxpg.LABEL_AS_NAME, value=[]): -# wxpg.PyArrayStringProperty.__init__(self, label, name, value) -# self.SetValue(value) -# -# def OnSetValue(self, v): -# self.value = v -# self.display = ', '.join(self.value) -# -# def GetValueAsString(self, argFlags): -# return self.display -# -# def PyStringToValue(self, s, flags): -# return [a.strip() for a in s.split(',')] -# -# def OnEvent(self, propgrid, ctrl, event): -# if event.GetEventType() == wx.wxEVT_COMMAND_BUTTON_CLICKED: -# # Show dialog to select a string, call DoSetValue and -# # return True, if value changed. -# return True -# -# return False -# -# -#class PyObjectPropertyValue: -# """\ -# Value type of our sample PyObjectProperty. We keep a simple dash-delimited -# list of string given as argument to constructor. -# """ -# def __init__(self, s=None): -# try: -# self.ls = [a.strip() for a in s.split('-')] -# except: -# self.ls = [] -# -# def __repr__(self): -# return ' - '.join(self.ls) -# -# -#class PyObjectProperty(wxpg.PyProperty): -# """\ -# Another simple example. This time our value is a PyObject (NOTE: we can't -# return an arbitrary python object in DoGetValue. It cannot be a simple -# type such as int, bool, double, or string, nor an array or wxObject based. -# Dictionary, None, or any user-specified Python object is allowed). -# """ -# def __init__(self, label, name = wxpg.LABEL_AS_NAME, value=None): -# wxpg.PyProperty.__init__(self, label, name) -# self.SetValue(value) -# -# def GetClassName(self): -# return self.__class__.__name__ -# -# def GetEditor(self): -# return "TextCtrl" -# -# def GetValueAsString(self, flags): -# return repr(self.GetValue()) -# -# def PyStringToValue(self, s, flags): -# return PyObjectPropertyValue(s) -# -# -#class ShapeProperty(wxpg.PyEnumProperty): -# """\ -# Demonstrates use of OnCustomPaint method. -# """ -# def __init__(self, label, name = wxpg.LABEL_AS_NAME, value=-1): -# wxpg.PyEnumProperty.__init__(self, label, name, ['Line','Circle','Rectangle'], [0,1,2], value) -# -# def OnMeasureImage(self, index): -# return wxpg.DEFAULT_IMAGE_SIZE -# -# def OnCustomPaint(self, dc, rect, paint_data): -# """\ -# paint_data.m_choiceItem is -1 if we are painting the control, -# in which case we need to get the drawn item using DoGetValue. -# """ -# item = paint_data.m_choiceItem -# if item == -1: -# item = self.DoGetValue() -# -# dc.SetPen(wx.Pen(wx.BLACK)) -# dc.SetBrush(wx.Brush(wx.BLACK)) -# -# if item == 0: -# dc.DrawLine(rect.x,rect.y,rect.x+rect.width,rect.y+rect.height) -# elif item == 1: -# half_width = rect.width / 2 -# dc.DrawCircle(rect.x+half_width,rect.y+half_width,half_width-3) -# elif item == 2: -# dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height) -# -# -#class LargeImagePickerCtrl(wx.Window): -# """\ -# Control created and used by LargeImageEditor. -# """ -# def __init__(self): -# pre = wx.PreWindow() -# self.PostCreate(pre) -# -# def Create(self, parent, id_, pos, size, style = 0): -# wx.Window.Create(self, parent, id_, pos, size, style | wx.BORDER_SIMPLE) -# img_spc = size[1] -# self.tc = wx.TextCtrl(self, -1, "", (img_spc,0), (2048,size[1]), wx.BORDER_NONE) -# self.SetBackgroundColour(wx.WHITE) -# self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) -# self.property = None -# self.bmp = None -# self.Bind(wx.EVT_PAINT, self.OnPaint) -# -# def OnPaint(self, event): -# dc = wx.BufferedPaintDC(self) -# -# whiteBrush = wx.Brush(wx.WHITE) -# dc.SetBackground(whiteBrush) -# dc.Clear() -# -# bmp = self.bmp -# if bmp: -# dc.DrawBitmap(bmp, 2, 2) -# else: -# dc.SetPen(wx.Pen(wx.BLACK)) -# dc.SetBrush(whiteBrush) -# dc.DrawRectangle(2, 2, 64, 64) -# -# def RefreshThumbnail(self): -# """\ -# We use here very simple image scaling code. -# """ -# if not self.property: -# self.bmp = None -# return -# -# path = self.property.DoGetValue() -# -# if not os.path.isfile(path): -# self.bmp = None -# return -# -# image = wx.Image(path) -# image.Rescale(64, 64) -# self.bmp = wx.BitmapFromImage(image) -# -# def SetProperty(self, property): -# self.property = property -# self.tc.SetValue(property.GetDisplayedString()) -# self.RefreshThumbnail() -# -# def SetValue(self, s): -# self.RefreshThumbnail() -# self.tc.SetValue(s) -# -# def GetLastPosition(self): -# return self.tc.GetLastPosition() -# -# -#class LargeImageEditor(wxpg.PyEditor): -# """\ -# Double-height text-editor with image in front. -# """ -# def __init__(self): -# wxpg.PyEditor.__init__(self) -# -# def CreateControls(self, propgrid, property, pos, sz): -# try: -# h = 64 + 6 -# x = propgrid.GetSplitterPosition() -# x2 = propgrid.GetClientSize().x -# bw = propgrid.GetRowHeight() -# lipc = LargeImagePickerCtrl() -# if sys.platform == 'win32': -# lipc.Hide() -# lipc.Create(propgrid, wxpg.PG_SUBID1, (x,pos[1]), (x2-x-bw,h)) -# lipc.SetProperty(property) -# # Hmmm.. how to have two-stage creation without subclassing? -# #btn = wx.PreButton() -# #pre = wx.PreWindow() -# #self.PostCreate(pre) -# #if sys.platform == 'win32': -# # btn.Hide() -# #btn.Create(propgrid, wxpg.PG_SUBID2, '...', (x2-bw,pos[1]), (bw,h), wx.WANTS_CHARS) -# btn = wx.Button(propgrid, wxpg.PG_SUBID2, '...', (x2-bw,pos[1]), (bw,h), wx.WANTS_CHARS) -# return (lipc, btn) -# except: -# import traceback -# print traceback.print_exc() -# -# def UpdateControl(self, property, ctrl): -# ctrl.SetValue(property.GetDisplayedString()) -# -# def DrawValue(self, dc, property, rect): -# if not (property.GetFlags() & wxpg.PG_PROP_AUTO_UNSPECIFIED): -# dc.DrawText( property.GetDisplayedString(), rect.x+5, rect.y ); -# -# def OnEvent(self, propgrid, ctrl, event): -# if not ctrl: -# return False -# -# evtType = event.GetEventType() -# -# if evtType == wx.wxEVT_COMMAND_TEXT_ENTER: -# if propgrid.IsEditorsValueModified(): -# return True -# -# elif evtType == wx.wxEVT_COMMAND_TEXT_UPDATED: -# if not property.HasFlag(wxpg.PG_PROP_AUTO_UNSPECIFIED) or not ctrl or \ -# ctrl.GetLastPosition() > 0: -# -# # We must check this since an 'empty' text event -# # may be triggered when creating the property. -# PG_FL_IN_SELECT_PROPERTY = 0x00100000 -# if not (propgrid.GetInternalFlags() & PG_FL_IN_SELECT_PROPERTY): -# event.Skip(); -# event.SetId(propgrid.GetId()); -# -# propgrid.EditorsValueWasModified(); -# -# return False -# -# -# def CopyValueFromControl(self, property, ctrl): -# tc = ctrl.tc -# res = property.SetValueFromString(tc.GetValue(),0) -# # Changing unspecified always causes event (returning -# # true here should be enough to trigger it). -# if not res and property.IsFlagSet(wxpg.PG_PROP_AUTO_UNSPECIFIED): -# res = True -# -# return res -# -# def SetValueToUnspecified(self, ctrl): -# ctrl.tc.Remove(0,len(ctrl.tc.GetValue())); -# -# def SetControlStringValue(self, ctrl, txt): -# ctrl.SetValue(txt) -# -# def OnFocus(self, property, ctrl): -# ctrl.tc.SetSelection(-1,-1) -# ctrl.tc.SetFocus() +class PathProperty (StringProperty): + """Simple file or path property. + + Currently there isn't a fancy file-picker popup. Perhaps in the + future. + """ + def __init__(self, **kwargs): + super(PathProperty, self).__init__(**kwargs) + self.type = 'path' class PropertyPanel(Panel, wx.grid.Grid):