Add mode switching.
This commit is contained in:
@@ -8,10 +8,17 @@ type
|
|||||||
success*: bool ## Indicating if the opration was successfull
|
success*: bool ## Indicating if the opration was successfull
|
||||||
errorMsg*: string ## Error meassge in case the operation failed
|
errorMsg*: string ## Error meassge in case the operation failed
|
||||||
|
|
||||||
|
Mode* {.pure.} = enum ## Options for the display mode
|
||||||
|
None = "none" ## No images will be displayed
|
||||||
|
Foxes = "foxes" ## Some nice foxes
|
||||||
|
Inspiro = "inspiro" ## Inspiring nonsense
|
||||||
|
File = "file" ## Images from a local path
|
||||||
|
|
||||||
Command* = enum
|
Command* = enum
|
||||||
cClose = "close" ## Closes the control server and exists the applicaiton
|
cClose = "close" ## Closes the control server and exists the applicaiton
|
||||||
cRefresh = "refresh" ## Force refresh of the image now
|
cRefresh = "refresh" ## Force refresh of the image now
|
||||||
cTimeout = "timeout" ## Set image timeout to a new value
|
cTimeout = "timeout" ## Set image timeout to a new value
|
||||||
|
cMode = "mode" ## Change the servers display mode
|
||||||
|
|
||||||
CommandMessage* = object of RootObj
|
CommandMessage* = object of RootObj
|
||||||
command*: Command ## Command that the application should execute
|
command*: Command ## Command that the application should execute
|
||||||
@@ -28,3 +35,7 @@ proc newCommand*(c: Command, p: string = ""): CommandMessage =
|
|||||||
|
|
||||||
proc wrap*(msg: CommandMessage): string =
|
proc wrap*(msg: CommandMessage): string =
|
||||||
$(%msg) & "\r\L"
|
$(%msg) & "\r\L"
|
||||||
|
|
||||||
|
proc enumToStrings*(en: typedesc): seq[string] =
|
||||||
|
for x in en:
|
||||||
|
result.add $x
|
||||||
@@ -1,29 +1,50 @@
|
|||||||
import net
|
import strutils, net
|
||||||
import argparse
|
import argparse
|
||||||
import commands
|
import common
|
||||||
|
|
||||||
var socket = newSocket()
|
var socket = newSocket()
|
||||||
|
|
||||||
proc sendCommand(server, port: string, msg: CommandMessage) =
|
proc sendCommand*(server, port: string, msg: CommandMessage) =
|
||||||
socket.connect(server, Port(port.parseInt))
|
socket.connect(server, Port(port.parseInt))
|
||||||
if not socket.trySend(msg.wrap):
|
if not socket.trySend(msg.wrap):
|
||||||
echo "Cannot send command: ", msg
|
echo "Cannot send command: ", msg
|
||||||
socket.close()
|
socket.close()
|
||||||
|
|
||||||
var p = newParser("pixctrl"):
|
proc switchMode*(server, port: string, mode: string) =
|
||||||
help("Control utilitiy for randopix")
|
try:
|
||||||
option("-s", "--server", help="Host running the randopix server", default="127.0.0.1")
|
discard parseEnum[Mode](mode)
|
||||||
option("-p", "--port", help="Port to connect to the randopix server", default = $defaultPort)
|
except ValueError:
|
||||||
command("refresh"):
|
echo "Invalid mode: ", mode
|
||||||
help("Force image refresh now")
|
echo "Accepted modes: ", enumToStrings(Mode).join(", ")
|
||||||
run:
|
return
|
||||||
let c = newCommand(cRefresh)
|
let c = newCommand(cMode, mode)
|
||||||
sendCommand(opts.parentOpts.server, opts.parentOpts.port, c)
|
sendCommand(server, port, c)
|
||||||
command("timeout"):
|
|
||||||
help("Set timeout in seconds before a new image is displayed")
|
|
||||||
arg("seconds", default = "300")
|
|
||||||
run:
|
|
||||||
let c = newCommand(cTimeout, opts.seconds)
|
|
||||||
sendCommand(opts.parentOpts.server, opts.parentOpts.port, c)
|
|
||||||
|
|
||||||
p.run(commandLineParams())
|
when isMainModule:
|
||||||
|
var p = newParser("pixctrl"):
|
||||||
|
help("Control utilitiy for randopix")
|
||||||
|
option("-s", "--server", help="Host running the randopix server", default="127.0.0.1")
|
||||||
|
option("-p", "--port", help="Port to connect to the randopix server", default = $defaultPort)
|
||||||
|
|
||||||
|
command($cRefresh):
|
||||||
|
help("Force image refresh now")
|
||||||
|
run:
|
||||||
|
let c = newCommand(cRefresh)
|
||||||
|
sendCommand(opts.parentOpts.server, opts.parentOpts.port, c)
|
||||||
|
|
||||||
|
command($cTimeout):
|
||||||
|
help("Set timeout in seconds before a new image is displayed")
|
||||||
|
arg("seconds", default = "300")
|
||||||
|
run:
|
||||||
|
let c = newCommand(cTimeout, opts.seconds)
|
||||||
|
sendCommand(opts.parentOpts.server, opts.parentOpts.port, c)
|
||||||
|
|
||||||
|
command($cMode):
|
||||||
|
help("Change the display mode of the server")
|
||||||
|
arg("mode")
|
||||||
|
run:
|
||||||
|
switchMode(opts.parentOpts.server, opts.parentOpts.port, opts.mode)
|
||||||
|
try:
|
||||||
|
p.run(commandLineParams())
|
||||||
|
except:
|
||||||
|
echo p.help
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import os, sets, random, httpClient, json, strformat, options
|
import os, sets, random, httpClient, json, strformat, options
|
||||||
import gintro/[gdkpixbuf, gobject]
|
import gintro/[gdkpixbuf, gobject]
|
||||||
import commands
|
import common
|
||||||
|
|
||||||
const
|
const
|
||||||
supportedExts = @[".png", ".jpg", ".jpeg"]
|
supportedExts = @[".png", ".jpg", ".jpeg"]
|
||||||
@@ -12,12 +12,6 @@ type
|
|||||||
FileOpResult* = object of OpResult
|
FileOpResult* = object of OpResult
|
||||||
file*: string
|
file*: string
|
||||||
|
|
||||||
Mode* {.pure.} = enum ## Options for the display mode
|
|
||||||
None = "none" ## No images will be displayed
|
|
||||||
Foxes = "foxes" ## Some nice foxes
|
|
||||||
Inspiro = "inspiro" ## Inspiring nonsense
|
|
||||||
File = "file" ## Images from a local path
|
|
||||||
|
|
||||||
ImageProvider* = ref object of RootObj
|
ImageProvider* = ref object of RootObj
|
||||||
## Manages images that should be displayed
|
## Manages images that should be displayed
|
||||||
verbose: bool ## Additional logging for the image provider
|
verbose: bool ## Additional logging for the image provider
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import os, options, strformat
|
|||||||
import gintro/[glib, gobject, gtk, gio]
|
import gintro/[glib, gobject, gtk, gio]
|
||||||
import gintro/gdk except Window
|
import gintro/gdk except Window
|
||||||
import argparse except run
|
import argparse except run
|
||||||
import providers, server, commands
|
import providers, server, common
|
||||||
|
|
||||||
const
|
const
|
||||||
css = slurp("app.css")
|
css = slurp("app.css")
|
||||||
@@ -24,10 +24,6 @@ var
|
|||||||
# Server vor recieving commands from external tools
|
# Server vor recieving commands from external tools
|
||||||
serverWorker: system.Thread[ServerArgs]
|
serverWorker: system.Thread[ServerArgs]
|
||||||
|
|
||||||
proc enumToStrings(en: typedesc): seq[string] =
|
|
||||||
for x in en:
|
|
||||||
result.add $x
|
|
||||||
|
|
||||||
proc log(things: varargs[string, `$`]) =
|
proc log(things: varargs[string, `$`]) =
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
echo things.join()
|
echo things.join()
|
||||||
@@ -53,6 +49,10 @@ proc newArgs(): Option[Args] =
|
|||||||
try:
|
try:
|
||||||
let opts = p.parse(commandLineParams())
|
let opts = p.parse(commandLineParams())
|
||||||
|
|
||||||
|
# Catch the help option. Do nothing more
|
||||||
|
if opts.help:
|
||||||
|
return
|
||||||
|
|
||||||
# Parse the starting mode
|
# Parse the starting mode
|
||||||
var startMode: Mode
|
var startMode: Mode
|
||||||
try:
|
try:
|
||||||
@@ -127,17 +127,27 @@ proc checkServerChannel(image: Image): bool =
|
|||||||
|
|
||||||
if tried.dataAvailable:
|
if tried.dataAvailable:
|
||||||
let msg: CommandMessage = tried.msg
|
let msg: CommandMessage = tried.msg
|
||||||
log "Main app got message: ", msg.command
|
log "Recieved command: ", msg.command
|
||||||
|
|
||||||
case msg.command
|
case msg.command
|
||||||
of cRefresh:
|
of cRefresh:
|
||||||
forceUpdate(nil, nil, image)
|
forceUpdate(nil, nil, image)
|
||||||
|
|
||||||
of cTimeout:
|
of cTimeout:
|
||||||
let val = msg.parameter.parseInt * 1000
|
let val = msg.parameter.parseInt * 1000
|
||||||
log "Setting timeout to ", val
|
log "Setting timeout to ", val
|
||||||
args.timeout = val
|
args.timeout = val
|
||||||
discard updateTimeout.remove
|
discard updateTimeout.remove
|
||||||
updateTimeout = int(timeoutAdd(uint32(args.timeout), timedUpdate, image))
|
updateTimeout = int(timeoutAdd(uint32(args.timeout), timedUpdate, image))
|
||||||
|
|
||||||
|
of cMode:
|
||||||
|
try:
|
||||||
|
let mode = parseEnum[Mode](msg.parameter)
|
||||||
|
log "Switching mode: ", mode
|
||||||
|
imageProvider.mode = mode
|
||||||
|
except ValueError:
|
||||||
|
log "Invalid mode: ", msg.parameter
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log "Command ignored: ", msg.command
|
log "Command ignored: ", msg.command
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import net, json, strutils
|
import net, json, strutils
|
||||||
import commands
|
import common
|
||||||
|
|
||||||
type
|
type
|
||||||
ServerArgs* = object of RootObj
|
ServerArgs* = object of RootObj
|
||||||
|
|||||||
Reference in New Issue
Block a user