Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
live.balsa-bootstrap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
osp
live.balsa-bootstrap
Commits
4df8de78
Commit
4df8de78
authored
Feb 28, 2013
by
Pierre Marchand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some tools
parent
297020f0
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9655 additions
and
0 deletions
+9655
-0
tools/base.html
tools/base.html
+90
-0
tools/routes.py
tools/routes.py
+125
-0
tools/static/jquery.js
tools/static/jquery.js
+9440
-0
No files found.
tools/base.html
0 → 100644
View file @
4df8de78
<!DOCTYPE html>
<html>
<head>
<script
src=
"/static/jquery.js"
></script>
<script>
$
(
document
).
ready
(
function
(){
var
ws
=
new
WebSocket
(
"
ws://127.0.0.1:8000/plotter
"
);
var
STATUS_READY
=
false
;
var
STEP_CONTROL_MAX
=
10
;
var
STEP_CONTROL_STEP
=
1
;
var
step_control
=
0
;
ws
.
onopen
=
function
()
{
console
.
log
(
'
Connected to plotter
'
);
};
ws
.
onmessage
=
function
(
evt
)
{
var
data
=
JSON
.
parse
(
evt
.
data
);
if
(
data
.
status
!==
undefined
)
{
if
(
data
.
status
===
'
ready
'
)
{
STATUS_READY
=
true
;
}
}
};
$
(
'
#start
'
).
on
(
'
click
'
,
function
(){
$
(
this
).
hide
();
var
ww
=
$
(
window
).
width
();
var
wh
=
$
(
window
).
height
();
$
(
'
body
'
).
css
({
width
:
ww
+
'
px
'
,
height
:
wh
+
'
px
'
});
var
ctx_width
=
$
(
'
#context
'
).
width
();
var
ctx_height
=
$
(
'
#context
'
).
height
();
var
ctx_data
=
{
scale
:
1
,
w
:
ctx_width
,
h
:
ctx_height
,
};
ws
.
send
(
JSON
.
stringify
(
ctx_data
))
$
(
'
#context
'
).
on
(
'
mousemove
'
,
function
(
event
){
var
data
=
{
x
:
event
.
pageX
,
y
:
event
.
pageY
};
// if(STATUS_READY)
if
(
step_control
>=
STEP_CONTROL_MAX
)
{
console
.
log
(
data
);
// STATUS_READY = false;
step_control
=
0
;
ws
.
send
(
JSON
.
stringify
(
data
));
}
else
{
step_control
+=
STEP_CONTROL_STEP
;
}
});
});
});
</script>
<style>
*
{
margin
:
0
;
border
:
none
;
padding
:
0
}
body
{
background-color
:
#aaf
;
width
:
100%
;
height
:
100%
;
}
#context
{
width
:
100%
;
height
:
100%
;
background-color
:
white
;
}
</style>
</head>
<body>
<div
id=
"context"
>
<h1
id=
"start"
>
START
</h1>
</div>
</body>
</html>
\ No newline at end of file
tools/routes.py
0 → 100644
View file @
4df8de78
# -*- coding: utf-8 -*-
from
bottle
import
request
,
Bottle
,
abort
,
static_file
app
=
Bottle
()
import
chiplotle
from
chiplotle
import
hpgl
import
json
import
sys
import
os
DEBUG
=
True
DEBUG
=
False
ROOT_DIR
=
os
.
getcwd
()
plotter
=
None
import
threading
import
Queue
print
(
'ROOT => %s'
%
(
ROOT_DIR
,))
try
:
if
not
DEBUG
:
devices
=
chiplotle
.
instantiate_plotters
()
plotter
=
devices
[
0
]
bl
=
plotter
.
margins
.
hard
.
bottom_left
tr
=
plotter
.
margins
.
hard
.
top_right
cmd
=
hpgl
.
IP
([(
bl
.
x
,
bl
.
y
),(
tr
.
x
,
tr
.
y
)])
print
cmd
plotter
.
write
(
cmd
)
except
Exception
as
e
:
print
(
'Could not istantiate plotter: %s'
%
e
)
if
not
DEBUG
:
sys
.
exit
()
def
draw_on_plotter
(
x
,
y
):
cmd
=
hpgl
.
PD
([(
x
,
y
)])
print
cmd
if
not
DEBUG
:
try
:
plotter
.
write
(
cmd
)
except
Exception
as
e
:
print
(
'Error plotter.write: %s'
%
(
e
))
queue
=
Queue
.
Queue
()
def
worker
():
while
True
:
coord
=
queue
.
get
()
ok
=
False
try
:
x
=
int
(
coord
[
'x'
])
y
=
int
(
coord
[
'y'
])
ok
=
True
except
Exception
as
e
:
print
(
'Malformed coordinates: %s'
%
(
e
))
if
ok
:
draw_on_plotter
(
x
,
y
)
queue
.
task_done
()
workers
=
[]
for
i
in
range
(
4
):
t
=
threading
.
Thread
(
target
=
worker
)
t
.
daemon
=
True
t
.
start
()
workers
.
append
(
t
)
@
app
.
route
(
'/'
)
def
index
():
idx
=
open
(
'base.html'
)
idx_html
=
idx
.
read
()
idx
.
close
()
return
idx_html
@
app
.
route
(
'/static/<sf>'
)
def
static
(
sf
):
root
=
os
.
path
.
join
(
ROOT_DIR
,
'static'
)
print
(
'Looking for %s in %s'
%
(
sf
,
root
))
return
static_file
(
sf
,
root
=
root
)
@
app
.
route
(
'/plotter'
)
def
handle_websocket
():
wsock
=
request
.
environ
.
get
(
'wsgi.websocket'
)
if
not
wsock
:
abort
(
400
,
'Expected WebSocket request.'
)
wsock
.
send
(
json
.
dumps
({
'status'
:
'ready'
}))
while
True
:
try
:
message
=
wsock
.
receive
()
try
:
coord
=
json
.
loads
(
message
)
if
'scale'
in
coord
:
if
not
DEBUG
:
cmd
=
hpgl
.
SC
([(
0
,
int
(
coord
[
'w'
])),(
0
,
int
(
coord
[
'h'
]))])
print
cmd
plotter
.
write
(
cmd
)
else
:
print
hpgl
.
SC
([(
0
,
float
(
coord
[
'w'
])),(
0
,
float
(
coord
[
'h'
]))])
else
:
#draw_on_plotter(coord['x'], coord['y'])
queue
.
put
(
coord
)
wsock
.
send
(
json
.
dumps
({
'status'
:
'ready'
}))
except
Exception
as
e
:
wsock
.
send
(
json
.
dumps
({
'msg'
:
"%s"
%
e
,
'status'
:
'error'
}))
except
WebSocketError
:
break
from
gevent.pywsgi
import
WSGIServer
from
geventwebsocket
import
WebSocketHandler
,
WebSocketError
server
=
WSGIServer
((
"127.0.0.1"
,
8000
),
app
,
handler_class
=
WebSocketHandler
)
server
.
serve_forever
()
tools/static/jquery.js
0 → 100644
View file @
4df8de78
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment