我需要在用Python编写的应用程序中监听Mac上的全局鼠标事件(未绑定到应用程序).
我正在使用PyObjC,但我无法弄清楚如何做到这一点.简单的ObjC示例或其他Python技术也很受欢迎.
我的代码到目前为止:
from Quartz import *
def MyFunction(proxy, type, event):
print event
CGEventTapCreate(kCGHIDEventTap, kCGTailAppendEventTap, kCGEventTapOptionListenOnly, kCGEventLeftMouseDown, MyFunction)
Run Code Online (Sandbox Code Playgroud)
==分段错误
我知道我需要稍后将它添加到事件源中,但我需要首先使用它.
[更新]
使用PyObjC形式Macports解决了段错误,所以现在我写了这个:
from Quartz import *
def MyFunction(p, t, e, c):
print e
tap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, kCGEventLeftMouseDown, MyFunction, None)
runLoopSource = CFMachPortCreateRunLoopSource(None, tap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
CGEventTapEnable(tap, True);
CFRunLoopRun();
Run Code Online (Sandbox Code Playgroud)
但这只是永远运行而且不响应鼠标事件,有什么不对?
所以我弄错了.
在最初为API编写签名时,我创建了以下内容:
public JellyBeanResult getJellyBeanReport();
Run Code Online (Sandbox Code Playgroud)
现在,事实证明我想重新使用更具体的JellyBeanResult对象,因为它的功能,但让其他函数返回一个为不同进程命名的类型会让人感到困惑.我可以想到有几种方法可以解决这个问题.我可以将返回类型重命名为更通用的类型:
public GenericResult getJellyBeanReport();
public GenericResult getChocolateBarReport();
Run Code Online (Sandbox Code Playgroud)
但这会破坏使用API的任何代码.我可以创建一个新的,更准确的命名类,它扩展了更接近新函数的SpecificResult:
public class ChocolateBarResult extends JellyBeanResult{};
public JellyBeanResult getJellyBeanReport();
public ChocolateBarResult getChocolateBarReport();
Run Code Online (Sandbox Code Playgroud)
但这真的非常难看,如果我想再次使用返回类型,问题仍然存在.如何在不破坏使用它们的代码的情况下清理这些签名以减少它们的混乱?
我有一个关于C++中运算符重载的返回值的问题.通常,我发现了两种情况,一种是按值返回,一种是按引用返回.那么这个规则是什么呢?特别是在可以连续使用操作员的情况下,例如cout<<x<<y.
例如,当实现+操作"string +(string)"时.你将如何通过ref或val返回返回值.
我有一个问题单元测试一个类,当一个线程启动并完成时会触发事件.违规来源的简化版本如下:
public class ThreadRunner
{
private bool keepRunning;
public event EventHandler Started;
public event EventHandler Finished;
public void StartThreadTest()
{
this.keepRunning = true;
var thread = new Thread(new ThreadStart(this.LongRunningMethod));
thread.Start();
}
public void FinishThreadTest()
{
this.keepRunning = false;
}
protected void OnStarted()
{
if (this.Started != null)
this.Started(this, new EventArgs());
}
protected void OnFinished()
{
if (this.Finished != null)
this.Finished(this, new EventArgs());
}
private void LongRunningMethod()
{
this.OnStarted();
while (this.keepRunning)
Thread.Sleep(100);
this.OnFinished();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个测试来检查Finished事件在LongRunningMethod完成之后如下所示:
[TestClass] …Run Code Online (Sandbox Code Playgroud) 我需要能够从URL中提取方案,主机和端口.
所以,如果我在浏览器中的网址是:http://www.example.com:80/something.pl
我需要能够得到:http://www.example.com:80
我知道你不应该编写缓存所有异常类型的代码.
try
{
//code that can throw an exception
}
catch
{
//what? I don't see no
}
Run Code Online (Sandbox Code Playgroud)
相反,你应该做更像下面的代码的事情,允许你没有想到的任何其他异常.
try
{
//code that can throw an exception
}
catch(TypeAException)
{
//TypeA specific code
}
catch(TypeBException)
{
//TypeB specific code
}
Run Code Online (Sandbox Code Playgroud)
但如果你用另一个异常包装它们,是否可以捕获所有异常类型?考虑下面的这个Save()方法我写的是Catalog类的一部分.我是否有任何错误捕获所有异常类型并返回单个自定义CatalogIOException,原始异常作为内部异常?
基本上我不希望任何调用代码必须知道可能在Save()方法中抛出的所有特定异常.他们只需要知道他们是否试图保存只读目录(CatalogReadOnlyException),目录无法序列化(CatalogSerializationException),或者是否存在写入文件的问题(CatalogIOException).
这是处理异常的好方法还是坏方法?
/// <summary>
/// Saves the catalog
/// </summary>
/// <exception cref="CatalogReadOnlyException"></exception>
/// <exception cref="CatalogIOException"></exception>
/// <exception cref="CatalogSerializingExeption"></exception>
public void Save()
{
if (!this.ReadOnly)
{
try
{
System.Xml.Serialization.XmlSerializer serializer = new XmlSerializer(typeof(Catalog));
this._catfileStream.SetLength(0); //clears the file …Run Code Online (Sandbox Code Playgroud) 我正进入(状态
ORA-30926:无法在源表中获得稳定的行集
在以下查询中:
MERGE INTO table_1 a
USING
(SELECT a.ROWID row_id, 'Y'
FROM table_1 a ,table_2 b ,table_3 c
WHERE a.mbr = c.mbr
AND b.head = c.head
AND b.type_of_action <> '6') src
ON ( a.ROWID = src.row_id )
WHEN MATCHED THEN UPDATE SET in_correct = 'Y';
Run Code Online (Sandbox Code Playgroud)
我运行table_1它有数据,我也运行内部查询(src)也有数据.
为什么会出现此错误以及如何解决?
我想创建一个投票系统,可以对多个域对象进行投票:
所以我想我会Voteable为这些项创建一个接口:
interface Voteable
{
public function vote( User $user, $value );
}
Run Code Online (Sandbox Code Playgroud)
我认为这个vote方法会代理一个存储库方法,例如:
class VotingRepository
{
public function castVote( Voteable $item, User $user, $value )
{
// save the these values, along with the value
$itemId = $item->getId();
$userId = $user->getId();
}
}
Run Code Online (Sandbox Code Playgroud)
目前,存储库将是一个数据库.该数据库将具有每种投票类型的链接表:
因此,这实际上意味着每个域对象都需要另一个表来投票.这对工厂来说是个好人吗?一个VotingRepositoryFactory在这种情况下?换句话说,像:
class VotingRepositoryFactory
{
createVotingRepository( $type )
{
switch( $type )
{
case 'event':
// create a voting repository with EventVote table
return …Run Code Online (Sandbox Code Playgroud) 我已经阅读了无数的教程,并且我一直在努力.这是我得到的:
- 我在我的Windows桌面上运行RubyMine
- 我按照他们的指示在我的WebFaction主机帐户上安装了Git
- Git似乎在两台机器上都运行正常
这就是我正在做的事情:
1.在服务器上:
a.mkdir 项目
b.git init
c.git add.
d.git commit <---"没什么可提交的"
2.在客户端:
a.在RubyMine中创建新项目.
湾 项目
c的顶级目录中的"git init" ."推送更改"到服务器<----"无法将某些引用推送到......".
我错过了哪些步骤?
我正在尝试使用minidom在我的XML文档中包含对DTD的引用.
我正在创建文档,如:
doc = Document()
foo = doc.createElement('foo')
doc.appendChild(foo)
doc.toxml()
Run Code Online (Sandbox Code Playgroud)
这给了我:
<?xml version="1.0" ?>
<foo/>
Run Code Online (Sandbox Code Playgroud)
我需要得到类似的东西:
<?xml version="1.0" ?>
<!DOCTYPE something SYSTEM "http://www.path.to.my.dtd.com/my.dtd">
<foo/>
Run Code Online (Sandbox Code Playgroud)