这个问题经常被问到,但从来没有真正回答过.让我们看看我们是否可以补救它!
Google允许您使用事件处理程序通过其API绑定到Google Map View中的事件.
有时您可以将事件处理程序绑定到Google 本身已绑定的事件.因此,当您的事件触发并执行您告诉它的任何操作时,您可能会发现Google同时也在做自己的小事.
嗯,我可以处理事件,以便我的代码运行,但是阻止事件继续并解雇Google的事件处理程序?
你确定可以!欢迎来到Event Propagation(又名事件冒泡).
在这里,我绑定一个事件处理程序来双击Google Map:
var aListener = google.maps.event.addListener(map, 'dblclick', function(event) {
// Try to prevent event propagation to the map
event.stop();
event.cancelBubble = true;
if (event.stopPropagation) {
event.stopPropagation();
}
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
});
Run Code Online (Sandbox Code Playgroud)
这map是一个要绑定的Google Map对象.
这不起作用.事件冒泡,地图放大.我不知道为什么.
你问,你读过文件吗?
确实.该文件说,使用event.stop();
我看过别人说的话.这个问题正是我的问题.它被标记为已修复,但解决方案不起作用.
想法?
doubleclick事件的一种可能的解决方法是在您需要它时不要触发Google的默认行为,然后再重新启用它.
你用这个disableDoubleClickZoom参数做到这一点.请参阅 …
javascript event-handling mouseevent event-propagation google-maps-api-3
我在python中运行一个小程序,启动一个小窗口,需要保持在所有其他窗口之上.我相信这是特定于操作系统的,如何在使用GNOME的GNU-Linux中完成?
[ 更新 - Windows解决方案 ]
可爱,我觉得我搞定了.我在Vista 64位的Eclipse中使用Python 2.5.4和Pygame 1.9.1.因此,这适用于Windows系统.该SetWindowPos功能记录在这里.我将在我的解释中提到这一点.
进口:
from ctypes import windll
Run Code Online (Sandbox Code Playgroud)
然后我在user32中设置一个调用"SetWindowPos"的变量:
SetWindowPos = windll.user32.SetWindowPos
Run Code Online (Sandbox Code Playgroud)
现在,让我们说我刚做了一个窗口:
screen = pygame.display.set_mode((100,100), pygame.NOFRAME)
Run Code Online (Sandbox Code Playgroud)
下一行是关键.这将窗口设置在其他窗口的顶部.
SetWindowPos(pygame.display.get_wm_info()['window'], -1, x, y, 0, 0, 0x0001)
Run Code Online (Sandbox Code Playgroud)
基本上,您为hWnd(窗口句柄)提供从调用返回的窗口ID display.get_wm_info().现在该函数可以编辑刚刚初始化的窗口.
这-1是我们的hWndInsertAfter.
MSDN网站说:
通过将hWndInsertAfter参数设置为HWND_TOPMOST并确保未设置SWP_NOZORDER标志,或者通过设置Z顺序中的窗口位置使其位于任何现有的最顶层窗口之上,可以将窗口设置为最顶层窗口.当一个非最顶层的窗口最顶层时,它拥有的窗口也是最顶层的.然而,它的主人并没有改变.
因此,-1确保窗口位于任何其他现有的最顶层窗口之上,但这可能在所有情况下都不起作用.也许-2比一个-1?它目前适合我.:)
在x与y该窗口中指定的新坐标被设置.我希望窗口在SetWindowPos调用函数时保持当前位置.唉,我找不到一种方法可以轻松地将当前窗口(x,y)位置传递到函数中.我能够找到一个解决方案,但我想我不应该在这个问题中引入一个新主题.
所述0, 0,应该指定窗口的新的宽度和高度,以像素为单位.好吧,该功能已经在您的pygame.display.set_mode()函数中,所以我将它们保留为0. 0x0001忽略这些参数.
0x0001对应SWP_NOSIZE,是我唯一的uFlag.所提供的文档页面上列出了所有可用的uFlag.他们的一些十六进制表示如下:
为什么以下代码:
use strict;
use warnings;
no warnings 'uninitialized';
use Data::Dumper;
my $user;
my @data = @{$user->{ENTERPRISE}}; # Error on this line
print Dumper($user), qq{Done!\n};
Run Code Online (Sandbox Code Playgroud)
抛出错误" Can't use an undefined value as an ARRAY reference",而以下代码:
use strict;
use warnings;
no warnings 'uninitialized';
use Data::Dumper;
my $user;
foreach my $enterprise(@{$user->{ENTERPRISES}}) {
print qq{Enterprise:}, $enterprise;
}
print Dumper($user), qq{Done!\n};
Run Code Online (Sandbox Code Playgroud)
不抛出任何东西,而是返回:
$VAR1 = {
'ENTERPRISES' => []
};
Done!
Run Code Online (Sandbox Code Playgroud)
两者都有违规代码,但只有一个抛出错误.
可能的答案: Perl的自动化?
我在这里走在正确的轨道上吗?感谢您的输入.
我在我的论文中使用与列表 LaTeX包一起铸造样式代码片段.
我正在尝试更改代码片段的编号系统section.numberinsection.因此,下面我的示例中的两个代码片段将是1.1和1.2.如果第2部分中有第三个片段则会被编号2.1.
我这样做,因此list of code snippets也有类似的编号方案的list of tables和list of figures那些已经在我的论文,并有我在默认情况下寻求行为.
目前,片段的计数器仅从纸张中的每个片段的1开始递增.
我试图在下面的代码中使用此特定行来更改输出:\AtBeginDocument{\renewcommand*{\thelstlisting}{\thesection.\arabic{lstlisting}}}但它似乎不起作用.
思考?
\documentclass{thesis}
% Imports
\usepackage{listings}
\usepackage{minted}
% Style Minted
\usemintedstyle{default}
\definecolor{codebg}{rgb}{0.96,0.96,0.96}
\newminted{python}{bgcolor=codebg,
linenos=true,
frame=lines,
numbersep=5pt,
fontsize=\footnotesize}
\renewcommand\listoflistingscaption{LIST OF CODE SNIPPETS}
\renewcommand\listingscaption{Code Snippet}
% Style Listings
\AtBeginDocument{\renewcommand*{\thelstlisting}{\thesection.\arabic{lstlisting}}}
\begin{document}
\listoflistings
\chapter{A Chapter}
\section{A Section}
\subsection{A Sub-Section}
Nam pulvinar euismod facilisis. Quisque vel sagittis diam. In ut egestas sem. Cras …Run Code Online (Sandbox Code Playgroud) 我正在使用argparse读取我的python代码的参数.其中一个输入是文件[ title] 的标题,它可以包含Unicode字符.我一直在22????22用作测试字符串.
我需要将输入的值写入title文件,但是当我尝试将字符串转换为UTF-8它时,总是会抛出错误:
UnicodeDecodeError:'ascii'编解码器无法解码位置2中的字节0x8f:序数不在范围内(128)
我一直在环顾四周,看到我需要我的字符串u"foo"才能调用.encode()它.
当我运行type()我的输入时,argparse我看到:
<type 'str'>
Run Code Online (Sandbox Code Playgroud)
我希望得到一个回应:
<type 'unicode'>
Run Code Online (Sandbox Code Playgroud)
我怎样才能以正确的形式获得它?
理念:
修改argparse以接收a str但将其存储为unicode字符串u"foo":
parser.add_argument(u'title', metavar='T', type=unicode, help='this will be unicode encoded.')
Run Code Online (Sandbox Code Playgroud)
这种方法根本不起作用.思考?
编辑1:
一些示例代码,其中title是22????22:
inputs = vars(parser.parse_args())
title = inputs["title"]
print type(title)
print type(u'foo')
title = title.encode('utf8') # This line throws the error
print title
Run Code Online (Sandbox Code Playgroud) 我正在使用pygame和pyro在python中开发一个项目.我可以轻松地发送数据,函数,类等.但是,我不能在电线上发送表面而不会在运输途中死亡.
服务器在def __init__通过网络访问的类中创建一个表面:
self.screen = pygame.display.set_mode(SCREENRECT.size, NOFRAME)
Run Code Online (Sandbox Code Playgroud)
在服务器上,屏幕打印为Surface(800x800x32 SW),但当客户端检索时,它是Surface(Dead Display).
值得注意的是.当我使用访问器功能来获取我的屏幕时,我得到一个死显示.如果我print Player.screen用来获取变量,我会得到一个似乎是指向屏幕的pyro指针:<Pyro.core._RemoteMethod instance at 0x02B7B7B0>.也许我可以解除这个?
我很可能很厚,有没有人有一些见解?谢谢.:)