我在这里要做的是使用PIL将Tkinter Canvas的内容保存为.png图像.
这是我的保存功能('graph'是画布).
def SaveAs():
filename = tkFileDialog.asksaveasfilename(initialfile="Untitled Graph", parent=master)
graph.postscript(file=filename+".eps")
img = Image.open(filename+".eps")
img.save(filename+".png", "png")
Run Code Online (Sandbox Code Playgroud)
但它得到了这个错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Users\Adam\Desktop\Graphing Calculator\Graphing Calculator.py", line 352, in SaveAs
img.save(filename+".png", "png")
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1406, in save
self.load()
File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 283, in load
self.im = Ghostscript(self.tile, self.size, self.fp)
File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 72, in Ghostscript
gs.write(s)
IOError: [Errno 32] Broken pipe
Run Code Online (Sandbox Code Playgroud)
我在Windows 7,Python 2.7.1上运行它.
我该如何工作?
我目前正在开发 Win32 应用程序,我希望在系统任务栏中有一个图标。我用来Shell_NotifyIcon显示图标,它工作得很好,但图标经常消失,没有解释......
事实上,当我在构建代码后第一次在 Visual Studio 2013 中运行代码时,或者当我从另一个.exe目录中运行应用程序时,就会出现该错误(我没有出现任何错误,例如missing dll应用程序正在运行,但图标不再存在...)。
我用来创建图标的代码:
// At the beginning of the file
static NOTIFYICONDATA m_nid ;
// After
m_nid.cbSize = sizeof (m_nid);
m_nid.hWnd = hwnd;
m_nid.uVersion = NOTIFYICON_VERSION_4 ;
static const GUID myGUID =
{0x5CA81ADA, 0xA481, 0x4BA8, {0x8B, 0x70, 0x80, 0x3f, 0x48, 0x67, 0xA1, 0x68}};
m_nid.guidItem = myGUID;
m_nid.uFlags = NIF_ICON | NIF_TIP | NIF_GUID | NIF_MESSAGE ;
m_nid.uCallbackMessage = WM_SYSTEM_TRAY;
StringCchCopy (m_nid.szTip, ARRAYSIZE (m_nid.szTip), NotificationManager::APPLICATION_NAME.c_str ());
m_nid.hIcon = …Run Code Online (Sandbox Code Playgroud) class A: public B, public C { };
Run Code Online (Sandbox Code Playgroud)
在这种情况下,执行顺序是:
B(); // base(first)
C(); // base(second)
A(); // derived
Run Code Online (Sandbox Code Playgroud)
class A: public B, virtual public C { };
Run Code Online (Sandbox Code Playgroud)
但是在这种情况下,当我在继承时用c类写虚拟时,顺序为
// execution becomes:
C(); // virtual base
B(); // ordinary base
A(); // derived
Run Code Online (Sandbox Code Playgroud)
我已经读过某个地方,调用构造函数的顺序依赖于声明的顺序,同时继承多个类但是如何在用类编写虚拟时改变执行的顺序.我无法理解为什么我得到这样的结果.
我如何能圆一个FLOAD 了到下一个奇数.我发现在这里偶数可以做到这一点.所以我尝试了类似的东西:
import numpy as np
def round_up_to_odd(f):
return np.ceil(f / 2.) * 2 + 1
Run Code Online (Sandbox Code Playgroud)
但当然这不会将其舍入到NEXT奇数:
>>> odd(32.6)
35.0
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我一直在尝试在Cakephp 3.0.11中设置Ajax调用.我按照这里的解释:http://book.cakephp.org/3.0/en/views/json-and-xml-views.html
Json在路由中启用(但我不确定它是否有用):
$routes->extensions(['json', 'xml', 'html']);
Run Code Online (Sandbox Code Playgroud)
我在控制器中设置了我的例子:
$returnObject = new ObjectReturn();
$this->set('returnObject', $returnObject);
$this->set('_serialize', ['returnObject']);
Run Code Online (Sandbox Code Playgroud)
但当我打电话给我时,我得到了:
{
"message": "Template file \Pages\\score.ctp\ is missing.",
"url": "\/pages\/score",
"code": 500
}
Run Code Online (Sandbox Code Playgroud)
如果我创建页面,他会使用default.ctp作为布局来渲染我一些html.这有什么不对?
非常感谢 !
根据这个问题的第一个答案:函数模板重载,"非模板化(或"模板化程度较低")重载优于模板".
#include <iostream>
#include <string>
#include <functional>
void f1 (std::string const& str) {
std::cout << "f1 " << str << std::endl;
}
template <typename Callback, typename... InputArgs>
void call (Callback callback, InputArgs ...args) {
callback(args...);
}
void call (std::function<void(std::string const&)> callback, const char *str) {
std::cout << "custom call: ";
callback(str);
}
int main() {
auto f2 = [](std::string const& str) -> void {
std::cout << "f2 " << str << std::endl;
};
call(f1, "Hello World!"); …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
struct C
{
int d1;
int d2;
};
struct A
{
void write(C data)
{
}
};
struct B
{
void use(C data)
{
}
};
Run Code Online (Sandbox Code Playgroud)
现在我想定义一个使用A或B调用它们write和use方法的新类.像这样的东西:
template <class T>
struct D
{
T t;
D(T myT) { t=myT; }
void myFunct(C data)
{
// t.????(data);
}
};
Run Code Online (Sandbox Code Playgroud)
正如你可以看到这两个类是否有类似的方法名称,那么它很容易实现D,但由于A并且B有不同的方法,那么我需要告诉编译器它应该使用哪种方法.我怎样才能做到这一点?
我不想改变A或者B我也不想创建一个子类,A并B创建一个具有相同名称的方法.
我想要一种方法告诉编译器使用哪种方法作为模板的一部分,是否可能?
当实现我自己的unique_ptr(只是为了好玩),我发现它无法通过这个测试文件来自libstdcxx:
struct A;
struct B
{
std::unique_ptr<A> a;
};
struct A
{
B* b;
~A() { VERIFY(b->a != nullptr); }
};
void test01()
{
B b;
b.a.reset(new A);
b.a->b = &b;
}
Run Code Online (Sandbox Code Playgroud)
gcc愉快地传递了这个测试文件(当然,这个文件是来自libstdcxx),而clang因为VERIFY部分失败了.
题:
b->a != nullptr)对于gcc很重要,否则它没有测试文件,但我不知道它背后是什么.它与优化有关吗?我知道很多UB都是为了更好的优化.Here is a header file containing an inline variable:
// inline.hpp
#pragma once
#include <iostream>
struct Test {
~Test() { std::cout << "deleted" << std::endl; }
};
inline const Test test;
Run Code Online (Sandbox Code Playgroud)
...included into two .cpp files:
// usage.cpp
#include "inline.hpp"
Run Code Online (Sandbox Code Playgroud)
// main.cpp
#include "inline.hpp"
auto main() -> int { return 0; }
Run Code Online (Sandbox Code Playgroud)
This program prints "deleted" twice which is unexpected. I thought there was only a single instance of every inline variable, so I was expecting only one "deleted".
Is …
我正在开发一个拖放功能,它允许我在画布上移动项目。我让它工作(有点),但我只稍微移动,但线穿过屏幕(并最终离开屏幕的可见部分)画布,所以我无法到达它。我不知道从这里去哪里。下面是我到目前为止创建的拖放代码:
def onPressToMove(self, event): #get initial location of object to be moved
winX = event.x - self.workspace.canvasx(0)
winY = event.y - self.workspace.canvasy(0)
self.dragInfo["Widget"] = self.workspace.find_closest(event.x, event.y, halo = 5)[0]
self.dragInfo["xCoord"] = winX
self.dragInfo["yCoord"] = winY
def onReleaseToMove(self, event): #reset data on release
self.dragInfo["Widget"] = None
self.dragInfo["xCoord"] = 0
self.dragInfo["yCoord"] = 0
def onMovement(self, event):
winX = event.x - self.workspace.canvasx(0)
winY = event.y - self.workspace.canvasy(0)
newX = winX - self.dragInfo["xCoord"]
newY = winY - self.dragInfo["yCoord"]
self.workspace.move(self.dragInfo["Widget"], newX, newY)
Run Code Online (Sandbox Code Playgroud)
DragInfo 是我用来存储数据的字典。最初我认为将画布坐标转换为窗口坐标会有所帮助,但它的作用与没有这些东西时相同。