2
0
mirror of https://github.com/koreader/koreader synced 2024-11-11 19:11:14 +00:00

Merge pull request #1082 from chrox/cover_50

screenshot to PNG files by default
This commit is contained in:
HW 2014-11-05 11:44:55 +01:00
commit f0fba63f67
7 changed files with 85 additions and 19 deletions

2
base

@ -1 +1 @@
Subproject commit 5a83d4aaded90420306380613ccdc4613a53a9ce
Subproject commit f342e7fedabe46dde7a54f30e25d555d4d311879

View File

@ -7,7 +7,9 @@ local InfoMessage = require("ui/widget/infomessage")
local _ = require("gettext")
local DEBUG = require("dbg")
local ReaderScreenshot = InputContainer:new{}
local ReaderScreenshot = InputContainer:new{
datetime_name = "screenshots/Screenshot_%Y-%b-%d_%Hh%M.png",
}
function ReaderScreenshot:init()
local diagonal = math.sqrt(
@ -32,16 +34,13 @@ function ReaderScreenshot:init()
}
end
function ReaderScreenshot:onScreenshot()
if os.execute("screenshot") ~= 0 then
local screenshot_name = os.date("screenshots/Screenshot_%Y-%B-%d_%Hh%M.pam")
UIManager:show(InfoMessage:new{
text = _("Writing screen to ")..screenshot_name,
timeout = 2,
})
Screen.bb:writePAM(screenshot_name)
DEBUG(screenshot_name)
end
function ReaderScreenshot:onScreenshot(filename)
local screenshot_name = filename or os.date(self.datetime_name)
UIManager:show(InfoMessage:new{
text = _("Writing screen to ")..screenshot_name,
timeout = 2,
})
Screen:shot(screenshot_name)
UIManager.full_refresh = true
return true
end

View File

@ -174,10 +174,14 @@ function Screen:restoreFromSavedBB()
end
end
function Screen:shot(filename)
DEBUG("write PNG file", filename)
self.bb:writePNG(filename)
end
function Screen:close()
DEBUG("close screen framebuffer")
self.fb:close()
end
return Screen

View File

@ -1,8 +1,5 @@
local FileManagerHistory = require("apps/filemanager/filemanagerhistory")
local FileManagerMenu = require("apps/filemanager/filemanagermenu")
local InputContainer = require("ui/widget/container/inputcontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local FileManager = require("apps/filemanager/filemanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local ButtonDialog = require("ui/widget/buttondialog")

View File

@ -0,0 +1,18 @@
require("commonrequire")
local FileManager = require("apps/filemanager/filemanager")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local DEBUG = require("dbg")
describe("FileManager module", function()
it("should show file manager", function()
UIManager:quit()
local filemanager = FileManager:new{
dimen = Screen:getSize(),
root_path = "../../test",
}
UIManager:show(filemanager)
UIManager:scheduleIn(1, function() UIManager:close(filemanager) end)
UIManager:run()
end)
end)

View File

@ -0,0 +1,38 @@
require("commonrequire")
local DocumentRegistry = require("document/documentregistry")
local ReaderUI = require("apps/reader/readerui")
local lfs = require("libs/libkoreader-lfs")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local Event = require("ui/event")
local DEBUG = require("dbg")
describe("ReaderScreenshot module", function()
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui
setup(function()
readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
end)
it("should get screenshot in portrait", function()
local name = "screenshots/reader_screenshot_portrait.png"
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(1, function() UIManager:close(readerui) end)
UIManager:run()
readerui.screenshot:onScreenshot(name)
assert.truthy(lfs.attributes(name, "mode"))
end)
it("should get screenshot in landscape", function()
local name = "screenshots/reader_screenshot_landscape.png"
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(2, function() UIManager:close(readerui) end)
UIManager:run()
readerui.screenshot:onScreenshot(name)
assert.truthy(lfs.attributes(name, "mode"))
end)
end)

View File

@ -2,13 +2,17 @@ require("commonrequire")
local DocumentRegistry = require("document/documentregistry")
local ReaderUI = require("apps/reader/readerui")
local DocSettings = require("docsettings")
local UIManager = require("ui/uimanager")
local DEBUG = require("dbg")
describe("Readerui module", function()
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
local readerui
setup(function()
readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
end)
it("should save settings", function()
-- remove history settings and sidecar settings
DocSettings:open(sample_epub):clear()
@ -21,6 +25,12 @@ describe("Readerui module", function()
assert.are.same(doc_settings.data.last_xpointer,
readerui.doc_settings.data.last_xpointer)
end)
it("should show reader", function()
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(1, function() UIManager:close(readerui) end)
UIManager:run()
end)
it("should close document", function()
readerui:closeDocument()
assert(readerui.document == nil)