[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8343 - in trunk/gnue-designer/src: forms/PagePainter forms/PageP
From: |
jcater |
Subject: |
[gnue] r8343 - in trunk/gnue-designer/src: forms/PagePainter forms/PagePainter/skins ui/wx/uihelpers/doccanvas |
Date: |
Mon, 3 Apr 2006 18:25:21 -0500 (CDT) |
Author: jcater
Date: 2006-04-03 14:53:03 -0500 (Mon, 03 Apr 2006)
New Revision: 8343
Added:
trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/textedit.py
Modified:
trunk/gnue-designer/src/forms/PagePainter/PagePainter.py
trunk/gnue-designer/src/forms/PagePainter/skins/common.py
trunk/gnue-designer/src/forms/PagePainter/skins/default.py
trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py
trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py
trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/widget.py
Log:
added a popup text editor; reorganized the mouse logic into separate functions;
misc widget implementations
Modified: trunk/gnue-designer/src/forms/PagePainter/PagePainter.py
===================================================================
--- trunk/gnue-designer/src/forms/PagePainter/PagePainter.py 2006-04-03
16:17:50 UTC (rev 8342)
+++ trunk/gnue-designer/src/forms/PagePainter/PagePainter.py 2006-04-03
19:53:03 UTC (rev 8343)
@@ -53,6 +53,20 @@
def init(self, object):
+ # Determine text extents
+ dc = wx.PaintDC(self)
+ dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
+
+ if not common.char_x_scale:
+ for char in string.digits + string.letters:
+ w, h = dc.GetTextExtent(char)
+ common.char_x_scale = max(common.char_x_scale, w)
+ common.char_y_scale = max(common.char_y_scale, h)
+
+ # Make the scale slightly larger, so that input widgets
+ # are bigger than text labels.
+ common.char_y_scale += 4
+
canvas = self.canvas = PagePainterCanvas(self)
self.document.app.ui.autoSizer(self, canvas)
@@ -69,21 +83,6 @@
'ObjectDeleted' : self.__objectDeleted,
})
- # Determine text extents
- dc = wx.PaintDC(self)
- dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
-
- if not common.char_x_scale:
- for char in string.digits + string.letters:
- w, h = dc.GetTextExtent(char)
- common.char_x_scale = max(common.char_x_scale, w)
- common.char_y_scale = max(common.char_y_scale, h)
-
- # Make the scale slightly larger, so that input widgets
- # are bigger than text labels.
- #common.char_x_scale += 4
- common.char_y_scale += 2
-
canvas.set_grid_scale(common.char_x_scale, common.char_y_scale)
# Draw initial objects
@@ -91,6 +90,9 @@
def inventory(self, object):
+ """
+ Inventory each object as it is identified or added
+ """
# Right now, we assume if an object has an x,y component, it is
drawable.
# This won't be true when we support layout management.
@@ -125,7 +127,7 @@
# ==========================================================================
-# SimpleCanvas implementations
+# DocumentCanvas implementations
# ==========================================================================
#
# These will be reorganized into a separate file once design is completed.
Modified: trunk/gnue-designer/src/forms/PagePainter/skins/common.py
===================================================================
--- trunk/gnue-designer/src/forms/PagePainter/skins/common.py 2006-04-03
16:17:50 UTC (rev 8342)
+++ trunk/gnue-designer/src/forms/PagePainter/skins/common.py 2006-04-03
19:53:03 UTC (rev 8343)
@@ -21,7 +21,7 @@
# $Id$
from gnue.designer.ui.wx.uihelpers.doccanvas.widget import DocumentWidget
-from gnue.designer.ui.wx.uihelpers.doccanvas.colors import colorIndex
+from gnue.designer.ui.wx.uihelpers.doccanvas.colors import color_map
import wx
@@ -32,8 +32,11 @@
char_x_scale = 0
char_y_scale = 0
-__all__ = ['FormWidget','char_x_scale', 'char_y_scale']
+__all__ = ['FormWidget','ContainerWidget', 'char_x_scale', 'char_y_scale']
+#--------------------------------------------------------------------------
+# Globals
+#--------------------------------------------------------------------------
class FormWidget(DocumentWidget):
"""
A DocumentWidget specific to the forms document type
@@ -114,3 +117,12 @@
# TODO: eventually, this will show tab-order icons
pass
+
+class ContainerWidget(FormWidget):
+ """
+ A widget that can be a container
+ """
+ container = True
+
+
+
\ No newline at end of file
Modified: trunk/gnue-designer/src/forms/PagePainter/skins/default.py
===================================================================
--- trunk/gnue-designer/src/forms/PagePainter/skins/default.py 2006-04-03
16:17:50 UTC (rev 8342)
+++ trunk/gnue-designer/src/forms/PagePainter/skins/default.py 2006-04-03
19:53:03 UTC (rev 8343)
@@ -25,18 +25,21 @@
Implement the default, simple GUI skin
"""
-from common import FormWidget
+import wx
+
+from gnue.designer.ui.wx.uihelpers.doccanvas.colors import color_map
+from common import FormWidget, ContainerWidget
import common
-from gnue.designer.ui.wx.uihelpers.doccanvas.colors import colorIndex
-import wx
-
# --------------------------------------------------------------------------
# form widgets
# --------------------------------------------------------------------------
def getWidgetSkinClass(object):
+ """
+ Given a GObject, return the FormWidget that will be used to draw it
+ """
if object._type == 'GFLabel':
cls = LabelWidget
elif object._type == 'GFEntry':
@@ -45,6 +48,8 @@
cls = PageWidget
elif object._type == 'GFBox':
cls = BoxWidget
+ elif object._type == 'GFButton':
+ cls = ButtonWidget
else:
cls = UnknownWidget
@@ -54,27 +59,27 @@
# --------------------------------------------------------------------------
# Page
# --------------------------------------------------------------------------
-class PageWidget(FormWidget):
+class PageWidget(ContainerWidget):
def calc_metrics(self):
canvas = self.canvas
object = self.gobject.findParentOfType('GFLayout')
- # This gives us an offset onto the current drawing canvas
+ # This gives us an offset onto the current drawing canvas,
# accounting for any workspace margins.
- documentX = canvas.document_origin_x
- documentY = canvas.document_origin_y
+ x_offset = canvas.document_origin_x
+ y_offset = canvas.document_origin_y
# Right now, only Char positioning is supported.
x = 0
y = 0
- w = object['Char:width']
- h = object['Char:height']
+ width = object['Char:width']
+ height = object['Char:height']
# Convert from Char positions into wx positions
- w *= common.char_x_scale
- h *= common.char_y_scale
+ width *= common.char_x_scale
+ height *= common.char_y_scale
# Used to figure in compensation needed for selection box
# decorations and borders
@@ -83,33 +88,33 @@
# Save the area, relative to the canvas, of the area
# that needs to be refreshed when this widget changes.
# (Includes all generic decoration, like selection borders)
- self.refresh_area = wx.Rect(x + documentX - compensation,
- y + documentY - compensation,
- w + compensation * 2,
- h + compensation * 2)
+ self.refresh_area = wx.Rect(x + x_offset - compensation,
+ y + y_offset - compensation,
+ width + compensation * 2,
+ height + compensation * 2)
# Save the area, relative to the canvas, of the area
# that the widget sans decorations occupy on the
- self.hit_test_area = wx.Rect(x + documentX,
- y + documentY,
- w, h)
+ self.hit_test_area = wx.Rect(x + x_offset,
+ y + y_offset,
+ width, height)
self.hit_test_exclusions = [
- wx.Rect(x + documentX+common.char_x_scale,
- y + documentY + common.char_y_scale,
- w - common.char_x_scale * 2,
- h - common.char_y_scale * 2) ]
+ wx.Rect(x + x_offset + common.char_x_scale,
+ y + y_offset + common.char_y_scale,
+ width - common.char_x_scale * 2,
+ height - common.char_y_scale * 2) ]
# Save the area, relative to being drawn in a context at (0,0)
- self.draw_area = wx.Rect(compensation, compensation, w, h)
+ self.draw_area = wx.Rect(compensation, compensation, width, height)
def draw_widget(self, dc):
- dc.SetPen(wx.Pen(colorIndex['widget']))
- dc.SetBrush(wx.Brush(colorIndex['panel'], style=wx.CROSSDIAG_HATCH))
+ dc.SetPen(wx.Pen(color_map['widget']))
+ dc.SetBrush(wx.Brush(color_map['panel'], style=wx.SOLID))
object = self.gobject
- x,y,w,h = self.draw_area.Get()
+ x, y, width, height = self.draw_area.Get()
dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
- dc.DrawRoundedRectangle(x,y,w,h, 4)
+ dc.DrawRectangle(x, y, width, height)
# --------------------------------------------------------------------------
@@ -120,55 +125,153 @@
char_max_height = 1
def draw_widget(self, dc):
- dc.SetPen(wx.Pen(colorIndex['text']))
+ dc.SetPen(wx.Pen(color_map['text']))
dc.SetBrush(wx.Brush(wx.WHITE, style=wx.TRANSPARENT))
object = self.gobject
- x, y, w, h = self.draw_area.Get()
+ x, y, width, height = self.draw_area.Get()
dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
# Center each character in its cell
- for char in object.text:
- cw, ch = dc.GetTextExtent(char)
+ for char in object['text']:
+ text_width, text_height = dc.GetTextExtent(char)
dc.DrawText(char,
- x + (common.char_x_scale - cw) // 2,
+ x + (common.char_x_scale - text_width) // 2,
y + 1)
x += common.char_x_scale
+ def enter_edit_mode(self):
+ """
+ Called when the user double-clicks to edit
+ """
+ object = self.gobject
+ x, y, width, height = self.hit_test_area.Get()
+ self.text_edit(x, y,
+ width,
+ common.char_y_scale,
+ self.gobject['text'])
+
+ def end_text_edit(self, text):
+ """
+ Called when the text edit request is finished
+ """
+ self.gobject['text'] = text
+ # TODO: issue an object change event
# --------------------------------------------------------------------------
# Entry
# --------------------------------------------------------------------------
class EntryWidget(FormWidget):
def draw_widget(self, dc):
- dc.SetPen(wx.Pen(colorIndex['widget']))
- dc.SetBrush(wx.Brush(colorIndex['widgetback']))
- x,y,w,h = self.draw_area.Get()
- dc.DrawRoundedRectangle(x,y,w,h, 1)
+ dc.SetPen(wx.Pen(color_map['widget']))
+ dc.SetBrush(wx.Brush(color_map['widgetback']))
+ x, y, width, height = self.draw_area.Get()
+ dc.DrawRectangle(x, y, width, height - 1)
# --------------------------------------------------------------------------
+# Button
+# --------------------------------------------------------------------------
+class ButtonWidget(FormWidget):
+ def draw_widget(self, dc):
+ dc.SetPen(wx.Pen(color_map['widget']))
+ dc.SetBrush(wx.Brush(color_map['widgetback']))
+ x, y, width, height = self.draw_area.Get()
+ dc.DrawRoundedRectangle(x, y, width, height - 1, 4)
+
+ # Draw the text, centered in the button
+ dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
+ text = self.gobject['label']
+ text_width, text_height = dc.GetTextExtent(text)
+
+ dc.DrawText(text,
+ x + width // 2 - text_width // 2,
+ y + height // 2 - text_height // 2 - 2)
+
+ def enter_edit_mode(self):
+ """
+ Called when the user double-clicks to edit
+ """
+ object = self.gobject
+ x, y, width, height = self.hit_test_area.Get()
+ self.text_edit(x, y,
+ width,
+ common.char_y_scale,
+ self.gobject['label'])
+
+ def end_text_edit(self, text):
+ """
+ Called when the text edit request is finished
+ """
+ self.gobject['label'] = text
+ # TODO: issue an object change event
+
+
+# --------------------------------------------------------------------------
# Box
# --------------------------------------------------------------------------
-class BoxWidget(FormWidget):
+class BoxWidget(ContainerWidget):
def draw_widget(self, dc):
- dc.SetPen(wx.Pen(colorIndex['text']))
+ dc.SetPen(wx.Pen(color_map['text']))
dc.SetBrush(wx.Brush(wx.WHITE, style=wx.TRANSPARENT))
object = self.gobject
- x,y,w,h = self.draw_area.Get()
+ x, y, width, height = self.draw_area.Get()
+
+ x1 = x + common.char_x_scale // 2 + 1
+ y1 = y + common.char_y_scale // 2 + 1
+ x2 = x + width - common.char_x_scale // 2
+ y2 = y + height - common.char_y_scale // 2
+
+ # Draw the lines
dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
- dc.DrawRoundedRectangle(x, y + common.char_y_scale // 2 + 1,
- w, h - common.char_y_scale, common.char_x_scale//3)
+ text = self.gobject['label']
+ text_width, text_height = text_extents = dc.GetTextExtent(text)
+ dc.SetPen(wx.Pen(color_map['widgetdark']))
+ dc.DrawLine(x1 + 1, y2, x2, y2) # Bottom
+ dc.DrawLine(x2, y1 + 1, x2, y2) # Right
+
+ dc.SetPen(wx.Pen(color_map['widgetlight']))
+ dc.DrawLine(x1, y1 + 1, x1, y2) # Left
+ dc.DrawLine(x1 + 1, # Top
+ y1, x + int(common.char_x_scale * 1.5) - 4, y1)
+ dc.DrawLine(x + int(common.char_x_scale * 1.5) + 3 + text_width,
+ y1, x2, y1)
+
+ # and draw the text
+ dc.SetPen(wx.Pen(color_map['text']))
+ dc.DrawText(text,
+ x + int(common.char_x_scale * 1.5),
+ y + common.char_y_scale // 2 - text_height // 2)
+
+ def enter_edit_mode(self):
+ """
+ Called when the user double-clicks to edit
+ """
+ object = self.gobject
+ x, y, width, height = self.hit_test_area.Get()
+ self.text_edit(x, y,
+ width - common.char_x_scale * 3,
+ common.char_y_scale,
+ self.gobject['label'])
+
+ def end_text_edit(self, text):
+ """
+ Called when the text edit request is finished
+ """
+ self.gobject['label'] = text
+ # TODO: issue an object change event
+
+
# --------------------------------------------------------------------------
# Unknown/unimplemented widgets
# --------------------------------------------------------------------------
class UnknownWidget(FormWidget):
def draw_widget(self, dc):
- dc.SetPen(wx.Pen(colorIndex['widget']))
- dc.SetBrush(wx.Brush(colorIndex['widget'], style=wx.CROSSDIAG_HATCH))
+ dc.SetPen(wx.Pen(color_map['widget']))
+ dc.SetBrush(wx.Brush(color_map['widget'], style=wx.CROSSDIAG_HATCH))
object = self.gobject
- x,y,w,h = self.draw_area.Get()
+ x, y, width, height = self.draw_area.Get()
dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT))
- dc.DrawRoundedRectangle(x,y,w,h, 4)
+ dc.DrawRoundedRectangle(x, y, width, height - 1, 4)
Modified: trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py
===================================================================
--- trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py 2006-04-03
16:17:50 UTC (rev 8342)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/canvas.py 2006-04-03
19:53:03 UTC (rev 8343)
@@ -25,7 +25,7 @@
import wx
-from colors import colorIndex, buildColorIndex
+from colors import color_map, build_color_map
cursor_map = {'resize-top': wx.CURSOR_SIZENS,
'resize-bottom': wx.CURSOR_SIZENS,
@@ -54,14 +54,21 @@
def __init__(self, *arguments, **keywords):
super(DocumentCanvas, self).__init__(*arguments, **keywords)
- if not colorIndex:
- buildColorIndex()
+ # Set up the color space
+ build_color_map()
self.ordered_widget_list = []
self.Bind(wx.EVT_PAINT, self.__wx_on_paint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.__wx_on_erase_background)
- self.Bind(wx.EVT_MOUSE_EVENTS, self.__wx_on_mouse_event)
+ self.Bind(wx.EVT_LEFT_DOWN, self.__wx_mouse_left_down)
+ self.Bind(wx.EVT_LEFT_UP, self.__wx_mouse_left_up)
+ self.Bind(wx.EVT_LEFT_DCLICK, self.__wx_mouse_left_double)
+ self.Bind(wx.EVT_RIGHT_DOWN, self.__wx_mouse_right_down)
+ self.Bind(wx.EVT_RIGHT_UP, self.__wx_mouse_right_up)
+ self.Bind(wx.EVT_RIGHT_DCLICK, self.__wx_mouse_right_double)
+ self.Bind(wx.EVT_MOTION, self.__wx_mouse_motion)
+ self.Bind(wx.EVT_MOUSEWHEEL, self.__wx_mouse_wheel)
# Screen refreshing
self.__selection_area = None
@@ -79,12 +86,15 @@
def __del__(self):
+ """
+ Cleanup
+ """
for item in self.ordered_widget_list:
item.Destroy()
self.ordered_widget_list = None
- def set_mouse_mode(self, mode='normal', function=None):
+ def set_behavior_mode(self, mode='normal', function=None):
"""
mode String that is one of:
@@ -341,7 +351,7 @@
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
dc.SetLogicalFunction(wx.XOR)
else:
- dc.SetPen(wx.Pen(colorIndex['selectionframe']))
+ dc.SetPen(wx.Pen(color_map['selectionframe']))
dc.DrawRectangle(x, y, w, h)
@@ -386,8 +396,8 @@
if self.grid_style == 1:
SOLIDSPACING = 4
w, h = self.GetClientSizeTuple()
- pen1 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SHORT_DASH)
- pen2 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
+ pen1 = wx.Pen(color_map['workspaceGrid'], 1, wx.SHORT_DASH)
+ pen2 = wx.Pen(color_map['workspaceGrid'], 1, wx.SOLID)
dc.SetPen(pen1)
# Draw vertical grid lines
@@ -416,8 +426,8 @@
elif self.grid_style == 2:
SOLIDSPACING = 4
w, h = self.GetClientSizeTuple()
- pen1 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
- pen2 = wx.Pen(colorIndex['workspaceGrid'], 1, wx.SOLID)
+ pen1 = wx.Pen(color_map['workspaceGrid'], 1, wx.SOLID)
+ pen2 = wx.Pen(color_map['workspaceGrid'], 1, wx.SOLID)
dc.SetPen(pen1)
@@ -451,154 +461,209 @@
# ---------------------------------------------------------------
# Mouse events
# ---------------------------------------------------------------
- def __wx_on_mouse_event(self, event):
+ def __wx_mouse_left_down(self, event):
"""
- Process any wx.MouseEvents
+ Left Button Clicked (down)
"""
- x, y = event.GetPositionTuple()
- x, y = self.CalcUnscrolledPosition(x, y)
+ x, y = self.CalcUnscrolledPosition(*event.GetPositionTuple())
mode = self.__mouse_mode
current_action = self.__mouse_current_action
- if event.Dragging():
- if mode == 'normal':
- if current_action == 'rubberband':
- self.__update_rubberband(x,y)
+ if mode == 'normal':
- elif current_action == 'move':
- self.__update_moving(x,y)
+ if not current_action:
+ # No previous action.
+ new_action = None
- elif current_action == 'resize':
- self.__update_resizing(x,y)
+ # Check to see if a currently selected area has been
+ # clicked, and whether it will be moved or resized:
+ for rect, action in self.__mouse_hot_spots:
+ if rect.InsideXY(x, y):
+ new_action = action
+ break
+ # Check to see if any widgets were clicked
+ if not new_action:
+ selected = self.select_hit_test(x, y)
+ if selected:
+ self.selected_from_canvas([selected])
+ new_action = 'move'
- elif event.Moving():
- cursor = None
- if mode == 'normal':
- if not current_action:
- # No previous action. Should we change the cursor?
- for rect, position in self.__mouse_hot_spots:
- if rect.InsideXY(x, y):
- cursor = cursor_map[position]
- break
- if not cursor:
- cursor = wx.CURSOR_ARROW
+ # Finally, assume we're creating a rubberband selector
+ if not new_action:
+ new_action = 'rubberband'
+ self.__start_rubberband(x, y)
- if cursor != self.__current_cursor:
- self.SetCursor(wx.StockCursor(cursor))
+ elif new_action == 'move':
+ self.__start_moving(x, y)
- return True
+ elif new_action.startswith('resize-'):
+ self.__start_resizing(x, y,
+ new_action.split('-')[1])
+ new_action = 'resize'
+ self.__mouse_current_action = new_action
- elif event.LeftDown():
+ return True
- if mode == 'normal':
- if not current_action:
- # No previous action.
- new_action = None
+ def __wx_mouse_left_up(self, event):
+ """
+ Left Button Released
+ """
+ x, y = self.CalcUnscrolledPosition(*event.GetPositionTuple())
- # Check to see if a currently selected area has been
- # clicked, and whether it will be moved or resized:
- for rect, action in self.__mouse_hot_spots:
- if rect.InsideXY(x, y):
- new_action = action
- break
+ mode = self.__mouse_mode
+ current_action = self.__mouse_current_action
- # Check to see if any widgets were clicked
- if not new_action:
- selected = self.select_hit_test(x, y)
- if selected:
- self.selected_from_canvas([selected])
- new_action = 'move'
+ if mode == 'normal':
- # Finally, assume we're creating a rubberband selector
- if not new_action:
- new_action = 'rubberband'
- self.__start_rubberband(x, y)
+ if current_action == 'rubberband':
+ area = self.__stop_rubberband(x, y)
+ # if their wasn't any drag action, treat it as
+ # a single click. Otherwise, as a drag.
+ if area.height > 2 or area.width > 2:
+ widgets = self.drag_hit_test(area)
+ else:
+ widget = self.select_hit_test(area.x, area.y)
+ widgets = widget and [widget] or []
+ self.selected_from_canvas(widgets)
- elif new_action == 'move':
- self.__start_moving(x, y)
+ elif current_action == 'move':
+ self.__stop_moving()
- elif new_action.startswith('resize-'):
- self.__start_resizing(x, y,
- new_action.split('-')[1])
- new_action = 'resize'
+ elif current_action == 'resize':
+ self.__stop_resizing()
- self.__mouse_current_action = new_action
+ self.__mouse_current_action = ''
- return True
+ return True
+ elif mode == 'picker':
+ widget = self.select_hit_test(x,y)
+ if widget:
+ widget.pick_from_canvas()
- elif event.LeftUp():
+ elif mode == 'edit':
+ widget = self.select_hit_test(x,y)
+ if widget:
+ self.widget_picked(widget)
- if mode == 'normal':
+ elif mode == 'create':
+ pass
- if current_action == 'rubberband':
- area = self.__stop_rubberband(x, y)
- # if their wasn't any drag action, treat it as
- # a single click. Otherwise, as a drag.
- if area.height > 2 or area.width > 2:
- widgets = self.drag_hit_test(area)
- else:
- widget = self.select_hit_test(area.x, area.y)
- widgets = widget and [widget] or []
- self.selected_from_canvas(widgets)
+ elif mode == 'delete':
+ pass
- elif current_action == 'move':
- self.__stop_moving()
+ return True
+
+ def __wx_mouse_left_double(self, event):
+ """
+ Left Button double-clicked
+ """
+ x, y = self.CalcUnscrolledPosition(*event.GetPositionTuple())
- elif current_action == 'resize':
- self.__stop_resizing()
+ mode = self.__mouse_mode
+ current_action = self.__mouse_current_action
- self.__mouse_current_action = ''
+ if mode == 'normal':
+ widget = self.select_hit_test(x, y)
+ if widget:
+ widget.enter_edit_mode()
- return True
+ return True
+
+
+ def __wx_mouse_right_down(self, event):
+ """
+ Right Button Clicked (down)
+ """
+ x, y = self.CalcUnscrolledPosition(*event.GetPositionTuple())
- elif mode == 'picker':
- widget = self.select_hit_test(x,y)
- if widget:
- widget.pick_from_canvas()
+ mode = self.__mouse_mode
+ current_action = self.__mouse_current_action
- elif mode == 'edit':
- widget = self.select_hit_test(x,y)
- if widget:
- self.widget_picked(widget)
+ return True
- elif mode == 'create':
- pass
+ def __wx_mouse_right_up(self, event):
+ """
+ Right Button Released
+ """
+ x, y = self.CalcUnscrolledPosition(*event.GetPositionTuple())
- elif mode == 'delete':
- pass
+ mode = self.__mouse_mode
+ current_action = self.__mouse_current_action
- return False
+ return True
- # ---------------------------------------------------------------
- # Hit Tests
- # ---------------------------------------------------------------
- def select_hit_test(self, x, y):
+ def __wx_mouse_right_double(self, event):
"""
- Return the first widget at a point
+ Right Button double-clicked
"""
- for widget in self.ordered_widget_list:
- if widget.select_hit_test(x,y):
- return widget
- return None
+ x, y = self.CalcUnscrolledPosition(*event.GetPositionTuple())
+ mode = self.__mouse_mode
+ current_action = self.__mouse_current_action
- def drag_hit_test(self, area):
+ return True
+
+
+ def __wx_mouse_motion(self, event):
"""
- Return a list of all widgets in a rectangle
+ Mouse cursor moved
"""
- widgets = []
- append = widgets.append
- for widget in self.ordered_widget_list:
- if widget.drag_hit_test(area):
- append(widget)
- return widgets
+ x, y = self.CalcUnscrolledPosition(*event.GetPositionTuple())
+ mode = self.__mouse_mode
+ current_action = self.__mouse_current_action
+
+ if event.Dragging():
+ if mode == 'normal':
+ if current_action == 'rubberband':
+ self.__update_rubberband(x,y)
+
+ elif current_action == 'move':
+ self.__update_moving(x,y)
+
+ elif current_action == 'resize':
+ self.__update_resizing(x,y)
+
+
+ else:
+ cursor = None
+ if mode == 'normal':
+ if not current_action:
+ # No previous action. Should we change the cursor?
+ for rect, position in self.__mouse_hot_spots:
+ if rect.InsideXY(x, y):
+ cursor = cursor_map[position]
+ break
+ if not cursor:
+ cursor = wx.CURSOR_ARROW
+
+ if cursor != self.__current_cursor:
+ self.SetCursor(wx.StockCursor(cursor))
+
+ return True
+
+ return True
+
+ def __wx_mouse_wheel(self, event):
+ """
+ Mouse wheel scrolled
+ """
+ x, y = self.CalcUnscrolledPosition(*event.GetPositionTuple())
+
+ mode = self.__mouse_mode
+ current_action = self.__mouse_current_action
+
+ # TODO: Scroll the workspace
+
+ return True
+
+
# ---------------------------------------------------------------
# Get all selected widgets
# ---------------------------------------------------------------
@@ -898,6 +963,31 @@
# Misc management stuff
# ---------------------------------------------------------------
+ # ---------------------------------------------------------------
+ # Hit Tests
+ # ---------------------------------------------------------------
+ def select_hit_test(self, x, y):
+ """
+ Return the first widget at a point
+ """
+ for widget in self.ordered_widget_list:
+ if widget.select_hit_test(x,y):
+ return widget
+ return None
+
+
+ def drag_hit_test(self, area):
+ """
+ Return a list of all widgets in a rectangle
+ """
+ widgets = []
+ append = widgets.append
+ for widget in self.ordered_widget_list:
+ if widget.drag_hit_test(area):
+ append(widget)
+ return widgets
+
+
def deselect_all(self):
"""
Mark all selected objects as not selected. Only Refresh the objects
Modified: trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py
===================================================================
--- trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py 2006-04-03
16:17:50 UTC (rev 8342)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/colors.py 2006-04-03
19:53:03 UTC (rev 8343)
@@ -27,24 +27,29 @@
import wx
-colorIndex = {}
-def buildColorIndex():
- colorIndex['selectionframe'] = wx.BLUE #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
- colorIndex['selectedframe'] = wx.BLUE #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
- colorIndex['workspace'] =
wx.SystemSettings_GetColour(wx.SYS_COLOUR_APPWORKSPACE)
- colorIndex['workspaceGrid'] = wx.Colour(240,240,240) # TODO: ???
- colorIndex['panel'] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BACKGROUND)
- colorIndex['text'] = wx.BLACK
- colorIndex['widget'] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWFRAME)
- colorIndex['widgetback'] = wx.WHITE
+color_map = {}
-def buildTermColorIndex():
- colorIndex['selectionframe'] = wx.BLUE #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
- colorIndex['selectedframe'] = wx.BLUE #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
- colorIndex['workspace'] =
wx.SystemSettings_GetColour(wx.SYS_COLOUR_APPWORKSPACE)
- colorIndex['workspaceGrid'] = wx.Colour(240,240,240) # TODO: ???
- colorIndex['panel'] = wx.BLACK
- colorIndex['text'] = wx.WHITE
- colorIndex['widget'] = wx.TRANSPARENT
- colorIndex['widgetback'] = wx.WHITE
-
\ No newline at end of file
+def build_color_map():
+ if color_map:
+ return
+ color_map['selectionframe'] = wx.BLUE #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DHILIGHT)
+ color_map['selectedframe'] = wx.BLUE #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_HOTLIGHT)
+ color_map['workspace'] =
wx.SystemSettings_GetColour(wx.SYS_COLOUR_APPWORKSPACE)
+ color_map['workspaceGrid'] = wx.Colour(240,240,240) # TODO: ???
+ color_map['panel'] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)
+ color_map['text'] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT)
+ color_map['widget'] = wx.BLACK #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWFRAME)
+ color_map['widgetdark'] =
wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DSHADOW)
+ color_map['widgetlight'] =
wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DLIGHT)
+ color_map['widgetback'] = wx.WHITE
+
+def buildTermcolor_map():
+ color_map['selectionframe'] = wx.BLUE #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
+ color_map['selectedframe'] = wx.BLUE #
wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
+ color_map['workspace'] =
wx.SystemSettings_GetColour(wx.SYS_COLOUR_APPWORKSPACE)
+ color_map['workspaceGrid'] = wx.Colour(240,240,240) # TODO: ???
+ color_map['panel'] = wx.BLACK
+ color_map['text'] = wx.WHITE
+ color_map['widget'] = wx.TRANSPARENT
+ color_map['widgetback'] = wx.WHITE
+
Added: trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/textedit.py
===================================================================
--- trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/textedit.py
2006-04-03 16:17:50 UTC (rev 8342)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/textedit.py
2006-04-03 19:53:03 UTC (rev 8343)
@@ -0,0 +1,76 @@
+#
+# Copyright 2001-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise 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, or (at your option) any later version.
+#
+# GNU Enterprise 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 program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+import wx
+
+#
+# Our text handler
+#
+# When we are completed, we will call a method passed to us
+# (via complete) along with a success code and the final result
+# (if success = 1)
+#
+class PopupTextEdit(wx.TextCtrl):
+ def __init__(self, panel, complete, x, y, width, height, value):
+ wx.TextCtrl.__init__(self, panel, -1, pos=wx.Point(x,y),
+ size=wx.Size(width,height),
+ style=wx.TE_PROCESS_TAB|wx.TE_PROCESS_ENTER|wx.SIMPLE_BORDER)
+ self.SetBackgroundColour(wx.Colour(255,239,176))
+ self.__complete = complete
+ self.SetValue(value)
+ self.Bind(wx.EVT_CHAR, self.__wx_on_char)
+ self.Bind(wx.EVT_KILL_FOCUS, self.__wx_focus_out)
+
+
+ def done(self, success):
+ if self.__complete:
+
+ self.__wx_focus_out = self.__dummy
+
+ if success:
+ self.__complete(1, self.GetValue())
+ else:
+ self.__complete(0)
+
+ self.Destroy()
+
+
+ def __wx_on_char(self, event):
+ if event.GetKeyCode() in (wx.WXK_RETURN,wx.WXK_TAB):
+ self.done(1)
+ elif event.GetKeyCode() == wx.WXK_ESCAPE:
+ self.done(0)
+ else:
+ event.Skip()
+
+
+ def __wx_focus_out(self, event):
+ self.done(1)
+
+
+ def __dummy(self, event):
+ event.Skip()
+
+
+ def Destroy(self, *args, **parms):
+ self.__complete = None
+ wx.TextCtrl.Destroy(self, *args, **parms)
Property changes on:
trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/textedit.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/widget.py
===================================================================
--- trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/widget.py 2006-04-03
16:17:50 UTC (rev 8342)
+++ trunk/gnue-designer/src/ui/wx/uihelpers/doccanvas/widget.py 2006-04-03
19:53:03 UTC (rev 8343)
@@ -25,7 +25,8 @@
import wx
import dnd
-from colors import colorIndex
+from colors import color_map
+from textedit import PopupTextEdit
# ===================================================================
# A Drawable canvas widget
@@ -178,6 +179,17 @@
self.draw_decorations(dc)
+ def text_edit(self, x, y, width, height, text, multiline=False):
+ PopupTextEdit(self.canvas, self.__end_text_edit, x, y,
+ width, height, text).SetFocus()
+
+
+ def __end_text_edit(self, success, text=None):
+ if success:
+ self.end_text_edit(text)
+ else:
+ self.cancel_text_edit()
+
# ====================================================================
# You can implement the following functions, but usually won't need to
# ====================================================================
@@ -195,7 +207,7 @@
"""
x, y, w, h = self.hit_test_area.Get()
dc.SetBrush(wx.Brush(wx.BLACK, wx.TRANSPARENT))
- dc.SetPen(wx.Pen(colorIndex['selectedframe']))
+ dc.SetPen(wx.Pen(color_map['selectedframe']))
dc.DrawRectangle(3, 3, w + 2, h + 2)
@@ -266,7 +278,6 @@
"""
self.set_selected()
-
# ====================================================================
# You *must* implement the following functions
# ====================================================================
@@ -284,3 +295,52 @@
"""
assert(False)
+
+ def enter_edit_mode(self):
+ """
+ Called when the user has asked to "edit" the widget, by
+ double-clicking or pressing the equivalent hotkey.
+
+ On widgets with text, this usually switches to an input box
+ letting the user edit the text.
+
+ If your widget has no concept of being editable, then
+ you can leave this method as-is.
+ """
+ pass
+
+
+ def validate_text_edit(self, text):
+ """
+ Called when self.text_edit() has been called in your code, and
+ the user has saved their edited changes.
+
+ You should return True or False depending on if their
+ entered value is considered valid. If you return True,
+ then end_text_edit() is immediately called. Otherwise,
+ the user is warned.
+ """
+
+ return True
+
+ def end_text_edit(self, text):
+ """
+ Called when self.text_edit() has been called in your code, and
+ the user has saved their edited changes.
+
+ If you never call self.text_edit(), there's no need to
+ implement this method.
+ """
+ assert(False)
+
+ def cancel_text_edit(self, text):
+ """
+ Called when self.text_edit() has been called in your code, and
+ the user has canceled the edit.
+
+ If you never call self.text_edit(), there's no need to
+ implement this method.
+
+ Usually, there is no need for anything more than a NO-OP.
+ """
+ pass
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8343 - in trunk/gnue-designer/src: forms/PagePainter forms/PagePainter/skins ui/wx/uihelpers/doccanvas,
jcater <=