diff --git a/src/providers.nim b/src/providers.nim index d79d3d3..8acc387 100644 --- a/src/providers.nim +++ b/src/providers.nim @@ -5,6 +5,7 @@ import common const supportedExts = @[".png", ".jpg", ".jpeg"] + placeholderImg = slurp("resources/blank.png") foxesUrl = "https://randomfox.ca/floof/" inspiroUrl = "http://inspirobot.me/api?generate=true" @@ -75,6 +76,13 @@ func calcImageSize(maxWidth, maxHeight, imgWidth, imgHeight: int): tuple[width: # Image Provider procs ######################## +proc getPlaceHolder(ip: ImageProvider): FileOpResult = + ## Provide the placeholder image. + ## This is used when no mode is active + let f = fmt"{tmpFile}.blank" + writeFile(f, placeholderImg) + return newFileOpResult(f) + proc getFox(ip: ImageProvider): FileOpResult = ## Download image from the fox API try: @@ -131,14 +139,14 @@ proc getLocalFile(ip: var ImageProvider): FileOpResult = proc getFileName(ip: var ImageProvider): FileOpResult = ## Get the temporary file name of the next file to display case ip.mode + of Mode.None: + return ip.getPlaceHolder() of Mode.File: return ip.getLocalFile() of Mode.Foxes: return ip.getFox() of Mode.Inspiro: return ip.getInspiro() - else: - return newFileOpResultError("Not implemented") ######################## # Exported procs @@ -147,8 +155,6 @@ proc getFileName(ip: var ImageProvider): FileOpResult = proc next*(ip: var ImageProvider, maxWidth, maxHeight: int): FileOpResult = ## Uses the image provider to get a new image ready to display. ## `width` and `height` should be the size of the window. - if ip.mode == Mode.None: - return newFileOpResultError("No mode active") let op = ip.getFileName() if not op.success: return op diff --git a/src/randopix.nim b/src/randopix.nim index d671de3..e875bf0 100644 --- a/src/randopix.nim +++ b/src/randopix.nim @@ -98,7 +98,6 @@ proc updateImage(image: Image): bool = if imageProvider.mode == Mode.None: log "No display mode" label.notify "No mode selected" - return true var wWidth, wHeight: int window.getSize(wWidth, wHeight) @@ -110,7 +109,8 @@ proc updateImage(image: Image): bool = return image.setFromFile(op.file) - label.notify + if imageProvider.mode != Mode.None: + label.notify except: let e = getCurrentException() diff --git a/src/resources/blank.png b/src/resources/blank.png new file mode 100644 index 0000000..400ade8 Binary files /dev/null and b/src/resources/blank.png differ