实现键盘处理的好方法是什么?在我编写键盘交互式程序(如俄罗斯方块游戏)的任何语言中,我最终得到的代码如下所示:
for event in pygame.event.get():
if event.type == KEYDOWN:
if False: pass #make everything an elif
elif rotating: pass
elif event.key == K_q:
elif event.key == K_e:
elif event.key == K_LEFT:
curpiece.shift(-1, 0)
shadowpiece = curpiece.clone(); setupshadow(shadowpiece)
elif event.key == K_RIGHT:
curpiece.shift(1, 0)
shadowpiece = curpiece.clone(); setupshadow(shadowpiece)
Run Code Online (Sandbox Code Playgroud)
(缩短).我不喜欢这个,因为这必须在我的主循环中,并且它与程序的所有部分混淆.这也使得用户配置屏幕不可能改变哪个键映射到哪个动作.使用某种形式的函数回调是否有良好的模式?
人们在Python交互式启动脚本中放置了哪些常见的时间节点?当我尝试进行相关文件操作或者imports时,我做了一个笨重的工作来帮助我知道我在哪里,使用win32模块更改控制台窗口的名称.
import sys
import os
import win32api
__title_prefix = 'Python %i.%i.%i %s %s' % (sys.version_info[0:4] +
(sys.version_info[4] or "",))
def __my_chdir(path):
__os_chdir(path)
win32api.SetConsoleTitle(__title_prefix + " - " + os.getcwd())
# replace chdir func
__os_chdir = os.chdir
os.chdir = __my_chdir
os.chdir(r'C:\Scripts')
Run Code Online (Sandbox Code Playgroud) 我对Haskell很新,所以我正在寻找一种简单的方法来检测按键,而不是使用getLine.
如果有人知道任何库,或者这样做的一些技巧,那就太好了!
如果有更好的地方可以问这个问题,请指导我,我很感激.
我正在尝试使用R中的rgl包为交互式3D绘图添加固定标题,但到目前为止我还没能做到.我还希望在主标题下有一个主标题和副标题.
这是一个示例代码,
library(rgl)
data<-read.table(text=" X Y Z
1 147.0883 -18.69122 -13.90000
2 147.0894 -18.69455 -10.97250
3 147.0883 -18.69122 -17.45000
4 147.0883 -18.69122 -15.44000
5 147.0883 -18.69122 -13.45000
6 147.0909 -18.69922 -12.25000
7 147.0883 -18.69122 -17.30000
8 147.0883 -18.69122 -16.40000
9 147.0883 -18.69122 -14.30000
10 147.0883 -18.69122 -18.50000
11 147.0883 -18.69122 -15.67606
12 147.0883 -18.69122 -17.25780
13 147.0883 -18.69122 -3.64000
14 147.1164 -18.68133 -22.13000
15 147.0883 -18.69122 -18.54778
16 147.0883 -18.69122 -15.50000
17 147.1185 -18.68691 -14.55500
18 147.0883 -18.69122 -18.12500
19 …Run Code Online (Sandbox Code Playgroud) 我想在ViewController(1)和NavigationViewController(2)之间进行交互式转换.
NavigationController由一个按钮调用,因此在呈现时没有交互式转换.它可以通过按钮或UIPanGestureRecognizer来解除,因此它可以被交互或不被解雇.
我有一个名为TransitionManager的对象,用于转换,UIPercentDrivenInteractiveTransition的子类.
下面的代码的问题interactionControllerFor...是永远不会调用两个委托方法.
此外,当我按下按钮或swip(UIPanGestureRecognizer)时,模态segue的基本动画完成.所以这两个委托方法animationControllerFor...也不起作用.
有任何想法吗 ?谢谢
let transitionManager = TransitionManager()
override func viewDidLoad() {
super.viewDidLoad()
self.transitioningDelegate = transitionManager
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let dest = segue.destinationViewController as UIViewController
dest.transitioningDelegate = transitionManager
dest.modalPresentationStyle = .Custom
}
Run Code Online (Sandbox Code Playgroud)
class TransitionPushManager: UIPercentDrivenInteractiveTransition,
UINavigationControllerDelegate, UIViewControllerTransitioningDelegate {
@IBOutlet var navigationController: UINavigationController!
var animation : Animator! // Implement UIViewControllerAnimatedTransitioning protocol
override func awakeFromNib() {
var panGesture = UIPanGestureRecognizer(target: self, action: "gestureHandler:")
navigationController.view.addGestureRecognizer(panGesture)
animation = Animator()
} …Run Code Online (Sandbox Code Playgroud) 在为我的编程语言实现解释器时,我首先想到了一个简单的控制台窗口,它允许用户输入一些代码,然后作为独立的程序作为shell执行.
但是存在严重的问题:如果用户输入的每一行代码都作为独立程序处理,它必须通过标记器和解析器,然后由解释器执行 - 那么函数呢?
例:
>> def x:
>> print("Blah")
>>
>> x()
Run Code Online (Sandbox Code Playgroud)
函数存储在哪里,以便可以随时调用它?
交互式控制台如何将所有输入的内容视为一个程序,而不是一遍又一遍地执行所有操作?
在python中,我可以运行脚本并在该脚本的上下文中进入交互模式.这让我搞乱全局变量以及不检查程序状态的东西.
$ python -i hello.py
Run Code Online (Sandbox Code Playgroud)
我可以用Coffeescript做到这一点吗?我尝试过以下方法:
$ coffee -i hello.coffee
Run Code Online (Sandbox Code Playgroud)
不加载hello.coffee.它相当于咖啡-i
$ cat hello.coffee | coffee -i
Run Code Online (Sandbox Code Playgroud)
在REPL中逐行运行脚本,但在EOF之后结束REPL.
Python提供了一个交互式解释器,允许通过向控制台提交几行代码来评估小代码片段.我想知道Perl是否也存在具有类似功能的工具(例如,包含箭头键可访问的历史记录)?
似乎有各种各样的解决方案,但我似乎找不到任何好的建议.即提到了很多工具,但我对人们实际使用的工具及其原因感兴趣.那么,除了标准的perl调试(perl -d -e 1)之外,你有什么好的建议吗?
这是我看过的一些有趣的页面:
所以,举个例子,我在ipython会话中,我有一个变量,
var = [3,5,6]
Run Code Online (Sandbox Code Playgroud)
在ipython会话中定义,我想通过运行脚本来做一些事情,例如:
# my_script
plot(var)
Run Code Online (Sandbox Code Playgroud)
所以我要打字
%run my_script.py
Run Code Online (Sandbox Code Playgroud)
从交互式会话到plot var,好像我输入了:
plot(var)
Run Code Online (Sandbox Code Playgroud)
在交互式会话中.
这可能吗?怎么样?
使用 R 中的“plotly”库 - 我生成了一些随机数据并进行了一些交互式数据可视化:
library(plotly)
library(ggplot2)
library(dplyr)
library(hrbrthemes)
#subplot 1
data1 <- data.frame(
day = as.Date("2017-06-14") - 0:364,
value = runif(365) - seq(-140, 224)^2 / 10000
)
p1 <- ggplot(data1, aes(x=day, y=value)) +
geom_line( color="#69b3a2") +
xlab("") +
theme_ipsum() +
theme(axis.text.x=element_text(angle=60, hjust=1))
fig1 <- ggplotly(p1)
scatter_1 = data.frame(x = rnorm(100,100,100), y = rnorm(100,100,100))
fig2 <- plot_ly(data = scatter_1, x = ~x, y = ~y)
#subplot 2
data2 <- data.frame(
day = as.Date("2017-06-14") - 0:364,
value = runif(365) - seq(-140, …Run Code Online (Sandbox Code Playgroud) interactive ×10
python ×4
r ×2
coffeescript ×1
command-line ×1
console ×1
delegates ×1
haskell ×1
html ×1
interpreter ×1
io ×1
ios ×1
ipython ×1
keyboard ×1
perl ×1
plot ×1
plotly ×1
rgl ×1
ruby ×1
shell ×1
startup ×1
swift ×1
title ×1
transition ×1
user-input ×1