Example #1
0
        def tap_(self, rec):
            nonlocal last
            i = tapmap[rec.ptr.value]

            # block already solved tiles; block current open tile
            if solved[i] or last == i:
                return

            if last is not None and tiles[last][0] == tiles[i][0]:
                solved[last] = True
                solved[i] = True
                last = None
                flip(i)
                if all(solved):
                    sound.victory()
                    self.performSelector(SEL("reset:"),
                                         withObject=None,
                                         afterDelay=NSTimeInterval(1))
                    return
                else:
                    sound.match()
                    return

            # after solving a tile or at the start of the game
            if last is not None:
                flip(last, back=True)

            flip(i)
            last = i
            sound.tap()
Example #2
0
    def test_send_sel(self):
        """send_message accepts a SEL object as the selector parameter."""
        Example = ObjCClass('Example')

        obj = Example.alloc().init()

        self.assertEqual(send_message(obj, SEL("accessIntField"), restype=c_int, argtypes=[]), 33)
Example #3
0
 def __init__(self, interface):
     self.interface = interface
     self.native = TogaMenuItem.alloc().init()
     self.native.interface = self.interface
     self.native.impl = self
     self.native.target = self.native
     self.native.action = SEL("onPress:")
Example #4
0
    def create(self):
        self._impl = TogaSlider.alloc().init()
        self._impl._interface = self

        self._impl.setTarget_(self._impl)
        self._impl.setAction_(SEL('onSlide:'))

        self._add_constraints()
Example #5
0
    def create(self):
        self.native = TogaSlider.alloc().init()
        self.native.interface = self.interface

        self.native.target = self.native
        self.native.action = SEL('onSlide:')

        self.add_constraints()
Example #6
0
    def create(self):
        self.native = TogaPopupButton.alloc().init()
        self.native.interface = self.interface

        self.native.target = self.native
        self.native.action = SEL('onSelect:')

        self.add_constraints()
Example #7
0
def release_views(views):
    for view in views:
        if view.respondsToSelector(SEL("releaseReference")):
            try:
                view.releaseReference()
                view.release()
            except ValueError:
                pass
Example #8
0
    def create(self):
        self._impl = TogaSlider.alloc().init()
        self._impl._interface = self

        self._impl.continuous = True
        self._impl.addTarget_action_forControlEvents_(self._impl, SEL('onSlide:'), UIControlEventValueChanged)

        # Add the layout constraints
        self._add_constraints()
Example #9
0
    def loadView(self) -> None:
        self.title = self.interface.title

        self.cancelButton = UIBarButtonItem.alloc(
        ).initWithBarButtonSystemItem_target_action_(
            UIBarButtonSystemItem.Cancel, self, SEL('cancelClicked'))
        self.navigationController.navigationBar.topItem.leftBarButtonItem = self.cancelButton

        self.doneButton = UIBarButtonItem.alloc(
        ).initWithBarButtonSystemItem_target_action_(
            UIBarButtonSystemItem.Done, SEL('doneClicked'))
        self.navigationController.navigationBar.topItem.rightBarButtonItem = self.doneButton

        self.interface.content._update_layout(
            width=UIScreen.mainScreen().bounds.size.width,
            height=UIScreen.mainScreen().bounds.size.height,
            padding_top=12)

        self.view = self.interface.content._impl
Example #10
0
    def application_didFinishLaunchingWithOptions_(self, application,
                                                   launchOptions) -> bool:
        print("App finished launching.")
        App.app.create()

        NSNotificationCenter.defaultCenter.addObserver(
            self,
            selector=SEL('keyboardWillShow:'),
            name=UIKeyboardWillShowNotification,
            object=None)
        NSNotificationCenter.defaultCenter.addObserver(
            self,
            selector=SEL('keyboardWillHide:'),
            name=UIKeyboardWillHideNotification,
            object=None)
        # Set the initial keyboard size.
        App.app.interface.main_window.content._impl.viewport.kb_height = 0.0

        return True
Example #11
0
    def create(self):
        self.native = TogaButton.alloc().init()
        self.native.interface = self.interface

        self.native.setTitleColor(self.native.tintColor, forState=UIControlStateNormal)
        self.native.setTitleColor(UIColor.grayColor, forState=UIControlStateDisabled)
        self.native.addTarget(self.native, action=SEL('onPress:'), forControlEvents=UIControlEventTouchDown)

        # Add the layout constraints
        self.add_constraints()
Example #12
0
 def make_view(self):
     picker = UIDatePicker.alloc().init()
     
      # We create an Objective-C instance that will respond to the date picker value changed event
     delegate = PickerDelegate.alloc().init()
     delegate.picker = self
     delegate.objc_picker = picker
     
     # 4096 is the value for UIControlEventValueChanged
     picker.addTarget(delegate, action=SEL("didChange"), forControlEvents=4096)
     return picker
Example #13
0
    def create(self):
        self.native = TogaButton.alloc().init()
        self.native.interface = self.interface

        self.native.bezelStyle = NSRoundedBezelStyle
        self.native.buttonType = NSMomentaryPushInButton
        self.native.target = self.native
        self.native.action = SEL('onPress:')

        # Add the layout constraints
        self.add_constraints()
