introspection

unresponsive drag and drop in pygobject

百般思念 提交于 2019-12-07 17:43:34
问题 im trying to get drag and drop working well in pygobject, but it is slow and unresponsive, 90% of the time i have to wave the item i am dragging around before i can drop it successfully, can anyone see if i am doing it incorrectly or is this a bug with pygobject? here is my code from gi.repository import Gtk, GdkPixbuf, Gdk import os def got_data_cb(windowid, context, x, y, data, info, time): # Got data. tempArray = data.get_text().splitlines() for i in tempArray: i = i.replace('file://','')

How do you list all the namespaces in an instance of TCL?

蓝咒 提交于 2019-12-07 16:46:02
问题 How do you list all the namespaces loaded in an instance of tclsh? Chenz 回答1: Try running this proc from the TCLer's Wiki proc listns {{parentns ::}} { set result [list] foreach ns [namespace children $parentns] { eval lappend result [listns $ns] lappend result $ns } return $result } When I run it, I get the following output: % listns ::platform ::activestate::teapot::link ::activestate::teapot ::activestate ::tcl ::clock ::tcl::info ::tcl::dict ::tcl::tm ::tcl::mathop ::tcl::unsupported :

Python Introspection: How to get varnames of class methods?

*爱你&永不变心* 提交于 2019-12-07 05:55:16
问题 I want to get the names of the keyword arguments of the methods of a class. I think I understood how to get the names of the methods and how to get the variable names of a specific method, but I don't get how to combine these: class A(object): def A1(self, test1=None): self.test1 = test1 def A2(self, test2=None): self.test2 = test2 def A3(self): pass def A4(self, test4=None, test5=None): self.test4 = test4 self.test5 = test5 a = A() # to get the names of the methods: for methodname in a._

python: determine if a class is nested

折月煮酒 提交于 2019-12-07 03:41:43
问题 Suppose you have a python method that gets a type as parameter; is it possible to determine if the given type is a nested class? E.g. in this example: def show_type_info(t): print t.__name__ # print outer class name (if any) ... class SomeClass: pass class OuterClass: class InnerClass: pass show_type_info(SomeClass) show_type_info(OuterClass.InnerClass) I would like the call to show_type_info(OuterClass.InnerClass) to show also that InnerClass is defined inside OuterClass. 回答1: AFAIK, given a

Check existence of global function in Swift

谁说我不能喝 提交于 2019-12-07 01:35:49
问题 Is it possible to detect if some global function (not class method) is defined (in iOS)? Something like respondsToSelector in a class... 回答1: Swift currently does not support looking up global functions. For C functions (most global functions from Apple's frameworks are C functions) there are at least two ways: using a weakly linked symbol the dynamic linker API: dlopen Both check dynamically (at runtime) if a symbol can be found. Here's an example that checks if

SQLAlchemy introspection

[亡魂溺海] 提交于 2019-12-06 10:23:31
问题 What I am trying to do is to get from SqlAlchemy entity definition all it's Column()'s, determine their types and constraints, to be able to pre-validate, convert data and display custom forms to user. How can I introspect it? Example: class Person(Base): ''' Represents Person ''' __tablename__ = 'person' # Columns id = Column(String(8), primary_key=True, default=uid_gen) title = Column(String(512), nullable=False) birth_date = Column(DateTime, nullable=False) I want to get this id, title,

Automatically populate all properties of an Objective C instance with a dictionary

☆樱花仙子☆ 提交于 2019-12-06 06:02:58
I have a class with properties that I would like to set values from a dictionary. In other words, I would like to automate this: objectInstace.val1 = [dict objectForKey:@"val1"]; objectInstace.val2 = [dict objectForKey:@"val2"]; with something like this (pseudo code): for key, value in dict: setattr(objectInstance, key, value) You can use the Key-Value Coding method setValuesForKeysWithDictionary: . It does precisely what you want. Just [someObject setValuesForKeysWithDictionary:propertiesDictionary] . ok unless I'm missing something why not create a method like: setObjectProperties: (id)

add methods in subclasses within the super class constructor

筅森魡賤 提交于 2019-12-06 05:25:33
I want to add methods (more specifically: method aliases) automatically to Python subclasses. If the subclass defines a method named 'get' I want to add a method alias 'GET' to the dictionary of the subclass. To not repeat myself I'd like to define this modifation routine in the base class. But if I check in the base class __init__ method, there is no such method, since it is defined in the subclass. It will become more clear with some source code: class Base: def __init__(self): if hasattr(self, "get"): setattr(self, "GET", self.get) class Sub(Base): def get(): pass print(dir(Sub)) Output: ['

WinRT Reflection (C++/CX)

拜拜、爱过 提交于 2019-12-06 04:36:40
问题 how can I introspect an object in C++/CX? I known how to get its class name (using IInspectable) but I wasn't able to figure out how to get a list of its properties or how to invoke methods if I have just a name of the method (string). I searched for an answer here and at Google but what I found is related to the .NET layer of WinRT (the System.Reflection namespace doesn't seem to be available in C++/CX). 回答1: C++ doesn't provide any specific APIs to reflect on WinRT types, these types are

Pytest - Fixture introspect on function level

浪子不回头ぞ 提交于 2019-12-06 03:22:01
I've got a fixture that requires a variable from the test function. Using introspection and declaring the variable in the function namespace/context should work if introspection on function level works, as it does for module level, but each time I run the code I end up with None instead of the string "Fancy Table". In the fixture I set the scope to 'function' and then introspect via getattr and request.function: #conftest.py @pytest.fixture(scope='function') def table(request): from data_setup import create_table table_name = getattr(request.function, "table_name", None) create_table(request,