diff --git a/.gitattributes b/.gitattributes index 979a516..9c63074 100644 --- a/.gitattributes +++ b/.gitattributes @@ -140,6 +140,7 @@ invesalius/gui/task_surface.py -text invesalius/gui/task_tools.py -text invesalius/gui/widgets/__init__.py -text invesalius/gui/widgets/clut_raycasting.py -text +invesalius/gui/widgets/colourselect.py -text invesalius/gui/widgets/foldpanelbar.py -text invesalius/gui/widgets/gradient.py -text invesalius/gui/widgets/listctrl.py -text diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index 1e0edcd..1583820 100755 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -301,8 +301,9 @@ class VolumeInteraction(wx.Panel): import wx.lib.platebtn as pbtn import wx.lib.buttons as btn import wx.lib.pubsub as ps -import wx.lib.colourselect as csel + import constants as const +import widgets.colourselect as csel [BUTTON_RAYCASTING, BUTTON_VIEW, BUTTON_SLICE_PLANE] = [wx.NewId() for num in xrange(3)] RAYCASTING_TOOLS = wx.NewId() @@ -345,7 +346,7 @@ class VolumeToolPanel(wx.Panel): button_slice_plane = self.button_slice_plane = pbtn.PlateButton(self, BUTTON_SLICE_PLANE,"", BMP_SLICE_PLANE, style=pbtn.PB_STYLE_SQUARE, size=(24,24)) - + self.button_raycasting = button_raycasting # VOLUME VIEW ANGLE BUTTON @@ -402,7 +403,7 @@ class VolumeToolPanel(wx.Panel): def OnButtonView(self, evt): self.button_view.PopupMenu(self.menu_view) - + def OnButtonSlicePlane(self, evt): self.button_slice_plane.PopupMenu(self.slice_plane_menu) @@ -455,21 +456,21 @@ class VolumeToolPanel(wx.Panel): menu.AppendItem(item) menu.Bind(wx.EVT_MENU, self.OnMenuView) self.menu_view = menu - + #SLICE PLANES BUTTON self.slice_plane_menu = slice_plane_menu = wx.Menu() itens = ["Axial", "Coronal", "Sagital"] - + for value in itens: new_id = wx.NewId() - - item = wx.MenuItem(slice_plane_menu, new_id, value, + + item = wx.MenuItem(slice_plane_menu, new_id, value, kind = wx.ITEM_CHECK) ID_TO_ITEMSLICEMENU[new_id] = item slice_plane_menu.AppendItem(item) - + slice_plane_menu.Bind(wx.EVT_MENU, self.OnMenuPlaneSlice) - + self.Fit() self.Update() @@ -479,20 +480,20 @@ class VolumeToolPanel(wx.Panel): presets += [filename.split(".")[0] for filename in os.listdir(folder) if os.path.isfile(os.path.join(folder,filename))] - + def OnMenuPlaneSlice(self, evt): - + id = evt.GetId() item = ID_TO_ITEMSLICEMENU[id] checked = item.IsChecked() label = item.GetLabel() - + if not (checked): ps.Publisher().sendMessage('Disable plane', label) else: ps.Publisher().sendMessage('Enable plane', label) - + def ChangeButtonColour(self, pubsub_evt): colour = [i*255 for i in pubsub_evt.data] self.button_colour.SetColour(colour) diff --git a/invesalius/gui/task_slice.py b/invesalius/gui/task_slice.py index acbac8d..5a5f6fd 100644 --- a/invesalius/gui/task_slice.py +++ b/invesalius/gui/task_slice.py @@ -20,7 +20,6 @@ import sys import wx -import wx.lib.colourselect as csel import wx.lib.hyperlink as hl import wx.lib.platebtn as pbtn import wx.lib.pubsub as ps @@ -29,6 +28,8 @@ import data.mask as mask import constants as const import gui.widgets.gradient as grad import gui.widgets.foldpanelbar as fpb +import widgets.colourselect as csel + from project import Project BTN_NEW = wx.NewId() @@ -207,7 +208,7 @@ class InnerFoldPanel(wx.Panel): leftSpacing=0, rightSpacing=0) self.__id_editor = item.GetId() self.last_panel_opened = None - + #fold_panel.Expand(fold_panel.GetFoldPanel(1)) # Panel sizer to expand fold panel @@ -226,15 +227,15 @@ class InnerFoldPanel(wx.Panel): def __bind_evt(self): self.fold_panel.Bind(fpb.EVT_CAPTIONBAR, self.OnFoldPressCaption) - + def __bind_pubsub_evt(self): ps.Publisher().subscribe(self.OnRetrieveStyle, 'Retrieve task slice style') ps.Publisher().subscribe(self.OnDisableStyle, 'Disable task slice style') - + def OnFoldPressCaption(self, evt): id = evt.GetTag().GetId() closed = evt.GetFoldStatus() - + if self.__id_editor == id: if closed: ps.Publisher().sendMessage('Disable style', const.SLICE_STATE_EDITOR) @@ -245,7 +246,7 @@ class InnerFoldPanel(wx.Panel): else: ps.Publisher().sendMessage('Disable style', const.SLICE_STATE_EDITOR) self.last_style = None - + evt.Skip() def OnRetrieveStyle(self, pubsub_evt): @@ -344,7 +345,7 @@ class MaskProperties(wx.Panel): n = self.combo_thresh.GetCount() for i in xrange(n-1, -1, -1): self.combo_thresh.Delete(i) - + def __bind_events_wx(self): self.Bind(grad.EVT_THRESHOLD_CHANGE, self.OnSlideChanged, self.gradient) @@ -397,7 +398,7 @@ class MaskProperties(wx.Panel): else: self.combo_thresh.SetSelection(3) thresh_min, thresh_max = default_thresh - + self.gradient.SetMinValue(thresh_min) self.gradient.SetMaxValue(thresh_max) diff --git a/invesalius/gui/task_surface.py b/invesalius/gui/task_surface.py index 8ec21ff..8d87d41 100644 --- a/invesalius/gui/task_surface.py +++ b/invesalius/gui/task_surface.py @@ -19,12 +19,12 @@ import sys import wx -import wx.lib.colourselect as csel import wx.lib.hyperlink as hl import wx.lib.platebtn as pbtn import wx.lib.pubsub as ps import gui.widgets.foldpanelbar as fpb +import widgets.colourselect as csel #INTERPOLATION_MODE_LIST = ["Cubic", "Linear", "NearestNeighbor"] QUALITY_LIST = [_("Low"), _("Medium"), _("High"), _("Optimal *"), _("Custom")] diff --git a/invesalius/gui/widgets/colourselect.py b/invesalius/gui/widgets/colourselect.py new file mode 100644 index 0000000..a9d8c19 --- /dev/null +++ b/invesalius/gui/widgets/colourselect.py @@ -0,0 +1,176 @@ +#---------------------------------------------------------------------------- +# Name: ColourSelect.py +# Purpose: Colour Box Selection Control +# +# Author: Lorne White, Lorne.White@telusplanet.net +# +# Created: Feb 25, 2001 +# Licence: wxWindows license +#---------------------------------------------------------------------------- + +# creates a colour wxButton with selectable color +# button click provides a colour selection box +# button colour will change to new colour +# GetColour method to get the selected colour + +# Updates: +# call back to function if changes made + +# Cliff Wells, logiplexsoftware@earthlink.net: +# - Made ColourSelect into "is a button" rather than "has a button" +# - Added label parameter and logic to adjust the label colour according to the background +# colour +# - Added id argument +# - Rearranged arguments to more closely follow wx conventions +# - Simplified some of the code + +# Cliff Wells, 2002/02/07 +# - Added ColourSelect Event + +# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for 2.5 compatability. +# + +""" +Provides a `ColourSelect` button that, when clicked, will display a +colour selection dialog. The selected colour is displayed on the +button itself. +""" + +#---------------------------------------------------------------------------- + +import wx + +#---------------------------------------------------------------------------- + +wxEVT_COMMAND_COLOURSELECT = wx.NewEventType() + +class ColourSelectEvent(wx.PyCommandEvent): + def __init__(self, id, value): + wx.PyCommandEvent.__init__(self, id = id) + self.SetEventType(wxEVT_COMMAND_COLOURSELECT) + self.value = value + + def GetValue(self): + return self.value + +EVT_COLOURSELECT = wx.PyEventBinder(wxEVT_COMMAND_COLOURSELECT, 1) + +#---------------------------------------------------------------------------- + +class ColourSelect(wx.BitmapButton): + def __init__(self, parent, id=wx.ID_ANY, label="", colour=wx.BLACK, + pos=wx.DefaultPosition, size=wx.DefaultSize, + callback=None, style=0): + if label: + w, h = parent.GetTextExtent(label) + w += 6 + h += 6 + else: + w, h = 20, 20 + wx.BitmapButton.__init__(self, parent, id, wx.EmptyBitmap(w,h), + pos=pos, size=size, style=style|wx.BU_AUTODRAW) + + if type(colour) == type( () ): + colour = wx.Colour(*colour) + self.colour = colour + self.SetLabel(label) + self.callback = callback + bmp = self.MakeBitmap() + self.SetBitmap(bmp) + parent.Bind(wx.EVT_BUTTON, self.OnClick, self) + + + def GetColour(self): + return self.colour + + def GetValue(self): + return self.colour + + def SetValue(self, colour): + self.SetColour(colour) + + def SetColour(self, colour): + if type(colour) == tuple: + colour = wx.Colour(*colour) + if type(colour) == str: + colour = wx.NamedColour(colour) + + self.colour = colour + bmp = self.MakeBitmap() + self.SetBitmap(bmp) + + + def SetLabel(self, label): + self.label = label + + def GetLabel(self): + return self.label + + + def MakeBitmap(self): + bdr = 8 + width, height = self.GetSize() + + # yes, this is weird, but it appears to work around a bug in wxMac + if "wxMac" in wx.PlatformInfo and width == height: + height -= 1 + + bmp = wx.EmptyBitmap(width-bdr, height-bdr) + dc = wx.MemoryDC() + dc.SelectObject(bmp) + dc.SetFont(self.GetFont()) + label = self.GetLabel() + # Just make a little colored bitmap + dc.SetBackground(wx.Brush(self.colour)) + dc.Clear() + + if label: + # Add a label to it + avg = reduce(lambda a, b: a + b, self.colour.Get()) / 3 + fcolour = avg > 128 and wx.BLACK or wx.WHITE + dc.SetTextForeground(fcolour) + dc.DrawLabel(label, (0,0, width-bdr, height-bdr), + wx.ALIGN_CENTER) + + dc.SelectObject(wx.NullBitmap) + return bmp + + + def SetBitmap(self, bmp): + self.SetBitmapLabel(bmp) + #self.SetBitmapSelected(bmp) + #self.SetBitmapDisabled(bmp) + #self.SetBitmapFocus(bmp) + #self.SetBitmapSelected(bmp) + self.Refresh() + + + def OnChange(self): + evt = ColourSelectEvent(self.GetId(), self.GetValue()) + evt.SetEventObject(self) + wx.PostEvent(self, evt) + if self.callback is not None: + self.callback() + + def OnClick(self, event): + data = wx.ColourData() + data.SetChooseFull(True) + data.SetColour(self.colour) + dlg = wx.ColourDialog(wx.GetTopLevelParent(self), data) + + try: + changed = dlg.ShowModal() == wx.ID_OK + except(wx._core.PyAssertionError): + changed = True + + if changed: + data = dlg.GetColourData() + self.SetColour(data.GetColour()) + dlg.Destroy() + + # moved after dlg.Destroy, since who knows what the callback will do... + if changed: + self.OnChange() + -- libgit2 0.21.2