如何在Electron应用程序中将数据或消息记录到控制台?
这个真正基本的hello世界默认打开开发工具,我无法使用console.log('hi').Electron有替代品吗?
main.js
var app = require('app');
var BrowserWindow = require('browser-window');
require('crash-reporter').start();
var mainWindow = null;
app.on('window-all-closed', function() {
// Mac OS X - close is done explicitly with Cmd + Q, not just closing windows
if (process.platform != 'darwin') {
app.quit();
}
});
app.on('ready', function(){
mainWindow = new BrowserWindow({ width: 800, height: 600});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
mainWindow.openDevTools();
mainWindow.on('closed', function(){
mainWindow = null;
});
});
Run Code Online (Sandbox Code Playgroud) 我有一个简单的类,只有一个方法exec(arg1,..,argn),我希望有一些别名方法调用exec预定义的参数值(例如exec_sync = exec.bind(this, true)).
以下是诀窍:
class Executor {
constructor() {
this.exec_sync = this.exec.bind(this, true);
}
exec(sync, cmd, args/* ... */) {
// impl
}
}
Run Code Online (Sandbox Code Playgroud)
但是我不知道这是不是一个好主意,或者这对ES6来说是否是惯用的.
UDATE:
在一个现实生活中的例子中,我有两个嵌套循环,分别有3个和4个循环,用于动态地向类中添加12个别名方法.当您真正可以利用JS作为基于原型的编程语言时,显式定义别名方法将是一项繁琐的任务.
更新2 - 示例:
假设我们有有一个方法,一个简单的HTTP客户端request(method, body),我们希望提供别名方法GET,PUT等等.它看起来像下面这样:
class HTTP {
constructor() {
['GET', 'PUT', 'POST', 'DEL'].forEach((method) => {
this[method] = this.request.bind(this, method);
}, this);
}
request(method, body) {
// execute the HTTP request
}
}
Run Code Online (Sandbox Code Playgroud) 我知道组件的动态子项必须具有以下唯一key(来自官方文档的修改示例):
render: function() {
var results = this.props.results;
return (
{results.map(function(result) {
return <ChildComponent type="text" key={result.id} changeCallback={this.props.callbackFn}/>;
})}
);
}
Run Code Online (Sandbox Code Playgroud)
考虑到这ChildComponent是另一个嵌套在这里的React组件,render方法如下所示
render: function() {
var results = this.props.results;
return (
<div className="something">
<input type="text" onChange={this.props.changeCallback} />
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
在callbackFn(event)调用时有没有办法访问密钥?
我无法将菜单项连接到事件处理程序.这是一个UI模拟显示状态随时间的变化.这是一个下拉菜单(通过Bootstrap),根菜单项显示当前选择:
[ANN]<click ... [ANN] ... [BOB]<click ... [BOB]
[Ann] [Ann]
[Bob]<click + ajax [Bob]
[Cal] [Cal]
Run Code Online (Sandbox Code Playgroud)
最终目标是根据用户的选择异步更改页面内容.点击Bob应该触发handleClick,但事实并非如此.
作为旁注,我对componentDidMount调用的方式并不十分满意this.handleClick();,但它现在可以作为从服务器获取初始菜单内容的一种方式.
/** @jsx React.DOM */
var CurrentSelection = React.createClass({
componentDidMount: function() {
this.handleClick();
},
handleClick: function(event) {
alert('clicked');
// Ajax details ommitted since we never get here via onClick
},
getInitialState: function() {
return {title: "Loading items...", items: []};
},
render: function() {
var itemNodes = this.state.items.map(function (item) {
return <li key={item}><a href='#' onClick={this.handleClick}>{item}</a></li>;
});
return <ul className='nav'>
<li …Run Code Online (Sandbox Code Playgroud) 我试图通过OpenCV.org这个教程:
MOG指针初始化为
Ptr<BackgroundSubtractor> pMOG; //MOG Background subtractor
Run Code Online (Sandbox Code Playgroud)
在主要情况下,它以下列方式使用:
pMOG = createBackgroundSubtractorMOG();
Run Code Online (Sandbox Code Playgroud)
但是,这会产生以下错误:
Error: Identifier "createBackgroundSubtractorMOG" is undefined
Run Code Online (Sandbox Code Playgroud)
此外,要更新背景模型时,使用以下命令:
pMOG->apply(frame, fgMaskMOG);
Run Code Online (Sandbox Code Playgroud)
这又会产生以下错误:
Error: class "cv::BackgroundSubtractor" has no member "apply"
Run Code Online (Sandbox Code Playgroud)
知道可以做些什么吗?提前谢谢了!
这是整个教程代码:
//opencv
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
//C
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>
using namespace cv;
using namespace std;
//global variables
Mat frame; //current frame
Mat fgMaskMOG; //fg mask generated by MOG method
Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method
Ptr<BackgroundSubtractor> pMOG; //MOG Background subtractor
Ptr<BackgroundSubtractor> …Run Code Online (Sandbox Code Playgroud) 实际上我找到了导致问题的原因.我的问题是为什么要加入transform你的html, body休息时间position: fixed?
原来的问题
对我来说,最简单的CSS任务似乎失败了:position: fixed不保持元素相对于视点的位置.考虑以下样式表:
.stay-there-dammit {
position: fixed;
right: 0px;
left: 0px;
z-index: 1030;
}
Run Code Online (Sandbox Code Playgroud)
页面首次加载时,定位正确.但是对视口的任何更改(例如滚动或调整大小)都不会影响.stay-there-dammit元素的定位.所以说它不会使其位置适应新的视口.
奇怪的是这个网站显示了position: fixed应该如何工作,实际上在我的浏览器中工作没有任何问题!
所以问题是:是否有任何可能破坏固定定位的东西?
顺便说一句.我使用Bootstrap 3.
更新:
似乎是由某些第三方应用程序设置的转换html,body打破了position: fixed.这是我必须删除的内容:
html, body {
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3, mirror=1);
-webkit-transform: scale(1, 1);
-moz-transform: scale(1, 1);
-ms-transform: scale(1, 1);
-o-transform: scale(1, 1);
transform: scale(1, 1);
}
Run Code Online (Sandbox Code Playgroud)
似乎以下问题解决了同样的问题:
使用-webkit-transform时,固定的位置不起作用
但为什么?
我有一个通过httplib使用连接到URL的功能lxml.它检查xpath某个模式,如果检查结果是肯定的,则返回一个字符串.但如果检查结果为否定,则不返回任何内容.
现在的情况是,我的函数返回None.我调用该函数,检查它的返回值是否为not None并继续在代码中.
一个例子:
def foobar(arg):
# connect to page by httplib
# check for arg in a certain pattern by lxml
if check:
return result
else:
return None
result = foobar(arg)
if result:
# do stuff
else:
# do other stuff
Run Code Online (Sandbox Code Playgroud)
最近我读到,这是不行的.我该如何避免这种情况?
亲爱的社区你好:)
我想让DBus在我的Raspberry Pi上工作.当我在Pi桌面环境中时,libdbus-c ++ - 1的示例代码工作正常 - >(startx)
我在互联网上的研究和我在stackoverflow上找到的例子对我没有帮助:[.
但是,当我在Shell模式时,我收到错误消息
./client
terminate called after throwing an instance of 'DBus::Error'
what(): /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
Aborted
Run Code Online (Sandbox Code Playgroud)
我也试过了
eval 'dbus-launch --auto-syntax' ./client
eval 'dbus-launch --auto-syntax' ./server
Run Code Online (Sandbox Code Playgroud)
但它不起作用,服务器应用程序正在启动一个消息守护程序,但无法从客户端访问它.守护进程也保持活动状态.
我有:
terminate called after throwing an instance of 'DBus::Error'
what(): The name org.freedesktop.DBus.Examples.Echo was not provided by any .service files
call1: Aborted
Run Code Online (Sandbox Code Playgroud)
它也没有显示在服务列表中.
在此之后我尝试了另一个命令
DISPLAY=":0" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/dbus/system_bus_socket" ./server
Run Code Online (Sandbox Code Playgroud)
我得到了:
terminate called after throwing an instance of 'DBus::Error'
what(): …Run Code Online (Sandbox Code Playgroud) Rails 有一个名为的类扩展class_attribute,它允许继承类实例变量。这适用于不可变对象,例如String,但不适用于可变对象:
class Base
class_attribute :options
self.options = {}
end
class SubClass < Base
end
Base.options # {}
SubClass.options[:foo] = "bar" # { foo: "bar" }
Base.options # { foo: "bar" }
Run Code Online (Sandbox Code Playgroud)
问题是如何让子类拥有自己的副本,options而不在其主体中显式初始化它:
class SubClass < Base
self.options = {}
end
Run Code Online (Sandbox Code Playgroud) 我有一张tikz图片:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes, shadows, arrows}
\begin{document}
\thispagestyle{empty}
\tikzstyle{abstract}=[circle, draw=black, fill=white]
\tikzstyle{labelnode}=[circle, draw=white, fill=white]
\tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}[
every node/.style={line width=2mm, circle split, draw, minimum size=5cm}
]
\node (output) [thick, font=\fontsize{60}{60}\selectfont, thick] {$y_{(out)}$ \nodepart{lower} $y_{(in)}$};
\node (hidden) [thick, font=\fontsize{60}{60}\selectfont, below=1cm of output] {$h_{(out)}$ \nodepart{lower} $h_{(in)}$};
\node (input) [thick, font=\fontsize{60}{60}\selectfont, below=1cm of output, abstract, below=of hidden] {$x$};
\draw[line width=1mm, ->] (input) -- (hidden) node[font=\fontsize{60}{60}\selectfont, below=of output, labelnode, midway, right=2cm] {$W_1\, {\rm{, }} \,b_1$};
\draw[line width=1mm, ->] (hidden) -- (output) …Run Code Online (Sandbox Code Playgroud)