/[thuban]/trunk/thuban/Thuban/UI/classifier.py
ViewVC logotype

Diff of /trunk/thuban/Thuban/UI/classifier.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 429 by jonathan, Wed Feb 19 16:52:51 2003 UTC revision 430 by jonathan, Mon Feb 24 18:47:06 2003 UTC
# Line 90  class ClassTable(wxPyGridTableBase): Line 90  class ClassTable(wxPyGridTableBase):
90              clazz = Classification()              clazz = Classification()
91    
92          p = clazz.GetDefaultData()          p = clazz.GetDefaultData()
93          np = ClassDataPoint(classData = p)          np = ClassDataDefault(classData = p)
94          self.tdata.append([np, 'DEFAULT', np.GetLabel()])          self.tdata.append([np, 'DEFAULT', np.GetLabel()])
95    
96          for p in clazz.points.values():          for p in clazz.points.values():
# Line 211  class ClassTable(wxPyGridTableBase): Line 211  class ClassTable(wxPyGridTableBase):
211    
212                          self.tdata[row][COL_VISUAL] = data                          self.tdata[row][COL_VISUAL] = data
213    
214                          # i just want it to redraw!                          self.GetView().Refresh()
                         self.GetView().BeginBatch()  
                         self.GetView().EndBatch()  
215    
216          elif col == COL_LABEL:          elif col == COL_LABEL:
217              data.SetLabel(value)              data.SetLabel(value)
# Line 247  class ClassTable(wxPyGridTableBase): Line 245  class ClassTable(wxPyGridTableBase):
245          self.tdata.append([np, np.GetValue(), np.GetLabel()])          self.tdata.append([np, np.GetValue(), np.GetLabel()])
246          msg = wxGridTableMessage(self, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1)          msg = wxGridTableMessage(self, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1)
247          self.GetView().ProcessTableMessage(msg)          self.GetView().ProcessTableMessage(msg)
248          self.GetView().BeginBatch()          self.GetView().Refresh()
         self.GetView().EndBatch()  
249    
250  class Classifier(wxDialog):  class Classifier(wxDialog):
251            
# Line 397  class Classifier(wxDialog): Line 394  class Classifier(wxDialog):
394                  prop.SetStroke(new_prop.GetStroke())                  prop.SetStroke(new_prop.GetStroke())
395                  prop.SetStrokeWidth(new_prop.GetStrokeWidth())                  prop.SetStrokeWidth(new_prop.GetStrokeWidth())
396                  prop.SetFill(new_prop.GetFill())                  prop.SetFill(new_prop.GetFill())
397                  self.classGrid.BeginBatch()                  self.classGrid.Refresh()
                 self.classGrid.EndBatch()  
398              propDlg.Destroy()              propDlg.Destroy()
399    
400    
401  ID_SELPROP_OK = 4001  ID_SELPROP_OK = 4001
402  ID_SELPROP_CANCEL = 4002  ID_SELPROP_CANCEL = 4002
403  ID_SELPROP_SPINCTRL = 4002  ID_SELPROP_SPINCTRL = 4002
404    ID_SELPROP_PREVIEW = 4003
405    ID_SELPROP_STROKECLR = 4004
406    ID_SELPROP_FILLCLR = 4005
407    
408  class SelectPropertiesDialog(wxDialog):  class SelectPropertiesDialog(wxDialog):
409    
# Line 412  class SelectPropertiesDialog(wxDialog): Line 411  class SelectPropertiesDialog(wxDialog):
411          wxDialog.__init__(self, parent, -1, _("Select Properties"),          wxDialog.__init__(self, parent, -1, _("Select Properties"),
412                            style = wxRESIZE_BORDER)                            style = wxRESIZE_BORDER)
413    
         topBox = wxBoxSizer(wxVERTICAL)  
   
