vanilla icon indicating copy to clipboard operation
vanilla copied to clipboard

Add support for new Yosemite views, controls, etc.

Open typesupply opened this issue 11 years ago • 32 comments

AppKit Release notes: https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/

~~NSVisualEffectView~~ (done)

This is handled simply with a new Group kwarg:

self.w.group = vanilla.Group((10, 10, -10, -10), blendingMode="withinWindow")

Internally, this is handled not so simply.

~~Window Styles~~ (done)

These are the current init kwargs that specify window appearance.

closable = True | False
miniaturizable = True | False
initiallyVisible = True | False
fullScreenMode = None | "primary" | "auxillary"

10.10 adds new appearance options: https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/#10_10Window

Full Size Content View

This pushes the content view underneath the title and toolbars. Those should then be set to be transparent. (Not always, but I don't want two flags so if the transparency is not desired a coder can override this with getNSWindow().setTitlebarAppearsTransparent_(False).) I'm not sure when this is used but we may as well make it possible.

self.w = vanilla.Window(..., fullSizeContentView=False, ...)
try:
    NSFullSizeContentViewWindowMask
except NameError:
    NSFullSizeContentViewWindowMask = 1 << 15

if fullSizeContentView and osVersion >= "10.10":
    mask = mask | NSFullSizeContentViewWindowMask

# ... later ...

if fullSizeContentView and osVersion >= "10.10":
    self._window.setTitlebarAppearsTransparent_(True)

Titlebar Visibility

This will show/hide the title of the window. If it is hidden, the toolbar moves to the space formally occupied by the title.

self.w = vanilla.Window(..., titleVisible=True, ...)
try:
    NSWindowTitleVisible
except NameError:
    NSWindowTitleVisible  = 0
    NSWindowTitleHidden = 1
if osVersion >= "10.10":
    if not titleVisible:
        self._window.setTitleVisibility_(NSWindowTitleHidden)
    else:
        self._window.setTitleVisibility_(NSWindowTitleVisible)

NSTitlebarAccessoryViewController

This is an advanced thing that should be handled outside of vanilla.

~~HUDWindow~~ (done)

Action Button with Menu

How would callbacks work?

List

  • more cell types
    • ~~add ticks to list slider~~ (done)
    • ~~image cell~~ (done)
    • ~~segmented cell~~ (done)
  • demos
    • ~~image cell~~
    • ~~checkbox cell~~
    • ~~slider cell~~
    • ~~popup cell~~
  • ~~column width bug~~ (hopefully done)
  • ~~should the column resizing behavior be an init kwarg?~~ (no. this is handled with column construction data.)
  • ~~make it possible to disable column sorting.~~ (done)
  • is dataSource needed? It adds lots of complexity to the code.
  • more documentation about and examples of drag and drop.

Cell vs. View Mode

Here's a tricky one: the use of cells in NSTableView is now deprecated. Instead, we are supposed to use views. That's easy enough to switch but mixing cells and views in the same table is not permitted. So, we can't simply change things like SliderListCell to be view based instead of cell based. We do need to make the change though. (Plus, view based tables can do some really useful stuff.)

I think we could handle this change by automatically detecting the cell types during __init__ by skimming the "cell" settings in columnDescriptions. If anything there is cell based, the table view would be set to cell mode. Otherwise it would be set to view mode.

I'm still researching this so this could change.

Localization

This is going to require some research on how localization is handled at the app level. I'm not sure if localization will be able to be specified on the fly per control, which is what would be ideal for vanilla.

Auto-Layout

This is going to be tricky but it might be a very worthwhile thing to add.

NSMatrix

This class is now deprecated. It looks like RadioGroup can be rebuilt with a Group as a parent and individual buttons set to be radio buttons. According to the documentation, those will automatically be linked as a group in 10.8+.

Misc

  • ~~Remove any hacks needed for < 10.6.~~ (done)
  • ~~conditionally remove cell interaction when osVersion >= 10.10 since cells are slowly being deprecated.~~ (done. Apple hasn't assigned view based methods for everything yet so there are still some cell calls.)
  • add a convenience method for getting the selected item from a popup button

typesupply avatar Nov 02 '14 11:11 typesupply

A checkbox also needs some editing. The title seems always disabled…

see https://github.com/typemytype/vanilla/commit/ffdee5d7a6a3e9f6a188f195e7f4a09fb261f315

typemytype avatar Nov 03 '14 08:11 typemytype

A small proposal showing how localization could work, without losing the cocoa default implementation. There are lots of UI element that arent made by vanilla, like menu item, some dialogs, this will somehow be supported, I guess...

will make a sample app later on this week

https://dl.dropboxusercontent.com/u/41873/locaVanillaTest.zip

typemytype avatar Nov 03 '14 10:11 typemytype

The checkbox issue should be fixed now: https://github.com/typesupply/vanilla/commit/f4836f0fdc755d812321f1800bb233a641f349a7

typesupply avatar Nov 03 '14 11:11 typesupply

This looks like a good way to handle localization. I guess my dream of RoboFont extensions being able to declare their localizations isn't going to work out since NSBundle is immutable.

typesupply avatar Nov 03 '14 11:11 typesupply

maybe a small request: make column headers in a List not sortable. (this could be an argument in init


def __init__(self, posSize, … columnsCanSort=True, ….):
    …
    self._columnsCanSort = columnsCanSort

def _makeColumnsWithColumnDescriptions(self, columnDescriptions):
    bindingOptions = None
    if self._columnsCanSort:
        bindingOptions={NSCreatesSortDescriptorBindingOption:False}
    …
    column.bind_toObject_withKeyPath_options_(binding, self._arrayController, keyPath, bindingOptions)

https://github.com/typesupply/vanilla/blob/yosemite/Lib/vanilla/vanillaList.py#L659

typemytype avatar Nov 03 '14 11:11 typemytype

yeah a nsBundle is idd immutable and once it is loaded, it seems very hacky to reload it. On the fly localization could be possible in a sub class of a nsBundle, I guess

will check it out...

typemytype avatar Nov 03 '14 11:11 typemytype

Column sorting can now be turned off on a full list or single column basis. Example:

import vanilla

class Test(object):

    def __init__(self):
        self.w = vanilla.Window((500, 500))
        columnDescriptions = [
            dict(title="one"),
            dict(title="two", allowsSorting=False),
            dict(title="three"),
        ]
        self.w.l = vanilla.List((10, 10, -10, -10),
            [
                dict(one="A", two="D", three="G"),
                dict(one="B", two="E", three="H"),
                dict(one="C", two="F", three="I"),
            ],
            columnDescriptions=columnDescriptions,
            allowsSorting=True
        )
        self.w.open()


from vanilla.test.testTools import executeVanillaTest

executeVanillaTest(Test)

typesupply avatar Nov 03 '14 12:11 typesupply

a proposal for the auto layout https://gist.github.com/typemytype/b9c85801762c579448d7

As this could be a radical change, it maybe better to first concentrate on getting all elements 10.10 ready and then make a new branch focussed on auto layout…

but this could be very cool :)

typemytype avatar Nov 03 '14 20:11 typemytype

This looks great! It's all coming back to me now. Using "auto" as the posSize will be a nice indicator. We'll have to look through the vanilla objects to make sure that there aren't any posSize dependencies. I don't think this is going to be that big of a change, but yeah let's get 10.10 support done first.

typesupply avatar Nov 03 '14 21:11 typesupply

and all the existing subclasses...

typemytype avatar Nov 03 '14 22:11 typemytype

a Window object could have an optional argument supporting full screen: supportFullScreen=True/False (available from 10.7+)

# not sure if NSWindowCollectionBehaviorFullScreenPrimary is already in pyObjC
if supportFullSCreen:
    try:
        self._window.setCollectionBehavior_(128) #NSWindowCollectionBehaviorFullScreenPrimary
    except:
        # fail silently on 10.6
        pass

typemytype avatar Nov 04 '14 08:11 typemytype

We already have support for full screen. I've sketched out the new window appearance settings API above. Let me know what you think. I'm happy with it.

typesupply avatar Nov 04 '14 12:11 typesupply

I committed and pushed the window appearance changes.

typesupply avatar Nov 04 '14 12:11 typesupply

running against some issues on 10.9.5 mainly the default python string compare doest work well with '10.9.5' >= '10.10' -->True even '10.9' >= '10.10' --> True

maybe testing version nrs with distutils is better

from distutils.version import StrictVersion
print '10.9' >= '10.10'
print StrictVersion('10.9.5') > StrictVersion('10.10')

typemytype avatar Nov 05 '14 15:11 typemytype

Hm. We could define some constants that use this. Something like:

osVersionCurrent = StrictVersion(platform.mac_ver()[0])
osVersion10_10 = StrictVersion("10.10")
osVersion10_9 = StrictVersion("10.9")
osVersion10_8 = StrictVersion("10.8")
osVersion10_7 = StrictVersion("10.7")
osVersion10_6 = StrictVersion("10.6")

That way the code wouldn't have a lot of StrictVersion(...) sprinkled throughout.

typesupply avatar Nov 05 '14 15:11 typesupply

I would even add the results as a bool in the constants

typemytype avatar Nov 05 '14 19:11 typemytype

I patched vanilla with using the StrictVersion osVersion comparison. Will send a pull request soon.

An other thing that could be handy is a convenient way to put a vanilla.Group into a vanilla.ScrollView. Will make a small example. It should be as easy as adding an nsView to a scrollView but not hard resetting the frame...

typemytype avatar Dec 15 '14 12:12 typemytype

a patch to support embedded Groups into a ScrollView

https://gist.github.com/typemytype/c9ac5349183209a7d3e7

I can also implement this and send a pull request...

typemytype avatar Dec 15 '14 13:12 typemytype

Thanks. I'm hoping to get back to updating vanilla next week. I had to do some of my day job work and the problem with List made me not want to work on vanilla for a while. I think List is going to have to be rewritten to not use bindings. Ugh.

typesupply avatar Dec 15 '14 14:12 typesupply

added an ActionButton to my fork, can send a pull request when you are ready

https://github.com/typemytype/vanilla/blob/fc3ab1ec91553eb01adf7ec8be673f61aa33c407/Lib/vanilla/vanillaPopUpButton.py#L121

screen shot 2014-12-17 at 11 32 45

typemytype avatar Dec 17 '14 10:12 typemytype

Column sorting can now be turned off on a full list or single column basis. Example

Are there any plans to move that into that master branch?

schriftgestalt avatar Mar 11 '16 11:03 schriftgestalt

I'd love to, but I don't have time right now. My open source time is going to other projects. Patches are welcome!

typesupply avatar Mar 11 '16 12:03 typesupply

I had a quick look at the changes. Some are really related to changes in Yosemite. But there are several things that should work in earlier version, too.

Why I can across this is someone tried to write a script that works in RoboFont and Glyphs. And RF 1.7 seems to use a version of vanilla that supports this particular argument (so it might use this branch?).

schriftgestalt avatar Mar 11 '16 19:03 schriftgestalt

Some of this stuff apparently is integrated now, some is not. I suggest to close this issue and open new ones for the remaining feature requests, if that's indeed what they are.

justvanrossum avatar Oct 27 '17 12:10 justvanrossum

ActionButton is added see https://github.com/typesupply/vanilla/blob/cf0707e29e489c9e5b5bad165f8fd2256881c9ef/Lib/vanilla/vanillaPopUpButton.py#L121

typemytype avatar Oct 27 '17 12:10 typemytype

related to Lists:

  • is dataSource needed? It adds lots of complexity to the code.

yes that is needed, only to support searching and shared dateSource over different views

  • more documentation about and examples of drag and drop.

will create a new issue for that

typemytype avatar Oct 27 '17 12:10 typemytype

Is there any possibility to get the dark VisualEffectViews working?

I can trigger light vibrant windows by adding self.w.blend = Group((0, 0, 0, 0), blendingMode='behindWindow')

Anyways since there is https://github.com/typesupply/vanilla/blob/2d27b1fe7abfd94a3cc6d574efe804dfad1d4029/Lib/vanilla/vanillaGroup.py#L11 we have no option to choose between the VisualEffectViews, not even when _nsObject is triggered, or is there?

form-follows-function avatar Dec 28 '18 20:12 form-follows-function

So, I've got that fixed by adding:

view = self.w

visualEffectView = NSVisualEffectView.new()
visualEffectView.setAutoresizingMask_(NSViewWidthSizable|NSViewHeightSizable)
    
visualEffectView.setWantsLayer_(True)
visualEffectView.setFrame_(frame)
visualEffectView.setState_(NSVisualEffectStateActive)
visualEffectView.setMaterial_(NSVisualEffectMaterialDark)
visualEffectView.setBlendingMode_(NSVisualEffectBlendingModeBehindWindow)

self.w._window.contentView().addSubview_positioned_relativeTo_(visualEffectView, NSWindowBelow, self.w)

self.w._window.setTitlebarAppearsTransparent_(True)
self.w._window.setStyleMask_(self.w._window.styleMask() | NSFullSizeContentViewWindowMask)
        
appearance = NSAppearance.appearanceNamed_('NSAppearanceNameVibrantDark')
self.w._window.setAppearance_(appearance)

form-follows-function avatar May 16 '19 22:05 form-follows-function

@typemytype

a patch to support embedded Groups into a ScrollView

https://gist.github.com/typemytype/c9ac5349183209a7d3e7

I can also implement this and send a pull request...

Been 6 years, but could you pull request this? It would be handy to use ScrollView without relying on pyobjc and keep vanilla interoperable within itself.

form-follows-function avatar Jul 15 '20 20:07 form-follows-function

Just started to read the thread again after seeing the notification. I found this:

Full Size Content View This pushes the content view underneath the title and toolbars. Those should then be set to be transparent.

The full size content view and titlebar transparency should not be set together. There are a lot cases that need a visible titlebar. It is used when there is a scroll view adjacent to the toolbar and the scrolled content should go under the (translucent) title bar. See Safari and Maps.

schriftgestalt avatar Jul 15 '20 22:07 schriftgestalt