我正在寻找一个与图库窗口小部件类似的窗口小部件,但是垂直滚动而不是水平滚动.我四处搜索,显然答案是没有这样的预制小部件存在.
所以我说自己,哦,好吧,我会看一下android源代码中的gallery类,并修改它来垂直滚动.不那么容易.android SDK隐藏了很多东西(可以理解为框架维护),但它也使得扩展小部件变得非常困难.例如,gallery类使用了很多来自其父级的成员变量,AbsSpinner(mSelectedPosition,etc等),以及它的父级父级等......从app-developer的角度来看,它们根本无法访问.如果无法访问这些成员变量,我就无法使用库类中的类似代码供我自己使用.
如果没有向上移动继承链并将这些父类的源代码全部放在我的项目中,或者从头开始编写小部件而不使用已经解决问题的现有框架小部件,我找不到一种方法来获取垂直滚动图库.
有更好的方法吗?为什么android框架使扩展小部件变得如此困难?
对于单索引数据框,这些列在按对象分组中可用:
df1 = pd.DataFrame({'a':[2,2,4,4], 'b': [5,6,7,8]})
df1.groupby('a')['b'].sum() ->
a
2 11
4 15
Run Code Online (Sandbox Code Playgroud)
但是在MultiIndex数据框中,如果不按级别分组,则无法再按对象分组访问列
df = pd.concat([df1, df1], keys=['c', 'd'], axis=1)
df ->
c d
a b a b
0 2 5 2 5
1 2 6 2 6
2 4 7 4 7
3 4 8 4 8
df.groupby([('c','a')])[('c','b')].sum() ->
KeyError: "Columns not found: 'b', 'c'"
Run Code Online (Sandbox Code Playgroud)
作为一种解决方法,此方法有效,但效率不高,因为它不使用cpythonized聚合器,更不用说它看上去很尴尬。
df.groupby([('c','a')]).apply(lambda df: df[('c', 'b')].sum())
Run Code Online (Sandbox Code Playgroud)
有没有办法访问我错过的groupby对象中的MultiIndex列?
问题为标题.
更具体地说,\(每次我想在Emacs(交互式)regexp函数中使用括号(更不用说\\(代码中)时,我都厌倦了必须输入等等.所以我写了类似的东西
(defadvice query-replace-regexp (before my-query-replace-regexp activate)
(ad-set-arg 0 (replace-regexp-in-string "(" "\\\\(" (ad-get-arg 0)))
(ad-set-arg 0 (replace-regexp-in-string ")" "\\\\)" (ad-get-arg 0)))))
Run Code Online (Sandbox Code Playgroud)
希望在"交互模式"期间我可以方便地忘记emage在regexp中的特性.除了我不能正确的regexp ...
(replace-regexp-in-string "(" "\\\\(" "(abc")
Run Code Online (Sandbox Code Playgroud)
给出\\(abc的,而不是想要的\(abc.斜杠数量的其他变化只会产生错误.思考?
自从我开始提问以来,不妨问另一个:由于lisp代码不应该使用交互功能,建议query-replace-regexp应该没问题,我是否正确?
为简单起见
class Parent {}
class Child1 : Parent {}
class Child2 : Parent {}
Run Code Online (Sandbox Code Playgroud)
在其他地方,我创建了Child1和Child2的实例,并将其存储在Parent下的相同向量中:
// . . . in .h file, for example
vector<Parent> vector_of_parent;
// . . . in one particular method
Child1 c1;
Child2 c2;
vector_of_parent.push_back(c1);
vector_of_parent.push_back(c2);
// . . .
Run Code Online (Sandbox Code Playgroud)
然后在另一种有权访问的方法中vector_of_parent,我试过了
void doSomething(Parent& some_child) {
// wrapped in a try block somehow...
Child1& c = dynamic_cast<Child1&> some_child;
// do something if the cast is successful
}
void otherMethod() {
doSomething(vector_of_parent.at(0)); // vector_of_parent.at(0) is a …Run Code Online (Sandbox Code Playgroud) g ++抱怨
myclass.cxx:185: error: no matching function for call to 'IMyInterface::doSomething(const SomeClass*, unsigned int)'
IMyInterface.h:34: note: candidates are: virtual void IMyInterface::doSomething(const SomeClass*&, unsigned int)
Run Code Online (Sandbox Code Playgroud)
我打电话的时候
m_instanceOfInterface->doSomething((const SomeClass*)0,(unsigned int)1);
Run Code Online (Sandbox Code Playgroud)
任何指针为什么?在我看来,g ++在声明的内容和被调用的内容之间看到完全相同的签名,但仍然抱怨找不到匹配的函数.
我可以打电话,在同样的情况下,另一种功能IMyInteface,IMyInterface::doSomethingElse(float& p).所以不知何故const问题是什么?
我没有传递NULL指针并为了好玩而抛出一个常量整数...原来我有
m_instanceOfInterface->doSomething((const SomeClass*)m_someDerivedClass,m_anInteger);
Run Code Online (Sandbox Code Playgroud)
并得到了同样的错误.因此,我决定通过提供一些明确的论证来澄清g ++的内容.我可以向你保证,NULL指针不是问题 - 虽然可以理解的是,当看到传递的NULL时,我们都有点畏缩const:)