414          self.prop = ClassData(classData = prop)          self.prop = ClassData(classData = prop)
415    
416          topBox.Add(wxStaticText(self, -1, _("Stroke Color: ")),          topBox = wxBoxSizer(wxVERTICAL)
417              0, wxALIGN_LEFT | wxALL, 4)  
418            itemBox = wxBoxSizer(wxHORIZONTAL)
419    
420            # preview box
421            previewBox = wxBoxSizer(wxVERTICAL)
422            previewBox.Add(wxStaticText(self, -1, _("Preview:")),
423                0, wxALIGN_LEFT | wxALL, 4)
424            self.previewer = ClassDataPreviewer(None, self.prop, shapeType,
425                                                self, ID_SELPROP_PREVIEW, (40, 40))
426            previewBox.Add(self.previewer, 1, wxGROW, 15)
427    
428            itemBox.Add(previewBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
429    
430            # control box
431            ctrlBox = wxBoxSizer(wxVERTICAL)
432            ctrlBox.Add(
433                wxButton(self, ID_SELPROP_STROKECLR, "Change Stroke Color"),
434                0, wxALIGN_CENTER_HORIZONTAL | wxALL | wxGROW, 4)
435            EVT_BUTTON(self, ID_SELPROP_STROKECLR, self.OnChangeStrokeColor)
436    
437            if shapeType != SHAPETYPE_ARC:
438                ctrlBox.Add(
439                    wxButton(self, ID_SELPROP_FILLCLR, "Change Fill Color"),
440                    0, wxALIGN_LEFT | wxALL | wxGROW, 4)
441                EVT_BUTTON(self, ID_SELPROP_FILLCLR, self.OnChangeFillColor)
442    
443          spinBox = wxBoxSizer(wxHORIZONTAL)          spinBox = wxBoxSizer(wxHORIZONTAL)
444          spinBox.Add(wxStaticText(self, -1, _("Stroke Width: ")),          spinBox.Add(wxStaticText(self, -1, _("Stroke Width: ")),
445                  0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxBOTTOM, 4)                  0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4)
446          self.spinCtrl = wxSpinCtrl(self, ID_SELPROP_SPINCTRL,          self.spinCtrl = wxSpinCtrl(self, ID_SELPROP_SPINCTRL,
447                                     min=1, max=10,                                     min=1, max=10,
448                                     value=str(prop.GetStrokeWidth()),                                     value=str(prop.GetStrokeWidth()),
# Line 431  class SelectPropertiesDialog(wxDialog): Line 452  class SelectPropertiesDialog(wxDialog):
452    
453          spinBox.Add(self.spinCtrl, 0, wxALIGN_LEFT | wxALL, 4)          spinBox.Add(self.spinCtrl, 0, wxALIGN_LEFT | wxALL, 4)
454    
455          topBox.Add(spinBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10)          ctrlBox.Add(spinBox, 0, wxALIGN_RIGHT | wxALL, 0)
456            itemBox.Add(ctrlBox, 0, wxALIGN_RIGHT | wxALL | wxGROW, 0)
457            topBox.Add(itemBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0)
458    
         if shapeType != SHAPETYPE_ARC:  
             topBox.Add(wxStaticText(self, -1, _("Fill Color: ")),  
                 0, wxALIGN_LEFT | wxBOTTOM, 4)  
459    
460          #          #
461          # Control buttons:          # Control buttons:
# Line 463  class SelectPropertiesDialog(wxDialog): Line 483  class SelectPropertiesDialog(wxDialog):
483    
484      def OnSpin(self, event):      def OnSpin(self, event):
485          self.prop.SetStrokeWidth(self.spinCtrl.GetValue())          self.prop.SetStrokeWidth(self.spinCtrl.GetValue())
486            self.previewer.Refresh()
487    
488        def __GetColor(self, cur):
489            dialog = wxColourDialog(self)
490            dialog.GetColourData().SetColour(Color2wxColour(cur))
491            ret = None
492            if dialog.ShowModal() == wxID_OK:
493                ret = wxColour2Color(dialog.GetColourData().GetColour())
494    
495            dialog.Destroy()
496    
497            return ret
498            
499        def OnChangeStrokeColor(self, event):
500            clr = self.__GetColor(self.prop.GetStroke())
501            if clr is not None:
502                self.prop.SetStroke(clr)
503            self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer
504    
505        def OnChangeFillColor(self, event):
506            clr = self.__GetColor(self.prop.GetFill())
507            if clr is not None:
508                self.prop.SetFill(clr)
509            self.previewer.Refresh() # XXX: work around, see ClassDataPreviewer
510    
511      def GetClassData(self):      def GetClassData(self):
512          return self.prop          return self.prop
513    
514    
515  class ClassDataPreviewer:  class ClassDataPreviewer(wxWindow):
516    
517      def Draw(self, dc, rect, data, shapeType):      def __init__(self, rect, data, shapeType,
518                           parent = None, id = -1, size = wxDefaultSize):
519            if parent is not None:
520                wxWindow.__init__(self, parent, id, size=size)
521                EVT_PAINT(self, self.OnPaint)
522    
523            self.rect = rect
524            self.data = data
525            self.shapeType = shapeType
526    
527        def OnPaint(self, event):
528            dc = wxPaintDC(self)
529    
530            # XXX: this doesn't seem to be having an effect:
531            dc.DestroyClippingRegion()
532    
533            self.Draw(dc, None)
534    
535        def Draw(self, dc, rect, data = None, shapeType = None):
536    
537            if data is None: data = self.data
538            if shapeType is None: shapeType = self.shapeType
539    
540            if rect is None:
541                x = y = 0
542                w, h = self.GetClientSizeTuple()
543            else:
544                x = rect.GetX()
545                y = rect.GetY()
546                w = rect.GetWidth()
547                h = rect.GetHeight()
548    
549          stroke = data.GetStroke()          stroke = data.GetStroke()
550          if stroke is Color.None:          if stroke is Color.None:
551              pen = wxTRANSPARENT_PEN              pen = wxTRANSPARENT_PEN
552          else:          else:
553              pen = wxPen(wxColour(stroke.red * 255,              pen = wxPen(Color2wxColour(stroke),
                                  stroke.green * 255,  
                                  stroke.blue * 255),  
554                          data.GetStrokeWidth(),                          data.GetStrokeWidth(),
555                          wxSOLID)                          wxSOLID)
556    
# Line 486  class ClassDataPreviewer: Line 558  class ClassDataPreviewer:
558          if stroke is Color.None:          if stroke is Color.None:
559              brush = wxTRANSPARENT_BRUSH              brush = wxTRANSPARENT_BRUSH
560          else:          else:
561              brush = wxBrush(wxColour(stroke.red * 255,              brush = wxBrush(Color2wxColour(stroke), wxSOLID)
                                      stroke.green * 255,  
                                      stroke.blue * 255), wxSOLID)  
562    
563          dc.SetPen(pen)          dc.SetPen(pen)
564          dc.SetBrush(brush)          dc.SetBrush(brush)
565    
566          if shapeType == SHAPETYPE_ARC:          if shapeType == SHAPETYPE_ARC:
567              dc.DrawSpline([wxPoint(rect.GetX(), rect.GetY() + rect.GetHeight()),              dc.DrawSpline([wxPoint(x, y + h),
568                             wxPoint(rect.GetX() + rect.GetWidth()/2,                             wxPoint(x + w/2, y + h/4),
569                                     rect.GetY() + rect.GetHeight()/4),                             wxPoint(x + w/2, y + h/4*3),
570                             wxPoint(rect.GetX() + rect.GetWidth()/2,                             wxPoint(x + w, y)])
                                    rect.GetY() + rect.GetHeight()/4*3),  
                            wxPoint(rect.GetX() + rect.GetWidth(), rect.GetY())])  
571    
572          elif shapeType == SHAPETYPE_POINT or \          elif shapeType == SHAPETYPE_POINT or \
573               shapeType == SHAPETYPE_POLYGON:               shapeType == SHAPETYPE_POLYGON:
574    
575              dc.DrawCircle(rect.GetX() + rect.GetWidth()/2,              dc.DrawCircle(x + w/2, y + h/2,
576                            rect.GetY() + rect.GetHeight()/2,                            (min(w, h) - data.GetStrokeWidth())/2)
                           (min(rect.GetWidth(), rect.GetHeight())  
                            - data.GetStrokeWidth())/2)  
577    
578  class ClassRenderer(wxPyGridCellRenderer):  class ClassRenderer(wxPyGridCellRenderer):
579    
580      def __init__(self, shapeType):      def __init__(self, shapeType):
581          wxPyGridCellRenderer.__init__(self)          wxPyGridCellRenderer.__init__(self)
582          self.shapeType = shapeType          self.previewer = ClassDataPreviewer(None, None, shapeType)
583    
584      def Draw(self, grid, attr, dc, rect, row, col, isSelected):      def Draw(self, grid, attr, dc, rect, row, col, isSelected):
585          data = grid.GetTable().GetValueAsCustom(row, col, "")          data = grid.GetTable().GetValueAsCustom(row, col, "")
# Line 526  class ClassRenderer(wxPyGridCellRenderer Line 592  class ClassRenderer(wxPyGridCellRenderer
592          dc.DrawRectangle(rect.GetX(), rect.GetY(),          dc.DrawRectangle(rect.GetX(), rect.GetY(),
593                           rect.GetWidth(), rect.GetHeight())                           rect.GetWidth(), rect.GetHeight())
594    
595          ClassDataPreviewer().Draw(dc, rect, data, self.shapeType)          self.previewer.Draw(dc, rect, data)
596    
597          if isSelected:          if isSelected:
598              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),              dc.SetPen(wxPen(wxColour(0 * 255, 0 * 255, 0 * 255),

Legend:
Removed from v.429  
changed lines
  Added in v.430

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26