Example #14
0
    def create(self):
        self.native = TogaSwitch.alloc().init()
        self.native.interface = self.interface

        self.native.bezelStyle = NSRoundedBezelStyle
        self.native.setButtonType(NSSwitchButton)
        self.native.target = self.native
        self.native.action = SEL('onPress:')

        # Add the layout constraints
        self.add_constraints()
Example #15
0
 def set_on_refresh(self, handler: callable or None) -> None:
     if callable(handler):
         self.controller.refreshControl = UIRefreshControl.alloc().init()
         self.controller.refreshControl.addTarget(
             self.controller,
             action=SEL('refresh'),
             forControlEvents=UIControlEventValueChanged)
     else:
         if self.controller.refreshControl:
             self.controller.refreshControl.removeFromSuperview()
         self.controller.refreshControl = None
Example #16
0
    def create(self):
        self.native = TogaStepper.alloc().init()
        self.native.interface = self.interface

        self.native.minValue = self.interface.min_value
        self.native.maxValue = self.interface.max_value
        self.native.increment = self.interface.step
        self.native.target = self.native
        self.native.action = SEL('onChange:')

        self.add_constraints()
Example #17
0
    def create(self):
        self._impl = TogaButton.alloc().init()
        self._impl._interface = self

        self._impl.setBezelStyle_(NSRoundedBezelStyle)
        self._impl.setButtonType_(NSMomentaryPushInButton)
        self._impl.setTarget_(self._impl)
        self._impl.setAction_(SEL('onPress:'))

        # Add the layout constraints
        self._add_constraints()
Example #18
0
    def create(self):

        self._impl = TogaStepper.alloc().init()
        self._impl._interface = self

        self._impl.minValue = self._config["min_value"]
        self._impl.maxValue = self._config["max_value"]
        self._impl.increment = self._config["step"]
        self._impl.setTarget_(self._impl)
        self._impl.setAction_(SEL('onChange:'))

        self._add_constraints()
Example #19
0
    def create(self):
        self.native = TogaTextField.new()
        self.native.interface = self.interface

        self.native.borderStyle = UITextBorderStyle.RoundedRect

        self.native.addTarget(self.native,
                              action=SEL('textFieldDidChange:'),
                              forControlEvents=UIControlEventEditingChanged)

        # Add the layout constraints
        self.add_constraints()
Example #20
0
    def create(self):
        self.native = TogaSlider.alloc().init()
        self.native.interface = self.interface

        self.native.continuous = True
        self.native.addTarget(
            self.native,
            action=SEL('onSlide:'),
            forControlEvents=UIControlEventValueChanged
        )

        # Add the layout constraints
        self.add_constraints()
Example #21
0
    def create(self):
        self.native = TogaCanvas.alloc().init()
        self.native.interface = self.interface
        self.native._impl = self

        NSNotificationCenter.defaultCenter.addObserver(
            self.native,
            selector=SEL("frameChanged:"),
            name=NSViewFrameDidChangeNotification,
            object=self.native)

        # Add the layout constraints
        self.add_constraints()
Example #22
0
    def create(self):
        self.native = NSPopUpButton.alloc().init()
        self.target = FileChooserTarget.alloc().init()
        self.target.interface = self.interface
        self.target.impl = self
        self.native.target = self.target
        self.native.action = SEL("onSelect:")

        self._current_selection = ""
        self.native.addItemWithTitle("")
        self.native.menu.addItem(NSMenuItem.separatorItem())
        self.native.addItemWithTitle("Choose...")

        self.add_constraints()
Example #23
0
    def menuForEvent_(self, event):
        if self.interface.on_delete:
            mousePoint = self.convertPoint(event.locationInWindow,
                                           fromView=None)
            row = self.rowAtPoint(mousePoint)

            popup = NSMenu.alloc().initWithTitle("popup")
            delete_item = popup.addItemWithTitle(
                "Delete", action=SEL('actionDeleteRow:'), keyEquivalent="")
            delete_item.tag = row
            # action_item = popup.addItemWithTitle("???", action=SEL('actionRow:'), keyEquivalent="")
            # action_item.tag = row

            return popup
Example #24
0
 def collectionView_cellForItemAtIndexPath_(self, view, path):
     i = path.item
     rv = view.dequeueReusableCellWithReuseIdentifier("knob", forIndexPath=path)
     cells[i] = rv
     closed[i] = NSBundle.mainBundle.loadNibNamed("knob", owner=self, options=NSDictionary.new()).firstObject()
     opened[i] = NSBundle.mainBundle.loadNibNamed("open", owner=self, options=NSDictionary.new()).firstObject()
     label = find_view(opened[i], "text")
     label.text = tiles[i][1]
     closed[i].retain()
     opened[i].retain()
     rv.addSubview(closed[i])
     rec = UITapGestureRecognizer.alloc().initWithTarget(self, action=SEL("tap:"))
     tapmap[rec.ptr.value] = i
     rv.addGestureRecognizer(rec)
     return rv
