我希望能够在我的gtk.Menu中放置一个gtk.ProgressBar,但由于菜单只需要gtk.MenuItems及其子类,我所做的就是采用一个普通的gtk.MenuItem并尝试添加我的进度条作为一个孩子.由于gtk.MenuItem是gtk.Bin的子类,因此它应该能够容纳任何小部件.
例:
menu = gtk.Menu()
item = gtk.MenuItem()
button = gtk.ProgressBar()
button.pulse()
button.show()
item.add(button)
item.show()
menu.append(item)
Run Code Online (Sandbox Code Playgroud)
没有pygtk抱怨,这运行得很好.但是,我的进度条根本没有显示:

如果我用gtk.Label替换进度条,它就显示得很好.
现在问我的问题:
我有一个多维数组,看起来像这样:
ourThing = array(
'id' => 1,
'title' => 'foo',
'data' => array(
'name' => 'bar',
'metadata' => array(
'time' => '2011-02-01 12:00:00'
)
)
);
Run Code Online (Sandbox Code Playgroud)
现在,因为我不得不使用json_encode和json_decode对他们,我需要至少东西在存储data为UTF-8.不幸的是,该网站使用的是Windows-1252,这是我无法改变的.因为我可能希望将来在数组中添加更多级别(在数据内),我想我会递归地更改编码,如下所示:
function encode_items($arr) {
foreach ($arr as $n => $v) {
if (is_array($v))
encode_items($arr[$n]);
else
$arr[$n] = mb_convert_encoding($v, 'Windows-1252', 'UTF-8');
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.如果我在编码后立即打印$ arr [$ n],它就会出现,但原始数组似乎没有改变,因为当我稍后尝试从数组中打印出值时,我会遇到字符编码问题.
tl; dr:我需要将信息的编码ourThing['data']从utf-8更改为windows-1252.
我怎样才能使原始数组发生变化?
编辑:感谢有用的评论者,我现在知道我做错了什么.我忘了在进行编码后实际返回数组.这是一个有效的例子:
ourArray = array(
'id' => 1,
'title' => 'foo',
'data' => array(
'name' => 'bar',
'metadata' …Run Code Online (Sandbox Code Playgroud) 我正在使用Restler来实现一个简单的REST API.现在如果我需要从另一个域通过AJAX使用该API,我将需要发送一个回调参数以及我的请求.在Restler中是否有对此的支持(我还没有找到任何真实的文档)?
我正在尝试使用Python和Mechanize登录网站,但是,当我试图让POST数据按照我的意愿行事时,我遇到了麻烦.
基本上我想使用mechanize和Python来复制它:
wget --quiet --save-cookies cookiejar --keep-session-cookies --post-data "action=login&login_nick=USERNAME&login_pwd=PASSWORD" -O outfile.htm http://domain.com/index.php
Run Code Online (Sandbox Code Playgroud)
表单如下所示:
<login POST http://domain.com/index.php application/x-www-form-urlencoded
<TextControl(login_nick=USERNAME)>
<PasswordControl(login_pwd=PASSWORD)>
<CheckboxControl(login_auto=[1])>
<SubmitButtonControl(<None>=) (readonly)>>
Run Code Online (Sandbox Code Playgroud)
设置适当的值并提交表单不是问题,但是省略了"action = login"-part.
response = self.browser.open(self.url+"/index.php")
self.browser.select_form(name="login")
self.browser["login_nick"] = self.encoded_username
self.browser["login_pwd"] = self.encoded_password
self.browser.method = "POST"
response = self.browser.open(self.browser.submit())
print (response.read())
Run Code Online (Sandbox Code Playgroud)
现在的问题是,我该如何添加action=login零件?
编辑:好的,所以我添加了一个名为action的隐藏字段并将值设置为login.使用Wireshark分析TCP流,POST数据确实按照应有的方式构建.然而,似乎机械化正在弄乱我的urlencoding(我已经为网站使用的charset专门编写了值).例如,我的用户名包含Å - 我已将其urlencoded为%C5.但是,当它与机械化一起发送时,它显示为%25C5. 如何通过更改字符串来停止机械化?
编辑:我意识到,在发送机器人之前,我可能不会对我的字符串进行urlencode.案件结案.
给定一个偶数个单元格的网格,其中网格边缘上的两个单元格缺失,我想形成成对的相邻单元格,使得没有合作伙伴没有剩余单元格(不计算"缺失"单元格) .
根据放置两个"缺失"单元的位置,我相信它总是可能或总是不可能做出这样的安排.我在这里画了两个例子,左边的绘图是成功的尝试,右边的绘图是不成功的尝试(两个单元格没有合作伙伴).为摇摇欲坠的相机手道歉.

单元格内的箭头表示该单元与哪个邻居合作.
我有两个问题:
我怎么知道放置"缺失"细胞的安全位置,而不是让每个细胞都成为伴侣?
在给定上面提到的条件的情况下,创建这样的排列的算法会是什么样的,并且还假设单元格表可以更大(尽管总是具有偶数个单元格)并且不一定是正方形(但是矩形)?示例可以是3x4网格或6x6网格.
我还不知道如何知道放置"缺失"单元的安全位置,但只要它们处于已知安全的位置,我的算法如下:
1. For each cell that isn't "missing" or already paired, iterating from top-left to bottom right, horizontally first:
2. Choose a random neighbor to form a pair with: either right or bottom.
3. Check all the cells to see if there are any cells that cannot make a pair, if so:
4. Undo the last pair, go back to 2 and choose the other neighbor.
Run Code Online (Sandbox Code Playgroud)
我完全不知道图论或其他什么可以帮助我找到一个好的解决方案,所以我非常感谢你能给予的任何帮助.任何非超级晦涩的语言中的伪代码或真实代码都会很棒,简单的文本解释也是如此.
我有一个ListView,它显示来自API的一些数据.在我的列表项中,我需要有两个不同的组件树,具体取决于该行的数据.更具体地说,如果行具有关联的图像,我需要以特定方式显示带有标签的图像.如果它没有图像,那么我想只显示一个标签,以不同的方式排列.对我来说,这听起来像我想要创建两个不同的组件,并动态选择要包含的组件.
它目前看起来像这样,缩写形式:
ListItem.Empty {
id: matchItem
property string team1Name
property string team2Name
property string team1Logo
property string team2Logo
width: parent.width
Item {
id: team1Info
width: parent.width*0.3
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
}
Item {
anchors.fill: parent
anchors.margins {
top: units.gu(2)
bottom: units.gu(2)
}
Image {
id: team1LogoImage
source: team1Logo
width: parent.width
height: units.gu(5)
fillMode: Image.PreserveAspectFit
anchors.horizontalAlignment: parent.horizontalCenter
}
Label {
text: team1Name
anchors.horizontalAlignment: Text.Center
}
}
}
// Some more elements and a repeat of the above …Run Code Online (Sandbox Code Playgroud) php ×2
python ×2
algorithm ×1
appindicator ×1
graph-theory ×1
mechanize ×1
pygtk ×1
qml ×1
rest ×1
ubuntu-touch ×1
webforms ×1