Example #1
0
    def __init__(self):
        wx.Menu.__init__(self)
        self.ID_TO_TOOL_ITEM = {}
        self.cdialog = None

        #------------ Sub menu of the window and level ----------
        submenu_wl = wx.Menu()

        self._gen_event = True

        #Window and level from DICOM
        new_id = self.id_wl_first = wx.NewId()
        wl_item = wx.MenuItem(submenu_wl, new_id,\
                            _('Default'), kind=wx.ITEM_RADIO)
        submenu_wl.AppendItem(wl_item)
        self.ID_TO_TOOL_ITEM[new_id] = wl_item

        #Case the user change window and level
        new_id = self.other_wl_id = wx.NewId()
        wl_item = wx.MenuItem(submenu_wl, new_id,\
                            _('Manual'), kind=wx.ITEM_RADIO)
        submenu_wl.AppendItem(wl_item)
        self.ID_TO_TOOL_ITEM[new_id] = wl_item

        for name in sorted(const.WINDOW_LEVEL):
            if not (name == _('Default') or name == _('Manual')):
                new_id = wx.NewId()
                wl_item = wx.MenuItem(submenu_wl, new_id,\
                                    name, kind=wx.ITEM_RADIO)
                submenu_wl.AppendItem(wl_item)
                self.ID_TO_TOOL_ITEM[new_id] = wl_item

        #----------- Sub menu of the save and load options ---------
        #submenu_wl.AppendSeparator()
        #options = [_("Save current values"),
        #           _("Save current values as..."),_("Load values")]

        #for name in options:
        #    new_id = wx.NewId()
        #    wl_item = wx.MenuItem(submenu_wl, new_id,\
        #                    name)
        #    submenu_wl.AppendItem(wl_item)
        #    self.ID_TO_TOOL_ITEM[new_id] = wl_item

        #------------ Sub menu of the pseudo colors ----------------
        if sys.platform.startswith('linux'):
            mkind = wx.ITEM_CHECK
        else:
            mkind = wx.ITEM_RADIO

        self.pseudo_color_items = {}
        submenu_pseudo_colours = wx.Menu()
        self.pseudo_color_items = {}
        new_id = self.id_pseudo_first = wx.NewId()
        color_item = wx.MenuItem(submenu_pseudo_colours, new_id,\
                            _("Default "), kind=mkind)
        submenu_pseudo_colours.AppendItem(color_item)
        color_item.Check(1)
        self.ID_TO_TOOL_ITEM[new_id] = color_item
        self.pseudo_color_items[new_id] = color_item

        for name in sorted(const.SLICE_COLOR_TABLE):
            if not (name == _("Default ")):
                new_id = wx.NewId()
                color_item = wx.MenuItem(submenu_wl, new_id,\
                                    name, kind=mkind)
                submenu_pseudo_colours.AppendItem(color_item)
                self.ID_TO_TOOL_ITEM[new_id] = color_item
                self.pseudo_color_items[new_id] = color_item

        self.plist_presets = presets.get_wwwl_presets()
        for name in sorted(self.plist_presets):
            new_id = wx.NewId()
            color_item = wx.MenuItem(submenu_wl, new_id, name, kind=mkind)
            submenu_pseudo_colours.AppendItem(color_item)
            self.ID_TO_TOOL_ITEM[new_id] = color_item
            self.pseudo_color_items[new_id] = color_item

        new_id = wx.NewId()
        color_item = wx.MenuItem(submenu_wl, new_id, _('Custom'), kind=mkind)
        submenu_pseudo_colours.AppendItem(color_item)
        self.ID_TO_TOOL_ITEM[new_id] = color_item
        self.pseudo_color_items[new_id] = color_item

        # --------------- Sub menu of the projection type ---------------------
        self.projection_items = {}
        submenu_projection = wx.Menu()
        for name in PROJECTIONS_ID:
            new_id = wx.NewId()
            projection_item = wx.MenuItem(submenu_projection,
                                          new_id,
                                          name,
                                          kind=wx.ITEM_RADIO)
            submenu_projection.AppendItem(projection_item)
            self.ID_TO_TOOL_ITEM[new_id] = projection_item
            self.projection_items[PROJECTIONS_ID[name]] = projection_item

        flag_tiling = False
        #------------ Sub menu of the image tiling ---------------
        submenu_image_tiling = wx.Menu()
        for name in sorted(const.IMAGE_TILING):
            new_id = wx.NewId()
            image_tiling_item = wx.MenuItem(submenu_image_tiling, new_id,\
                                name, kind=wx.ITEM_RADIO)
            submenu_image_tiling.AppendItem(image_tiling_item)
            self.ID_TO_TOOL_ITEM[new_id] = image_tiling_item

            #Save first id item
            if not (flag_tiling):
                self.id_tiling_first = new_id
                flag_tiling = True

        # Add sub itens in the menu
        self.AppendMenu(-1, _("Window width and level"), submenu_wl)
        self.AppendMenu(-1, _("Pseudo color"), submenu_pseudo_colours)
        self.AppendMenu(-1, _("Projection type"), submenu_projection)
        ###self.AppendMenu(-1, _("Image Tiling"), submenu_image_tiling)

        # It doesn't work in Linux
        self.Bind(wx.EVT_MENU, self.OnPopup)
        # In Linux the bind must be putted in the submenu
        if sys.platform.startswith('linux') or sys.platform == 'darwin':
            submenu_wl.Bind(wx.EVT_MENU, self.OnPopup)
            submenu_pseudo_colours.Bind(wx.EVT_MENU, self.OnPopup)
            submenu_image_tiling.Bind(wx.EVT_MENU, self.OnPopup)
            submenu_projection.Bind(wx.EVT_MENU, self.OnPopup)

        self.__bind_events()
