How to call NSPasteboard withUniqueName from Python using PyObjC - pyobjc

I am attempting to create a new pasteboard using the NSPasteboard class-level function withUniqueName from Python via PyObjC, however I get the error "AttributeError: No attribute withUniqueName".
This is my first use of PyObjC. I did read the PyObjC intro but I could very easily be calling it wrong.
This code yields the error:
from AppKit import *
pb = NSPasteboard.withUniqueName()
Based on the discussion of selectors in the intro, I also tried:
from AppKit import *
pb = NSPasteboard.withUniqueName_()
but that also gave an AttributeError.
This code (excerpted from http://www.macdrifter.com/2011/12/python-and-the-mac-clipboard.html works:
from AppKit import *
pb = NSPasteboard.generalPasteboard()
From the NSPasteboard docs I see that withUniqueName is a class function whereas general is a class variable, so my attempt to invoke withUniqueName in the same way may be errant.
In attempting to determine whether I was just calling withUniqueName wrong or whether PyObjC didn't implement it, I did dir(NSPasteboard). withUniqueName was not in the list, but neither was "general" nor "generalPasteboard". Even grepping through the installed modules, I could not find "general" nor "generalPasteboard", and I know the latter works, so that was frustrating my attempt at discovery. Also I don't understand why the Python code needs to call the variable as generalPasteboard when the name in the Apple docs is just general.
I'm using PyObjC 5.2 installed from PyPI with Python 3.7.0 on Sierra 10.12.6.
Does PyObjC 5.2 support NSPasteboard withUniqueName? If so, what is the correct way to call it? If not, how would I inspect the module/class to know that?

The name withUniqueName is the Swift name of this method, the Objective-C selector is +[NSPasteboard pasteboardWithUniqueName]. This means it can be called like this:
pboard = NSPasteboard.pasteboardWithUniqueName()

Related

Does erlang-ls support go-to-definition for variables?

Does erlang-ls support go-to-definition for variables?
Going to definition seems to work for functions and modules, but Coc.vim says "provider not found" when I gd on a variable name. Cmd-clicking a variable name doesn't do anything in VSCode, either.
What I tried:
erlang-ls docs and issues
Peeking through the source, I see that els_code_navigation matches on poi_kind. The relevant poi_kind would be variable, but "variable" doesn't appear in els_code_navigation.
There is currently no support in erlang_ls for jumping to the definition of a variable.
If this is something that you would like implemented please open a feature request in the erlang_ls GitHub project.

unable to find `as` method in `Config`

I saw the following code snippet
val settings = configuration.underlying.as[CookieSecretSettings]("silhouette.oauth1TokenSecretProvider")
I believe configuration is of type play.api.Configuration and underlying is of typeConfig` (https://www.playframework.com/documentation/2.6.x/api/scala/index.html#play.api.Configuration)
I copied the code in my Apploader (as I am using Compile Time Injection). The BuiltInComponentsFromContext has a configuration variable. I thought to use that as follows val config = configuration.underlying.as[CookieAuthenticatorSettings]("silhouette.authenticator") but the compiler cannot resolve as. What am I doing wrong?
The Config library seem to have asInstanceOf instead of as but I get other errors if I use that. I notice that the code for which as works uses play version 2.4.2 while I am using 2.6.12.
I realize this is an old question, but I stumbled upon this exact problem today and couldn't find anything helpful.
The as method is provided by a third-party library (Ficus) to read case classes and Scala types from Typesafe config. You need to include it in your build dependencies, then add to imports:
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._

Error when using global variables from es5-library in typescript

I am developing an app using Angular 2 and Ionic. I am using a bluetooth library for Cordova, so not writing using ES6-modules and exports.
The library defines a global variable called 'bluetoothle', and it works as expected when I run it. However, I get a lot of complaints from the typescript compiler. I would like to either:
(Preferred) Have some better way to import the ES5-library to my typescript-project.
Tell the compiler to ignore this error.
Declare the variable, and then let the library assign value to it(however, I don't know how to declare globals in typescript the way it was possible in ES6.
Thanks in advance,
Markus
You have two options there which depend on how much work you want to put in them.
The first and easy option is to just declare the variable at the top. This will tell TypeScript that this is a variable of type any and that it doesn't need to care about where it came from or which members it has:
declare var bluetoothle;
The other route, which would be cleaner but is way more work is writing a type definition file.

retrieving the module object on Lua

I have a C program that uses Lua to run some scripts. I need to open the Lua libraries via C code like luaopen_socket_core(myLuaState), for some reasons I can't load the modules from the Lua code, like socket = require "luasocket".
Once understood the idea of this program now I need to load a library called struct, so I added the struct.c to my project, and when I tried to use its functions like struct.unpack the runtimer complains that there is no global variable called struct. Of course it was loaded with luaopen_struct(myLuaState) instead of struct = require "struct" which is forbidden for me.
Any suggestion about an way of having this struct variable available?
Take a look at luaL_requiref in the auxiliary library, which mimics require called from Lua.
You probably called the open-function directly and forgot to set those variables manually, that function would do it all for you.

function 'Func/Arity' already imported from 'Module'

I defined both area/1 and perim/1 in modules sqaure and circle.
I want to import and use them in another module. Here is my import statements:
-import(square, [area/1, perim/1]).
-import(circle, [area/1, perim/1]).
I got these error messages.
~/test.erl:4: function area/1 already imported from square
~/test.erl:4: function perim/1 already imported from square
I know erlang does not support namespace. But since we can qualify a function call by specifying the module (i.e. square:area vs circle:area), I fail to see how the lack of namespace is the source of the error here.
So, what exactly caused the above error and how can I fix it?
In Erlang, "importing" a function from another module means being able to call it as if it were a local function, without the module prefix. So with this directive:
-import(square, [area/1, perim/1]).
you could write area(42) and it would mean the same as square:area(42).
However, if you include area and perim functions from two modules, it would be ambiguous which one you'd actually call when writing area(42).
As you correctly note, you can always qualify the function call with the name of the module, i.e. square:area(42) and circle:area(42) - so I would suggest doing so consistently and removing both import directives. This is also recommended by rule 6.6 of the Erlang Programming Rules - "Don't use import".

Resources