<commit_before>from AppKit import NSPopUpButton, NSPopUpButtonCell
from vanillaBase import VanillaBaseControl


class PopUpButton(VanillaBaseControl):
    
    """
    A button which, when selected, displays a list of items for the user to choose from.

    pre.
    from vanilla import *
     
    class PopUpButtonDemo(object):
        
        def __init__(self):
            self.w = Window((100, 40))
            self.w.popUpButton = PopUpButton((10, 10, -10, 20),
                                  ["A", "B", "C"],
                                  callback=self.popUpButtonCallback)
            self.w.open()
            
        def popUpButtonCallback(self, sender):
            print "pop up button selection!", sender.get()
            
    PopUpButtonDemo()
    """

    nsPopUpButtonClass = NSPopUpButton
    nsPopUpButtonCellClass = NSPopUpButtonCell

    frameAdjustments = {
        "mini": (-1, 0, 3, 0),
        "small": (-3, -4, 6, 5),
        "regular": (-3, -4, 6, 6),
    }

    def __init__(self, posSize, items, callback=None, sizeStyle="regular"):
        """
        *posSize* Tuple of form (left, top, width, height) representing the position and size of the pop up button. The size of the button sould match the appropriate value for the given _sizeStyle_.

        |\\3. *Standard Dimensions* |
        | Regular | H | 20          |
        | Small   | H | 17          |
        | Mini    | H | 15          |

        *items* A list of items to appear in the pop up list.

        *callback* The method to be called when the user selects an item in the pop up list.

        *sizeStyle* A string representing the desired size style of the pop up button. The options are:

        | "regular" |
        | "small"   |
        | "mini"    |
        """
        self._setupView(self.nsPopUpButtonClass, posSize)
        if self.nsPopUpButtonCellClass != NSPopUpButtonCell:
            self._nsObject.setCell_(self.nsPopUpButtonCellClass.alloc().init())
        if callback is not None:
            self._setCallback(callback)
        self._setSizeStyle(sizeStyle)
        self._nsObject.addItemsWithTitles_(items)

    def getNSPopUpButton(self):
        """
        Return the _NSPopUpButton_ that this object wraps.
        """
        return self._nsObject

    def get(self):
        """
        Get the index selected item in the pop up list.
        """
        return self._nsObject.indexOfSelectedItem()

    def set(self, value):
        """
        Set the index of the selected item in the pop up list.
        """
        self._nsObject.selectItemAtIndex_(value)

    def setItems(self, items):
        """
        Set the items to appear in the pop up list.
        """
        self._nsObject.removeAllItems()
        self._nsObject.addItemsWithTitles_(items)

    def getItems(self):
        """
        Get the list of items that appear in the pop up list.
        """
        return self._nsObject.itemTitles()
<commit_msg>Allow the addition os NSMenutItem objects.<commit_after>from AppKit import NSPopUpButton, NSPopUpButtonCell, NSMenuItem
from vanillaBase import VanillaBaseControl


class PopUpButton(VanillaBaseControl):
    
    """
    A button which, when selected, displays a list of items for the user to choose from.

    pre.
    from vanilla import *
     
    class PopUpButtonDemo(object):
        
        def __init__(self):
            self.w = Window((100, 40))
            self.w.popUpButton = PopUpButton((10, 10, -10, 20),
                                  ["A", "B", "C"],
                                  callback=self.popUpButtonCallback)
            self.w.open()
            
        def popUpButtonCallback(self, sender):
            print "pop up button selection!", sender.get()
            
    PopUpButtonDemo()
    """

    nsPopUpButtonClass = NSPopUpButton
    nsPopUpButtonCellClass = NSPopUpButtonCell

    frameAdjustments = {
        "mini": (-1, 0, 3, 0),
        "small": (-3, -4, 6, 5),
        "regular": (-3, -4, 6, 6),
    }

    def __init__(self, posSize, items, callback=None, sizeStyle="regular"):
        """
        *posSize* Tuple of form (left, top, width, height) representing the position and size of the pop up button. The size of the button sould match the appropriate value for the given _sizeStyle_.

        |\\3. *Standard Dimensions* |
        | Regular | H | 20          |
        | Small   | H | 17          |
        | Mini    | H | 15          |

        *items* A list of items to appear in the pop up list.

        *callback* The method to be called when the user selects an item in the pop up list.

        *sizeStyle* A string representing the desired size style of the pop up button. The options are:

        | "regular" |
        | "small"   |
        | "mini"    |
        """
        self._setupView(self.nsPopUpButtonClass, posSize)
        if self.nsPopUpButtonCellClass != NSPopUpButtonCell:
            self._nsObject.setCell_(self.nsPopUpButtonCellClass.alloc().init())
        if callback is not None:
            self._setCallback(callback)
        self._setSizeStyle(sizeStyle)
        self.setItems(items)

    def getNSPopUpButton(self):
        """
        Return the _NSPopUpButton_ that this object wraps.
        """
        return self._nsObject

    def get(self):
        """
        Get the index selected item in the pop up list.
        """
        return self._nsObject.indexOfSelectedItem()

    def set(self, value):
        """
        Set the index of the selected item in the pop up list.
        """
        self._nsObject.selectItemAtIndex_(value)

    def setItems(self, items):
        """
        Set the items to appear in the pop up list.
        """
        self._nsObject.removeAllItems()
        for item in items:
            if isinstance(item, NSMenuItem):
                menu = self._nsObject.menu()
                menu.addItem_(item)
            else:
                self._nsObject.addItemWithTitle_(item)

    def getItems(self):
        """
        Get the list of items that appear in the pop up list.
        """
        return self._nsObject.itemTitles()

{'fraction_non_alphanumeric': 0.0942194644023514, 'fraction_numerical': 0.010450685826257348, 'mean_word_length': 1.8864278982092366, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5695322', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1689, 'n_words': 541}