Example #2
0
    def __init__(self):
        wx.Menu.__init__(self)
        self.ID_TO_TOOL_ITEM = {}
        self.cdialog = None

        #------------ Sub menu of the window and level ----------
        submenu_wl = wx.Menu()

        self._gen_event = True

        #Window and level from DICOM
        new_id = self.id_wl_first = wx.NewId()
        wl_item = wx.MenuItem(submenu_wl, new_id,\
                            _('Default'), kind=wx.ITEM_RADIO)
        submenu_wl.AppendItem(wl_item)
        self.ID_TO_TOOL_ITEM[new_id] = wl_item

        #Case the user change window and level
        new_id = self.other_wl_id = wx.NewId()
        wl_item = wx.MenuItem(submenu_wl, new_id,\
                            _('Manual'), kind=wx.ITEM_RADIO)
        submenu_wl.AppendItem(wl_item)
        self.ID_TO_TOOL_ITEM[new_id] = wl_item

        for name in sorted(const.WINDOW_LEVEL):
            if not(name == _('Default') or name == _('Manual')):
                new_id = wx.NewId()
                wl_item = wx.MenuItem(submenu_wl, new_id,\
                                    name, kind=wx.ITEM_RADIO)
                submenu_wl.AppendItem(wl_item)
                self.ID_TO_TOOL_ITEM[new_id] = wl_item

        #----------- Sub menu of the save and load options ---------
        #submenu_wl.AppendSeparator()
        #options = [_("Save current values"),
        #           _("Save current values as..."),_("Load values")]

        #for name in options:
        #    new_id = wx.NewId()
        #    wl_item = wx.MenuItem(submenu_wl, new_id,\
        #                    name)
        #    submenu_wl.AppendItem(wl_item)
        #    self.ID_TO_TOOL_ITEM[new_id] = wl_item


        #------------ Sub menu of the pseudo colors ----------------
        if sys.platform == 'linux2':
            mkind = wx.ITEM_CHECK
        else:
            mkind = wx.ITEM_RADIO

        self.pseudo_color_items = {}
        submenu_pseudo_colours = wx.Menu()
        self.pseudo_color_items = {}
        new_id = self.id_pseudo_first = wx.NewId()
        color_item = wx.MenuItem(submenu_pseudo_colours, new_id,\
                            _("Default "), kind=mkind)
        submenu_pseudo_colours.AppendItem(color_item)
        color_item.Check(1)
        self.ID_TO_TOOL_ITEM[new_id] = color_item
        self.pseudo_color_items[new_id] = color_item

        for name in sorted(const.SLICE_COLOR_TABLE):
            if not(name == _("Default ")):
                new_id = wx.NewId()
                color_item = wx.MenuItem(submenu_wl, new_id,\
                                    name, kind=mkind)
                submenu_pseudo_colours.AppendItem(color_item)
                self.ID_TO_TOOL_ITEM[new_id] = color_item
                self.pseudo_color_items[new_id] = color_item

        self.plist_presets = presets.get_wwwl_presets()
        for name in sorted(self.plist_presets):
            new_id = wx.NewId()
            color_item = wx.MenuItem(submenu_wl, new_id, name,
                                     kind=mkind)
            submenu_pseudo_colours.AppendItem(color_item)
            self.ID_TO_TOOL_ITEM[new_id] = color_item
            self.pseudo_color_items[new_id] = color_item

        new_id = wx.NewId()
        color_item = wx.MenuItem(submenu_wl, new_id, _('Custom'),
                                 kind=mkind)
        submenu_pseudo_colours.AppendItem(color_item)
        self.ID_TO_TOOL_ITEM[new_id] = color_item
        self.pseudo_color_items[new_id] = color_item

        # --------------- Sub menu of the projection type ---------------------
        self.projection_items = {}
        submenu_projection = wx.Menu()
        for name in PROJECTIONS_ID:
            new_id = wx.NewId()
            projection_item = wx.MenuItem(submenu_projection, new_id, name,
                                          kind=wx.ITEM_RADIO)
            submenu_projection.AppendItem(projection_item)
            self.ID_TO_TOOL_ITEM[new_id] = projection_item
            self.projection_items[PROJECTIONS_ID[name]] = projection_item
        
        flag_tiling = False
        #------------ Sub menu of the image tiling ---------------
        submenu_image_tiling = wx.Menu()
        for name in sorted(const.IMAGE_TILING):
            new_id = wx.NewId()
            image_tiling_item = wx.MenuItem(submenu_image_tiling, new_id,\
                                name, kind=wx.ITEM_RADIO)
            submenu_image_tiling.AppendItem(image_tiling_item)
            self.ID_TO_TOOL_ITEM[new_id] = image_tiling_item
            
            #Save first id item
            if not(flag_tiling):
                self.id_tiling_first = new_id
                flag_tiling = True

        # Add sub itens in the menu
        self.AppendMenu(-1, _("Window width and level"), submenu_wl)
        self.AppendMenu(-1, _("Pseudo color"), submenu_pseudo_colours)
        self.AppendMenu(-1, _("Projection type"), submenu_projection)
        ###self.AppendMenu(-1, _("Image Tiling"), submenu_image_tiling)

        # It doesn't work in Linux
        self.Bind(wx.EVT_MENU, self.OnPopup)
        # In Linux the bind must be putted in the submenu
        if sys.platform == 'linux2' or sys.platform == 'darwin':
            submenu_wl.Bind(wx.EVT_MENU, self.OnPopup)
            submenu_pseudo_colours.Bind(wx.EVT_MENU, self.OnPopup)
            submenu_image_tiling.Bind(wx.EVT_MENU, self.OnPopup)
            submenu_projection.Bind(wx.EVT_MENU, self.OnPopup)

        self.__bind_events()