5 ändrade filer med 339 tillägg och 232 borttagningar
@ -1 +1 @@
|
||||
{"WindowX": 3, "WindowY": 47, "WindowWidth": 641, "WindowHeight": 449} |
||||
{"WindowX": 1, "WindowY": 460, "WindowWidth": 641, "WindowHeight": 449} |
@ -0,0 +1,221 @@
|
||||
import subprocess |
||||
import sys |
||||
import config |
||||
## TODO find a better way to get killAll-fn |
||||
import piplayer |
||||
import re |
||||
from fltk import * |
||||
|
||||
playState = True; |
||||
durationState = 0; |
||||
positionState = 0; |
||||
|
||||
dbusaddr = "org.mpris.MediaPlayer2.omxplayer" |
||||
|
||||
def setDBusAddr ( addr ) : |
||||
global dbusaddr |
||||
dbusaddr = addr |
||||
|
||||
def callDBus ( param ): |
||||
try: |
||||
param.insert ( 0, config.dbusconfig ); |
||||
param.insert ( 0, "bash" ); |
||||
out = subprocess.check_output ( param ) |
||||
return out; |
||||
except subprocess.CalledProcessError: |
||||
return b""; |
||||
|
||||
def playCb(ptr): |
||||
callDBus ( ["pause"] ); |
||||
getState( None ); |
||||
global playState |
||||
global playBtn |
||||
if ( playState == True ): |
||||
playBtn.label ("@||"); |
||||
else : |
||||
playBtn.label("@>"); |
||||
|
||||
def sizeCalc ( ): |
||||
global window |
||||
x = window.x(); |
||||
y = window.y(); |
||||
w = window.w(); |
||||
h = window.h(); |
||||
|
||||
#x=x+2; |
||||
#y=y+2; |
||||
x2 = x + w; |
||||
y2 = y + h - 75; |
||||
|
||||
return (x,y,x2,y2); |
||||
|
||||
|
||||
def DecodeState ( param ): |
||||
global playState; |
||||
global durationState; |
||||
global positionState; |
||||
i=0 |
||||
while (i < len(param)) : |
||||
m = re.search ( "Duration: ([0-9]+)", param[i] ); |
||||
if ( m is None ): |
||||
m = re.search ( "Position: ([0-9]+)", param[i] ); |
||||
if ( m is None ): |
||||
m = re.search ( "Paused: (true|false)", param[i] ); |
||||
if ( m is None ) : |
||||
pass; |
||||
else : |
||||
playState = ( m.group(1) == "false"); |
||||
else: |
||||
positionState = int ( m.group(1) ); |
||||
else: |
||||
durationState = int ( m.group(1) ); |
||||
i=i+1 |
||||
|
||||
def timeOut ( time ) : |
||||
time = int(time / 1000000); # mikrosec -> sec |
||||
hours = int(time / 3600); |
||||
minutes = int((time / 60)) - hours*60; |
||||
sec = time - minutes*60 - hours*360; |
||||
|
||||
return ( str(hours).zfill(2) + ":" + str(minutes).zfill(2) + ":" +str(sec).zfill(2) ); |
||||
|
||||
def setPosition ( pos ): |
||||
callDBus ( ["setposition", str(pos)] ); |
||||
getState ( None ); |
||||
|
||||
def getState ( ptr ) : |
||||
status = callDBus ( ["status"] ); |
||||
status = status.decode("utf-8").split("\n") |
||||
DecodeState ( status ); |
||||
|
||||
statusLabel.value ( timeOut ( positionState ) + " / " + timeOut ( durationState ) ); |
||||
if ( durationState == 0): |
||||
statusProgress.value(0); |
||||
else : |
||||
statusProgress.value( positionState / durationState ); |
||||
|
||||
def resizeWindow ( ): |
||||
global window; |
||||
global playBtn |
||||
global stateBtn |
||||
global killBtn |
||||
global statusLabel |
||||
global statusProgress |
||||
global volUp |
||||
global volDown |
||||
|
||||
h = window.h() |
||||
w = window.w() |
||||
|
||||
statusLabel.resize ( w-230, h-50, statusLabel.w(), statusLabel.h() ); |
||||
playBtn.position ( 20, h-60 ); |
||||
stateBtn.position ( 60, h-60); |
||||
killBtn.position ( 100, h-60 ); |
||||
|
||||
volUp.position ( w - 40, h-50 ); |
||||
volDown.position ( w - 60, h-50 ); |
||||
statusProgress.position ( 160, h-50 ); |
||||
statusProgress.size ( w - 410, 20 ); |
||||
|
||||
playBtn.redraw(); |
||||
stateBtn.redraw(); |
||||
killBtn.redraw(); |
||||
#statusLabel.redraw(); |
||||
statusProgress.redraw(); |
||||
window.redraw(); |
||||
|
||||
resizeOMX (); |
||||
|
||||
def resizeOMX (): |
||||
(x,y,x2,y2) = sizeCalc() |
||||
|
||||
status = callDBus ( ["status"] ); |
||||
times = 0; |
||||
while (status=="" and times < 5) : |
||||
status = callDBus ( ["status"] ); |
||||
time.sleep ( 0.5 ); |
||||
times = times + 1; |
||||
|
||||
if ( times < 5 ): |
||||
callDBus (["setvideopos", str(x), str(y), str(x2), str(y2)]); |
||||
|
||||
def seekCb (): |
||||
global statusProgress; |
||||
x = Fl.event_x(); |
||||
x = x - statusProgress.x(); |
||||
dim = x / statusProgress.w(); |
||||
positionState = durationState * dim; |
||||
setPosition ( positionState ); |
||||
|
||||
def volUpCb ( ptr ): |
||||
callDBus ( ["volumeup"] ); |
||||
|
||||
def volDownCb ( ptr ): |
||||
callDBus ( ["volumedown"] ); |
||||
|
||||
|
||||
window="" |
||||
playBtn="" |
||||
stateBtn="" |
||||
killBtn="" |
||||
statusLabel="" |
||||
statusProgress="" |
||||
volUp="" |
||||
volDown="" |
||||
def init ( cfg ): |
||||
global window |
||||
global playBtn |
||||
global stateBtn |
||||
global killBtn |
||||
global statusLabel |
||||
global statusProgress |
||||
global volUp |
||||
global volDown |
||||
global stateBtn |
||||
window = Fl_Window( cfg.get("WindowX", 100) , cfg.get("WindowY", 100), cfg.get("WindowWidth", 640), cfg.get("WindowHeight", 480)) |
||||
window.label(sys.argv[0]) |
||||
window.size_range ( 320, 240, 0, 0); |
||||
|
||||
playBtn = Fl_Button(20, 420, 40, 40) |
||||
playBtn.labeltype(FL_SYMBOL_LABEL) |
||||
playBtn.label("@||") |
||||
playBtn.callback(playCb) |
||||
playBtn.box ( FL_THIN_UP_BOX ); |
||||
|
||||
stateBtn = Fl_Button ( 60, 420, 40, 40 ); |
||||
stateBtn.label("?") |
||||
stateBtn.callback(getState) |
||||
stateBtn.box ( FL_THIN_UP_BOX ); |
||||
|
||||
killBtn = Fl_Button ( 100, 420, 40, 40 ); |
||||
killBtn.label ("x"); |
||||
## TODO |
||||
killBtn.callback ( piplayer.killAll ); |
||||
killBtn.box ( FL_THIN_UP_BOX ); |
||||
|
||||
statusLabel = Fl_Output ( 410, 430, 150, 20 ); |
||||
statusLabel.label (""); |
||||
statusLabel.box ( FL_FLAT_BOX ); |
||||
|
||||
statusProgress = Fl_Progress ( 160, 430, 230, 20 ); |
||||
statusProgress.box( FL_FLAT_BOX ); |
||||
statusProgress.minimum(0); |
||||
statusProgress.maximum(1); |
||||
statusProgress.color ( 0xffffffff ); |
||||
statusProgress.selection_color( 0x272828ff ); |
||||
|
||||
volUp = Fl_Button ( 600, 430, 20,20 ); |
||||
volUp.label ( "+" ); |
||||
volUp.box ( FL_THIN_UP_BOX ); |
||||
volUp.callback ( volUpCb ); |
||||
|
||||
volDown = Fl_Button ( 580, 430, 20,20 ); |
||||
volDown.label ( "-" ); |
||||
volDown.box ( FL_THIN_UP_BOX ); |
||||
volDown.callback ( volDownCb ); |
||||
|
||||
resizeWindow(); |
||||
|
||||
window.end() |
||||
window.show(1, [sys.argv[0]]) |
||||
|
Reference in new issue