Example #25
0
    def create(self):
        self.native = NSButton.alloc().init()
        self.native.bezelStyle = NSBezelStyle.Rounded
        self.native.setButtonType(NSSwitchButton)
        self.native.autoresizingMask = NSViewMaxYMargin | NSViewMaxYMargin

        self.target = SwitchTarget.alloc().init()
        self.target.interface = self.interface
        self.target.impl = self

        self.native.target = self.target
        self.native.action = SEL("onPress:")

        # Add the layout constraints
        self.add_constraints()
Example #26
0
File: app.py Project: djay/toga
    def create_menus(self):
        # Only create the menu if the menu item index has been created.
        if hasattr(self, '_menu_items'):
            self._menu_items = {}
            menubar = NSMenu.alloc().initWithTitle('MainMenu')
            submenu = None
            menuItem = None
            for cmd in self.interface.commands:
                if cmd == toga.GROUP_BREAK:
                    menubar.setSubmenu(submenu, forItem=menuItem)
                    submenu = None
                elif cmd == toga.SECTION_BREAK:
                    submenu.addItem_(NSMenuItem.separatorItem())
                else:
                    if submenu is None:
                        menuItem = menubar.addItemWithTitle(cmd.group.label,
                                                            action=None,
                                                            keyEquivalent='')
                        submenu = NSMenu.alloc().initWithTitle(cmd.group.label)
                        submenu.setAutoenablesItems(False)

                    if cmd.shortcut:
                        key, modifier = cocoa_key(cmd.shortcut)
                    else:
                        key = ''
                        modifier = None

                    item = NSMenuItem.alloc().initWithTitle(
                        cmd.label,
                        action=SEL('selectMenuItem:'),
                        keyEquivalent=key,
                    )
                    if modifier is not None:
                        item.keyEquivalentModifierMask = modifier

                    cmd._impl.native.append(item)
                    self._menu_items[item] = cmd

                    # This line may appear redundant, but it triggers the logic
                    # to force the enabled status on the underlying widgets.
                    cmd.enabled = cmd.enabled
                    submenu.addItem(item)

            if submenu:
                menubar.setSubmenu(submenu, forItem=menuItem)

            # Set the menu for the app.
            self.native.mainMenu = menubar
Example #27
0
    def create(self):
        self.native = UIStackView.alloc().init()
        self.native.interface = self.interface
        self.native.axis = UILayoutConstraintAxis.Horizontal

        self.native_label = UILabel.alloc().init()

        self.native_switch = TogaSwitch.alloc().init()
        self.native_switch.interface = self.interface
        self.native_switch.addTarget_action_forControlEvents_(self.native_switch, SEL('onPress:'),
                                                              UIControlEventValueChanged)
        # Add switch and label to UIStackView
        self.native.addArrangedSubview_(self.native_label)
        self.native.addArrangedSubview_(self.native_switch)
        
        # Add the layout constraints
        self.add_constraints()
Example #28
0
    def create(self):
        self._controller = TogaNavigationController.alloc(
        ).initWithRootViewController_(self._config['content']._controller)
        self._controller.interface = self
        self._controller.navigationBar.topItem.title = self._config['title']

        self._impl = self._controller.view

        if self._config['on_action']:
            self._action_button = UIBarButtonItem.alloc(
            ).initWithBarButtonSystemItem_target_action_(
                button_for_action(self._config['on_action']), self._controller,
                SEL('onAction'))
            self._controller.navigationBar.topItem.rightBarButtonItem = self._action_button

        # Add the layout constraints
        self._add_constraints()
Example #29
0
    def create(self):
        self.native = TogaNumericTextField.alloc().init()
        self.native.interface = self.interface
        self.native.delegate = self.native
        self.native.borderStyle = UITextBorderStyle.RoundedRect
        # FIXME: See Rubicon #96
        # self.native.keyboardType = UIKeyboardType.DecimalPad
        send_message(self.native,
                     'setKeyboardType:',
                     UIKeyboardType.DecimalPad.value,
                     restype=None,
                     argtypes=[c_int])

        # Make the text field respond to any content change.
        self.native.addTarget(self.native,
                              action=SEL('textFieldDidChange:'),
                              forControlEvents=UIControlEventEditingChanged)

        # Add the layout constraints
        self.add_constraints()
Example #30
0
    def create(self):
        # Hack! Because UISwitch has no label, we place it in a UITableViewCell to get a label
        self.native = UITableViewCell.alloc().initWithStyle_reuseIdentifier_(
            UITableViewCellStyleDefault, 'row')
        self.native.interface = self.interface

        self.native_switch = TogaSwitch.alloc().init()
        self.native_switch.interface = self.interface
        self.native_switch.addTarget_action_forControlEvents_(
            self.native_switch, SEL('onPress:'), UIControlEventValueChanged)
        # Add Switch to UITableViewCell
        self.native.accessoryView = self.native_switch

        # Add the layout constraints
        self.add_constraints()

        fitting_size = self.native.systemLayoutSizeFittingSize_(CGSize(0, 0))
        self.interface.style.hint(
            min_height=fitting_size.height,
            min_width=fitting_size.width,
        )