From 86ee8adbce3a73660c4c441b796b7628af901106 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Mon, 1 Apr 2024 18:26:41 -0400 Subject: [PATCH 01/12] tools/script_manager - changed category/categories to folder/folders to accurately refrect reality and to open the possibility of actually categorizing scripts. --- tools/script_manager.lua | 170 +++++++++++++++++++-------------------- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index 7376ed43..f8e6c73b 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -22,9 +22,9 @@ manage the lua scripts. On startup script_manager scans the lua scripts directory to see what scripts are present. - Scripts are sorted by 'category' based on what sub-directory they are in. With no - additional script repositories iinstalled, the categories are contrib, examples, official - and tools. When a category is selected the buttons show the script name and whether the + Scripts are sorted by 'folder' based on what sub-directory they are in. With no + additional script repositories iinstalled, the folders are contrib, examples, official + and tools. When a folder is selected the buttons show the script name and whether the script is started or stopped. The button is a toggle, so if the script is stopped click the button to start it and vice versa. @@ -128,7 +128,7 @@ sm.event_registered = false -- set up tables to contain all the widgets and choices sm.widgets = {} -sm.categories = {} +sm.folders = {} -- set log level for functions @@ -137,14 +137,14 @@ sm.log_level = DEFAULT_LOG_LEVEL --[[ sm.scripts is a table of tables for containing the scripts - It is organized as into category (folder) subtables containing + It is organized as into folder (folder) subtables containing each script definition, which is a table sm.scripts- | - - category------------| + - folder------------| | - script - - category----| | + - folder----| | - script| | - script - script| @@ -152,7 +152,7 @@ sm.log_level = DEFAULT_LOG_LEVEL and a script table looks like name the name of the script file without the lua extension - path category (folder), path separator, path, name without the lua extension + path folder (folder), path separator, path, name without the lua extension doc the header comments from the script to be used as a tooltip script_name the folder, path separator, and name without the lua extension running true if running, false if not, hidden if running but the @@ -178,7 +178,7 @@ sm.page_status = {} sm.page_status.num_buttons = DEFAULT_BUTTONS_PER_PAGE sm.page_status.buttons_created = 0 sm.page_status.current_page = 0 -sm.page_status.category = "" +sm.page_status.folder = "" -- use color in the interface? sm.use_color = false @@ -348,12 +348,12 @@ end -- script handling ------------------ -local function add_script_category(category) +local function add_script_folder(folder) local old_log_level = set_log_level(sm.log_level) - if #sm.categories == 0 or not string.match(du.join(sm.categories, " "), ds.sanitize_lua(category)) then - table.insert(sm.categories, category) - sm.scripts[category] = {} - log.msg(log.debug, "created category " .. category) + if #sm.folders == 0 or not string.match(du.join(sm.folders, " "), ds.sanitize_lua(folder)) then + table.insert(sm.folders, folder) + sm.scripts[folder] = {} + log.msg(log.debug, "created folder " .. folder) end restore_log_level(old_log_level) end @@ -452,19 +452,19 @@ local function deactivate(script) restore_log_level(old_log_level) end -local function add_script_name(name, path, category) +local function add_script_name(name, path, folder) local old_log_level = set_log_level(sm.log_level) - log.msg(log.debug, "category is " .. category) + log.msg(log.debug, "folder is " .. folder) log.msg(log.debug, "name is " .. name) local script = { name = name, - path = category .. "/" .. path .. name, + path = folder .. "/" .. path .. name, running = false, - doc = get_script_doc(category .. "/" .. path .. name), - script_name = category .. "/" .. name, + doc = get_script_doc(folder .. "/" .. path .. name), + script_name = folder .. "/" .. name, data = nil } - table.insert(sm.scripts[category], script) + table.insert(sm.scripts[folder], script) if pref_read(script.script_name, "bool") then activate(script) else @@ -476,10 +476,10 @@ end local function process_script_data(script_file) local old_log_level = set_log_level(sm.log_level) - -- the script file supplied is category/filename.filetype - -- the following pattern splits the string into category, path, name, fileename, and filetype + -- the script file supplied is folder/filename.filetype + -- the following pattern splits the string into folder, path, name, fileename, and filetype -- for example contrib/gimp.lua becomes - -- category - contrib + -- folder - contrib -- path - -- name - gimp.lua -- filename - gimp @@ -496,14 +496,14 @@ local function process_script_data(script_file) log.msg(log.info, "processing " .. script_file) -- add the script data - local category,path,name,filename,filetype = string.match(script_file, pattern) + local folder,path,name,filename,filetype = string.match(script_file, pattern) - if category and name and path then - log.msg(log.debug, "category is " .. category) + if folder and name and path then + log.msg(log.debug, "folder is " .. folder) log.msg(log.debug, "name is " .. name) - add_script_category(category) - add_script_name(name, path, category) + add_script_folder(folder) + add_script_name(name, path, folder) end restore_log_level(old_log_level) @@ -594,25 +594,25 @@ local function scan_repositories() local output = io.popen(find_cmd) for line in output:lines() do local l = string.gsub(line, ds.sanitize_lua(LUA_DIR) .. PS, "") -- strip the lua dir off - local category = string.match(l, "(.-)" .. PS) -- get everything to teh first / - if category then -- if we have a category (.git doesn't) - log.msg(log.debug, "found category " .. category) - if not string.match(category, "plugins") and not string.match(category, "%.git") then -- skip plugins + local folder = string.match(l, "(.-)" .. PS) -- get everything to teh first / + if folder then -- if we have a folder (.git doesn't) + log.msg(log.debug, "found folder " .. folder) + if not string.match(folder, "plugins") and not string.match(folder, "%.git") then -- skip plugins if #sm.installed_repositories == 1 then - log.msg(log.debug, "only 1 repo, adding " .. category) - table.insert(sm.installed_repositories, {name = category, directory = LUA_DIR .. PS .. category}) + log.msg(log.debug, "only 1 repo, adding " .. folder) + table.insert(sm.installed_repositories, {name = folder, directory = LUA_DIR .. PS .. folder}) else log.msg(log.debug, "more than 1 repo, we have to search the repos to make sure it's not there") local found = nil for _, repo in ipairs(sm.installed_repositories) do - if string.match(repo.name, ds.sanitize_lua(category)) then + if string.match(repo.name, ds.sanitize_lua(folder)) then log.msg(log.debug, "matched " .. repo.name) found = true break end end if not found then - table.insert(sm.installed_repositories, {name = category, directory = LUA_DIR .. PS .. category}) + table.insert(sm.installed_repositories, {name = folder, directory = LUA_DIR .. PS .. folder}) end end end @@ -625,11 +625,11 @@ end local function install_scripts() local old_log_level = set_log_level(sm.log_level) local url = sm.widgets.script_url.text - local category = sm.widgets.new_category.text + local folder = sm.widgets.new_folder.text - if string.match(du.join(sm.categories, " "), ds.sanitize_lua(category)) then - log.msg(log.screen, _("category ") .. category .. _(" is already in use. Please specify a different category name.")) - log.msg(log.error, "category " .. category .. " already exists, returning...") + if string.match(du.join(sm.folders, " "), ds.sanitize_lua(folder)) then + log.msg(log.screen, _("folder ") .. folder .. _(" is already in use. Please specify a different folder name.")) + log.msg(log.error, "folder " .. folder .. " already exists, returning...") restore_log_level(old_log_level) return end @@ -644,7 +644,7 @@ local function install_scripts() return end - local git_command = "cd " .. LUA_DIR .. " " .. CS .. " " .. git .. " clone " .. url .. " " .. category + local git_command = "cd " .. LUA_DIR .. " " .. CS .. " " .. git .. " clone " .. url .. " " .. folder log.msg(log.debug, "update git command is " .. git_command) if dt.configuration.running_os == "windows" then @@ -656,27 +656,27 @@ local function install_scripts() log.msg(log.info, "result from import is " .. result) if result == 0 then - local count = scan_scripts(LUA_DIR .. PS .. category) + local count = scan_scripts(LUA_DIR .. PS .. folder) if count > 0 then - update_combobox_choices(sm.widgets.category_selector, sm.categories, sm.widgets.category_selector.selected) - dt.print(_("scripts successfully installed into category ") .. category) - table.insert(sm.installed_repositories, {name = category, directory = LUA_DIR .. PS .. category}) + update_combobox_choices(sm.widgets.folder_selector, sm.folders, sm.widgets.folder_selector.selected) + dt.print(_("scripts successfully installed into folder ") .. folder) + table.insert(sm.installed_repositories, {name = folder, directory = LUA_DIR .. PS .. folder}) update_script_update_choices() - for i = 1, #sm.widgets.category_selector do - if string.match(sm.widgets.category_selector[i], ds.sanitize_lua(category)) then - log.msg(log.debug, "setting category selector to " .. i) - sm.widgets.category_selector.selected = i + for i = 1, #sm.widgets.folder_selector do + if string.match(sm.widgets.folder_selector[i], ds.sanitize_lua(folder)) then + log.msg(log.debug, "setting folder selector to " .. i) + sm.widgets.folder_selector.selected = i break end i = i + 1 end log.msg(log.debug, "clearing text fields") sm.widgets.script_url.text = "" - sm.widgets.new_category.text = "" + sm.widgets.new_folder.text = "" sm.widgets.main_menu.selected = 3 else dt.print(_("No scripts found to install")) - log.msg(log.error, "scan_scripts returned " .. count .. " scripts found. Not adding to category_selector") + log.msg(log.error, "scan_scripts returned " .. count .. " scripts found. Not adding to folder_selector") end else dt.print(_("failed to download scripts")) @@ -696,10 +696,10 @@ local function clear_button(number) restore_log_level(old_log_level) end -local function find_script(category, name) +local function find_script(folder, name) local old_log_level = set_log_level(sm.log_level) - log.msg(log.debug, "looking for script " .. name .. " in category " .. category) - for _, script in ipairs(sm.scripts[category]) do + log.msg(log.debug, "looking for script " .. name .. " in folder " .. folder) + for _, script in ipairs(sm.scripts[folder]) do if string.match(script.name, "^" .. ds.sanitize_lua(name) .. "$") then return script end @@ -708,12 +708,12 @@ local function find_script(category, name) return nil end -local function populate_buttons(category, first, last) +local function populate_buttons(folder, first, last) local old_log_level = set_log_level(sm.log_level) - log.msg(log.debug, "category is " .. category .. " and first is " .. first .. " and last is " .. last) + log.msg(log.debug, "folder is " .. folder .. " and first is " .. first .. " and last is " .. last) local button_num = 1 for i = first, last do - script = sm.scripts[category][i] + script = sm.scripts[folder][i] button = sm.widgets.buttons[button_num] if script.running == true then if sm.use_color then @@ -741,7 +741,7 @@ local function populate_buttons(category, first, last) else script_name, state = string.match(this.label, "(.-) (.+)") end - local script = find_script(sm.widgets.category_selector.value, script_name) + local script = find_script(sm.widgets.folder_selector.value, script_name) if script then log.msg(log.debug, "found script " .. script.name .. " with path " .. script.path) if script.running == true then @@ -779,9 +779,9 @@ end local function paginate(direction) local old_log_level = set_log_level(sm.log_level) - local category = sm.page_status.category - log.msg(log.debug, "category is " .. category) - local num_scripts = #sm.scripts[category] + local folder = sm.page_status.folder + log.msg(log.debug, "folder is " .. folder) + local num_scripts = #sm.scripts[folder] log.msg(log.debug, "num_scripts is " .. num_scripts) local max_pages = math.ceil(num_scripts / sm.page_status.num_buttons) local cur_page = sm.page_status.current_page @@ -829,18 +829,18 @@ local function paginate(direction) end sm.widgets.page_status.label = _("Page ") .. cur_page .. _(" of ") .. max_pages - populate_buttons(category, first, last) + populate_buttons(folder, first, last) restore_log_level(old_log_level) end -local function change_category(category) +local function change_folder(folder) local old_log_level = set_log_level(sm.log_level) - if not category then - log.msg(log.debug "setting category to selector value " .. sm.widgets.category_selector.value) - sm.page_status.category = sm.widgets.category_selector.value + if not folder then + log.msg(log.debug "setting folder to selector value " .. sm.widgets.folder_selector.value) + sm.page_status.folder = sm.widgets.folder_selector.value else - log.msg(log.debug, "setting catgory to argument " .. category) - sm.page_status.category = category + log.msg(log.debug, "setting catgory to argument " .. folder) + sm.page_status.folder = folder end paginate(2) @@ -898,14 +898,14 @@ local function load_preferences() end update_script_update_choices() log.msg(log.debug, "updated installed scripts") - -- category selector - local val = pref_read("category_selector", "integer") + -- folder selector + local val = pref_read("folder_selector", "integer") if val == 0 then val = 1 end - sm.widgets.category_selector.selected = val - sm.page_status.category = sm.widgets.category_selector.value - log.msg(log.debug, "updated category selector and set it to " .. sm.widgets.category_selector.value) + sm.widgets.folder_selector.selected = val + sm.page_status.folder = sm.widgets.folder_selector.value + log.msg(log.debug, "updated folder selector and set it to " .. sm.widgets.folder_selector.value) -- num_buttons local val = pref_read("num_buttons", "integer") if val == 0 then @@ -1069,18 +1069,18 @@ sm.widgets.script_url = dt.new_widget("entry"){ tooltip = _("enter the URL of the git repository containing the scripts you wish to add") } -sm.widgets.new_category = dt.new_widget("entry"){ +sm.widgets.new_folder = dt.new_widget("entry"){ text = "", - placeholder = _("name of new category"), - tooltip = _("enter a category name for the additional scripts") + placeholder = _("name of new folder"), + tooltip = _("enter a folder name for the additional scripts") } sm.widgets.add_scripts = dt.new_widget("box"){ orientation = vertical, dt.new_widget("label"){label = _("URL to download additional scripts from")}, sm.widgets.script_url, - dt.new_widget("label"){label = _("new category to place scripts in")}, - sm.widgets.new_category, + dt.new_widget("label"){label = _("new folder to place scripts in")}, + sm.widgets.new_folder, dt.new_widget("button"){ label = _("install additional scripts"), clicked_callback = function(this) @@ -1124,17 +1124,17 @@ sm.widgets.install_update = dt.new_widget("box"){ -- manage the scripts -sm.widgets.category_selector = dt.new_widget("combobox"){ - label = _("category"), - tooltip = _( "select the script category"), +sm.widgets.folder_selector = dt.new_widget("combobox"){ + label = _("folder"), + tooltip = _( "select the script folder"), selected = 1, changed_callback = function(self) if sm.run then - pref_write("category_selector", "integer", self.selected) - change_category(self.value) + pref_write("folder_selector", "integer", self.selected) + change_folder(self.value) end end, - table.unpack(sm.categories), + table.unpack(sm.folders), } sm.widgets.buttons ={} @@ -1175,7 +1175,7 @@ sm.widgets.page_control = dt.new_widget("box"){ sm.widgets.scripts = dt.new_widget("box"){ orientation = vertical, dt.new_widget("label"){label = _("Scripts")}, - sm.widgets.category_selector, + sm.widgets.folder_selector, sm.widgets.page_control, table.unpack(sm.widgets.buttons) } From a11726889d42bcb7fc9f3dcc0705855fd601b22b Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Tue, 2 Apr 2024 19:09:31 -0400 Subject: [PATCH 02/12] tools/script_manager - add support for "local" libraries by adding entries in the package.path search path if required --- contrib/micharambou | 1 + data/icons/power.png | Bin 0 -> 426 bytes data/icons/poweroff.png | Bin 0 -> 599 bytes development | 1 + tools/script_manager.lua | 21 +++++++++++++++++++++ 5 files changed, 23 insertions(+) create mode 120000 contrib/micharambou create mode 100644 data/icons/power.png create mode 100644 data/icons/poweroff.png create mode 120000 development diff --git a/contrib/micharambou b/contrib/micharambou new file mode 120000 index 00000000..bbe4f2d2 --- /dev/null +++ b/contrib/micharambou @@ -0,0 +1 @@ +/home/bill/src/dtluadev/gitannex/micharambou/ \ No newline at end of file diff --git a/data/icons/power.png b/data/icons/power.png new file mode 100644 index 0000000000000000000000000000000000000000..f9d1fe578f888f3ecf937287e3d94e05a112229d GIT binary patch literal 426 zcmV;b0agBqP)pF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H10XIoR zK~yM_jgmhvL{SjM&%9Oo7YTMLGz%ws)~H1CJIeN?*DO=dPQvs*J86J2)w%92d49tXMh`uaSc>rGa1kT+Q2jL<*^NH0T%jy08L>r U|26I@$^ZZW07*qoM6N<$g6#{bzW@LL literal 0 HcmV?d00001 diff --git a/data/icons/poweroff.png b/data/icons/poweroff.png new file mode 100644 index 0000000000000000000000000000000000000000..1fb1e75c828d38f907b7ff7556dc73de0455ff10 GIT binary patch literal 599 zcmV-d0;v6oP)pF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H10pv+U zK~yM_jgY--lTjGOf6sm2bnzpxR7tEc5sm0#Qi^uaKR~1y-av7%Aa!zZut@(0QOV+0 zce_YYQ$HZ6xL7QeYLh__ba_pn6&(~EY~SWS4sTLZNs4E=mwV57&N+`m7o>9eQ_=Y0 zg;?TH^~dsuPn|fXn^=)!z;;!Jx^djUPTqu~7c9=ndgcDde~JBB@1P@E7WB4XnYq61 zoXqCO6uk7yg@&HC=i4)?1t4xlh) z>hB(w5ncj)HVB?{8;}|-B#gL^fnMN6ty+5K0vI=Pwh;vL0)sXP-Y0Wj(LtXQi7e~t zN&;hswPDAB9f0qw+0k&BO(X|S?-n)pfD>JF3$MhOGydBLOB=+k?^M?FtS~C*5YPvF lQ)J$#z3W$JN@3j)e*jLFrNd8l&ny4{002ovPDHLkV1h8c408Yg literal 0 HcmV?d00001 diff --git a/development b/development new file mode 120000 index 00000000..1c69f2fb --- /dev/null +++ b/development @@ -0,0 +1 @@ +/home/bill/src/lua-scripts.local/development/ \ No newline at end of file diff --git a/tools/script_manager.lua b/tools/script_manager.lua index f8e6c73b..d54f9e6f 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -509,6 +509,25 @@ local function process_script_data(script_file) restore_log_level(old_log_level) end +local function ensure_lib_in_search_path(line) + local old_log_level = set_log_level(sm.log_level) + set_log_level(log.debug) + log.msg(log.debug, "line is " .. line) + if string.match(line, ds.sanitize_lua(dt.configuration.config_dir .. PS .. "lua/lib")) then + log.msg(log.debug, line .. " is already in search path, returning...") + return + end + local path = string.match(line, "(.+)/lib/.+lua") + log.msg(log.debug, "extracted path is " .. path) + log.msg(log.debug, "package.path is " .. package.path) + if not string.match(package.path, ds.sanitize_lua(path)) then + log.msg(log.debug, "path isn't in package.path, adding...") + package.path = package.path .. ";" .. path .. "/?.lua" + log.msg(log.debug, "new package.path is " .. package.path) + end + restore_log_level(old_log_level) +end + local function scan_scripts(script_dir) local old_log_level = set_log_level(sm.log_level) local script_count = 0 @@ -529,6 +548,8 @@ local function scan_scripts(script_dir) process_script_data(script_file) script_count = script_count + 1 end + else + ensure_lib_in_search_path(line) -- but let's make sure libraries can be found end end end From 9c4e906033df371c66e17b8c9d8c070837ce0784 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Fri, 5 Apr 2024 20:37:34 -0400 Subject: [PATCH 03/12] data/icons - added 20px icons --- data/icons/blank20.png | Bin 0 -> 5678 bytes data/icons/path20.png | Bin 0 -> 6265 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 data/icons/blank20.png create mode 100644 data/icons/path20.png diff --git a/data/icons/blank20.png b/data/icons/blank20.png new file mode 100644 index 0000000000000000000000000000000000000000..81ed51574807dde06248d05f94fe17aad24b193a GIT binary patch literal 5678 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 literal 0 HcmV?d00001 diff --git a/data/icons/path20.png b/data/icons/path20.png new file mode 100644 index 0000000000000000000000000000000000000000..1021d86405b81bbfa10a78e4ea7e8de8651462dd GIT binary patch literal 6265 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 Date: Fri, 5 Apr 2024 20:38:10 -0400 Subject: [PATCH 04/12] tools/script_manager added parser for script_data.metadata blocks in scripts. Parsed data block is used as the tooltip. Fallback is the comment block at the top of the script. --- tools/script_manager.lua | 158 +++++++++++++++++++++++++++------------ 1 file changed, 109 insertions(+), 49 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index d54f9e6f..39072052 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -68,7 +68,7 @@ end -- api check -du.check_min_api_version("5.0.0", "script_manager") +du.check_min_api_version("9.3.0", "script_manager") -- - - - - - - - - - - - - - - - - - - - - - - - -- C O N S T A N T S @@ -93,6 +93,10 @@ local LUA_SCRIPT_REPO = "https://github.com/darktable-org/lua-scripts.git" local LUA_API_VER = "API-" .. dt.configuration.api_version_string +-- local POWER_ICON = dt.configuration.config_dir .. "/lua/data/data/icons/power.png" +local POWER_ICON = dt.configuration.config_dir .. "/lua/data/icons/path20.png" +local BLANK_ICON = dt.configuration.config_dir .. "/lua/data/icons/blank20.png" + -- - - - - - - - - - - - - - - - - - - - - - - - -- P R E F E R E N C E S -- - - - - - - - - - - - - - - - - - - - - - - - @@ -344,6 +348,10 @@ local function string_dequote(str) return string.gsub(str, "['\"]", "") end +local function string_dei18n(str) + return string.match(str, "%_%((.+)%)") +end + ------------------ -- script handling ------------------ @@ -358,6 +366,51 @@ local function add_script_folder(folder) restore_log_level(old_log_level) end +local function get_script_metadata(script) + local old_log_level = set_log_level(sm.log_level) + -- set_log_level(log.debug) + + log.msg(log.debug, "processing metatdata for " .. script) + + local description = nil + local metadata = nil + + f = io.open(LUA_DIR .. PS .. script .. ".lua") + if f then + -- slurp the file + local content = f:read("*all") + f:close() + -- grab the script_data.metadata table + description = string.match(content, "script_data%.metadata = %{\r?\n(.-)\r?\n%}") + else + log.msg(log.error, _("Cant read from " .. script)) + end + + if description then + metadata = "" + -- format it into a string block for display + local lines = du.split(description, "\n") + log.msg(log.debug, "got " .. #lines .. " lines") + local first = 1 + for i = 1, #lines do + log.msg(log.debug, "splitting line " .. lines[i]) + local parts = du.split(lines[i], " = ") + log.msg(log.debug, "got value " .. parts[1] .. " and data " .. parts[2]) + if string.match(parts[2], "%_%(") then + parts[2] = _(string_dequote(string_dei18n(parts[2]))) + else + parts[2] = string_dequote(parts[2]) + end + metadata = metadata .. string.format("%s%-10s\t%s", first and "" or "\n", parts[1], parts[2]) + first = nil + end + log.msg(log.debug, "script data is \n" .. metadata) + end + + restore_log_level(old_log_level) + return metadata +end + local function get_script_doc(script) local old_log_level = set_log_level(sm.log_level) local description = nil @@ -461,6 +514,7 @@ local function add_script_name(name, path, folder) path = folder .. "/" .. path .. name, running = false, doc = get_script_doc(folder .. "/" .. path .. name), + metadata = get_script_metadata(folder .. "/" .. path .. name), script_name = folder .. "/" .. name, data = nil } @@ -511,7 +565,7 @@ end local function ensure_lib_in_search_path(line) local old_log_level = set_log_level(sm.log_level) - set_log_level(log.debug) + -- set_log_level(log.debug) log.msg(log.debug, "line is " .. line) if string.match(line, ds.sanitize_lua(dt.configuration.config_dir .. PS .. "lua/lib")) then log.msg(log.debug, line .. " is already in search path, returning...") @@ -710,10 +764,12 @@ end local function clear_button(number) local old_log_level = set_log_level(sm.log_level) local button = sm.widgets.buttons[number] - button.label = "" + local label = sm.widgets.labels[number] + button.image = BLANK_ICON button.tooltip = "" button.sensitive = false - --button.name = "" + label.label = "" + button.name = "" restore_log_level(old_log_level) end @@ -734,58 +790,36 @@ local function populate_buttons(folder, first, last) log.msg(log.debug, "folder is " .. folder .. " and first is " .. first .. " and last is " .. last) local button_num = 1 for i = first, last do - script = sm.scripts[folder][i] - button = sm.widgets.buttons[button_num] + local script = sm.scripts[folder][i] + local button = sm.widgets.buttons[button_num] + local label = sm.widgets.labels[button_num] if script.running == true then - if sm.use_color then - button.label = script.name - button.name = "sm_started" - else - button.label = script.name .. _(" started") - end + button.name = "pb_on" else - if sm.use_color then - button.label = script.name - button.name = "sm_stopped" - else - button.label = script.name .. _(" stopped") - end + button.name = "pb_off" end - button.ellipsize = "middle" + button.image = POWER_ICON + label.label = script.name + label.name = "pb_label" + button.ellipsize = "end" button.sensitive = true - button.tooltip = script.doc + label.tooltip = script.metadata and script.metadata or script.doc button.clicked_callback = function (this) - local script_name = nil + local cb_script = script local state = nil - if sm.use_color then - script_name = string.match(this.label, "(.+)") - else - script_name, state = string.match(this.label, "(.-) (.+)") - end - local script = find_script(sm.widgets.folder_selector.value, script_name) - if script then - log.msg(log.debug, "found script " .. script.name .. " with path " .. script.path) - if script.running == true then - log.msg(log.debug, "deactivating " .. script.name .. " on " .. script.path .. " for button " .. this.label) - deactivate(script) - if sm.use_color then - this.name = "sm_stopped" - else - this.label = script.name .. _(" stopped") - end + if cb_script then + log.msg(log.debug, "found script " .. cb_script.name .. " with path " .. cb_script.path) + if cb_script.running == true then + log.msg(log.debug, "deactivating " .. cb_script.name .. " on " .. cb_script.path) + deactivate(cb_script) + this.name = "pb_off" else - log.msg(log.debug, "activating " .. script.name .. " on " .. script.path .. " for button " .. this.label) - local result = activate(script) + log.msg(log.debug, "activating " .. cb_script.name .. " on " .. script.path) + local result = activate(cb_script) if result then - if sm.use_color then - this.name = "sm_started" - else - this.label = script.name .. " started" - end + this.name = "pb_on" end end - else - log.msg(log.error, "script " .. script_name .. " not found") end end button_num = button_num + 1 @@ -870,18 +904,34 @@ end local function change_num_buttons() local old_log_level = set_log_level(sm.log_level) + -- set_log_level(log.debug) cur_buttons = sm.page_status.num_buttons new_buttons = sm.widgets.num_buttons.value pref_write("num_buttons", "integer", new_buttons) if new_buttons < cur_buttons then + log.msg(log.debug, "took new is less than current branch") for i = 1, cur_buttons - new_buttons do table.remove(sm.widgets.scripts) end log.msg(log.debug, "finished removing widgets, now there are " .. #sm.widgets.buttons) elseif new_buttons > cur_buttons then + log.msg(log.debug, "took new is greater than current branch") + log.msg(log.debug, "number of scripts is " .. #sm.widgets.scripts) + log.msg(log.debug, "number of buttons is " .. #sm.widgets.buttons) + log.msg(log.debug, "number of labels is " .. #sm.widgets.labels) + log.msg(log.debug, "number of boxes is " .. #sm.widgets.boxes) if new_buttons > sm.page_status.buttons_created then for i = sm.page_status.buttons_created + 1, new_buttons do + log.msg(log.debug, "i is " .. i) table.insert(sm.widgets.buttons, dt.new_widget("button"){}) + log.msg(log.debug, "inserted new button") + log.msg(log.debug, "number of buttons is " .. #sm.widgets.buttons) + table.insert(sm.widgets.labels, dt.new_widget("label"){}) + log.msg(log.debug, "inserted new label") + log.msg(log.debug, "number of labels is " .. #sm.widgets.labels) + table.insert(sm.widgets.boxes, dt.new_widget("box"){ orientation = "horizontal", expand = false, fill = false, + sm.widgets.buttons[i], sm.widgets.labels[i]}) + log.msg(log.debug, "inserted new box") sm.page_status.buttons_created = sm.page_status.buttons_created + 1 end end @@ -889,7 +939,7 @@ local function change_num_buttons() log.msg(log.debug, #sm.widgets.buttons .. " buttons are available") for i = cur_buttons + 1, new_buttons do log.msg(log.debug, "inserting button " .. i .. " into scripts widget") - table.insert(sm.widgets.scripts, sm.widgets.buttons[i]) + table.insert(sm.widgets.scripts, sm.widgets.boxes[i]) end log.msg(log.debug, "finished adding widgets, now there are " .. #sm.widgets.buttons) else -- no change @@ -1158,10 +1208,20 @@ sm.widgets.folder_selector = dt.new_widget("combobox"){ table.unpack(sm.folders), } +-- a script "button" consists of: +-- a button to start and stop the script +-- a label that contains the name of the script +-- a horizontal box that contains the button and the label + sm.widgets.buttons ={} +sm.widgets.labels = {} +sm.widgets.boxes = {} for i =1, DEFAULT_BUTTONS_PER_PAGE do table.insert(sm.widgets.buttons, dt.new_widget("button"){}) - sm.page_status.buttons_create = sm.page_status.buttons_created + 1 + table.insert(sm.widgets.labels, dt.new_widget("label"){}) + table.insert(sm.widgets.boxes, dt.new_widget("box"){ orientation = "horizontal", expand = false, fill = false, + sm.widgets.buttons[i], sm.widgets.labels[i]}) + sm.page_status.buttons_created = sm.page_status.buttons_created + 1 end local page_back = "<" @@ -1198,7 +1258,7 @@ sm.widgets.scripts = dt.new_widget("box"){ dt.new_widget("label"){label = _("Scripts")}, sm.widgets.folder_selector, sm.widgets.page_control, - table.unpack(sm.widgets.buttons) + table.unpack(sm.widgets.boxes) } -- configure options From 3b0ff3475a13dca20df22c706d95bc10a60f58ea Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Fri, 5 Apr 2024 21:12:45 -0400 Subject: [PATCH 05/12] tools/script_manager added blank lines to improve code readability --- tools/script_manager.lua | 177 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 174 insertions(+), 3 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index 39072052..435768c3 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -216,17 +216,24 @@ end local function pref_read(name, pref_type) local old_log_level = set_log_level(sm.log_level) + log.msg(log.debug, "name is " .. name .. " and type is " .. pref_type) + local val = dt.preferences.read(MODULE, name, pref_type) + log.msg(log.debug, "read value " .. tostring(val)) + restore_log_level(old_log_level) return val end local function pref_write(name, pref_type, value) local old_log_level = set_log_level(sm.log_level) + log.msg(log.debug, "writing value " .. tostring(value) .. " for name " .. name) + dt.preferences.write(MODULE, name, pref_type, value) + restore_log_level(old_log_level) end @@ -236,12 +243,15 @@ end local function get_repo_status(repo) local old_log_level = set_log_level(sm.log_level) + local p = io.popen("cd " .. repo .. CS .. "git status") + if p then local data = p:read("*a") p:close() return data end + log.msg(log.error, "unable to get status of " .. repo) restore_log_level(old_log_level) return nil @@ -249,8 +259,11 @@ end local function get_current_repo_branch(repo) local old_log_level = set_log_level(sm.log_level) + local branch = nil + local p = io.popen("cd " .. repo .. CS .. "git branch --all") + if p then local data = p:read("*a") p:close() @@ -258,23 +271,29 @@ local function get_current_repo_branch(repo) for _, b in ipairs(branches) do log.msg(log.debug, "branch for testing is " .. b) branch = string.match(b, "^%* (.-)$") + if branch then log.msg(log.info, "current repo branch is " .. branch) return branch end + end end + if not branch then log.msg(log.error, "no current branch detected in repo_data") end + restore_log_level(old_log_level) return nil end local function get_repo_branches(repo) local old_log_level = set_log_level(sm.log_level) + local branches = {} local p = io.popen("cd " .. repo .. CS .. "git pull --all" .. CS .. "git branch --all") + if p then local data = p:read("*a") p:close() @@ -289,12 +308,14 @@ local function get_repo_branches(repo) end end end + restore_log_level(old_log_level) return branches end local function is_repo_clean(repo_data) local old_log_level = set_log_level(sm.log_level) + if string.match(repo_data, "\n%s-%a.-%a:%s-%a%g-\n") then log.msg(log.info, "repo is dirty") return false @@ -302,13 +323,17 @@ local function is_repo_clean(repo_data) log.msg(log.info, "repo is clean") return true end + restore_log_level(old_log_level) end local function checkout_repo_branch(repo, branch) local old_log_level = set_log_level(sm.log_level) + log.msg(log.info, "checkout out branch " .. branch .. " from repository " .. repo) + os.execute("cd " .. repo .. CS .. "git checkout " .. branch) + restore_log_level(old_log_level) end @@ -318,16 +343,20 @@ end local function update_combobox_choices(combobox, choice_table, selected) local old_log_level = set_log_level(sm.log_level) + local items = #combobox local choices = #choice_table + for i, name in ipairs(choice_table) do combobox[i] = name end + if choices < items then for j = items, choices + 1, -1 do combobox[j] = nil end end + if not selected then selected = 1 end @@ -338,8 +367,10 @@ end local function string_trim(str) local old_log_level = set_log_level(sm.log_level) + local result = string.gsub(str, "^%s+", "") result = string.gsub(result, "%s+$", "") + restore_log_level(old_log_level) return result end @@ -358,11 +389,13 @@ end local function add_script_folder(folder) local old_log_level = set_log_level(sm.log_level) + if #sm.folders == 0 or not string.match(du.join(sm.folders, " "), ds.sanitize_lua(folder)) then table.insert(sm.folders, folder) sm.scripts[folder] = {} log.msg(log.debug, "created folder " .. folder) end + restore_log_level(old_log_level) end @@ -435,18 +468,26 @@ end local function activate(script) local old_log_level = set_log_level(sm.log_level) + local status = nil -- status of start function local err = nil -- error message returned if module doesn't start + log.msg(log.info, "activating " .. script.name) + if script.running == false then + script_manager_running_script = script.name + status, err = du.prequire(script.path) log.msg(log.debug, "prequire returned " .. tostring(status) .. " and for err " .. tostring(err)) + script_manager_running_script = nil + if status then pref_write(script.script_name, "bool", true) log.msg(log.screen, _("Loaded ") .. script.script_name) script.running = true + if err ~= true then log.msg(log.debug, "got lib data") script.data = err @@ -456,17 +497,20 @@ local function activate(script) else script.data = nil end + else log.msg(log.screen, script.script_name .. _(" failed to load")) log.msg(log.error, "Error loading " .. script.script_name) log.msg(log.error, "Error message: " .. err) end + else -- script is a lib and loaded but hidden and the user wants to reload script.data.restart() script.running = true status = true pref_write(script.script_name, "bool", true) end + restore_log_level(old_log_level) return status end @@ -481,9 +525,13 @@ local function deactivate(script) -- deactivate it.... local old_log_level = set_log_level(sm.log_level) + pref_write(script.script_name, "bool", false) + if script.data then + script.data.destroy() + if script.data.destroy_method then if string.match(script.data.destroy_method, "hide") then script.running = "hidden" @@ -495,20 +543,26 @@ local function deactivate(script) package.loaded[script.script_name] = nil script.running = false end + log.msg(log.info, "turned off " .. script.script_name) log.msg(log.screen, script.name .. _(" stopped")) + else script.running = false + log.msg(log.info, "setting " .. script.script_name .. " to not start") log.msg(log.screen, script.name .. _(" will not start when darktable is restarted")) end + restore_log_level(old_log_level) end local function add_script_name(name, path, folder) local old_log_level = set_log_level(sm.log_level) + log.msg(log.debug, "folder is " .. folder) log.msg(log.debug, "name is " .. name) + local script = { name = name, path = folder .. "/" .. path .. name, @@ -518,12 +572,15 @@ local function add_script_name(name, path, folder) script_name = folder .. "/" .. name, data = nil } + table.insert(sm.scripts[folder], script) + if pref_read(script.script_name, "bool") then activate(script) else pref_write(script.script_name, "bool", false) end + restore_log_level(old_log_level) end @@ -565,31 +622,43 @@ end local function ensure_lib_in_search_path(line) local old_log_level = set_log_level(sm.log_level) - -- set_log_level(log.debug) + log.msg(log.debug, "line is " .. line) + if string.match(line, ds.sanitize_lua(dt.configuration.config_dir .. PS .. "lua/lib")) then log.msg(log.debug, line .. " is already in search path, returning...") return end + local path = string.match(line, "(.+)/lib/.+lua") + log.msg(log.debug, "extracted path is " .. path) log.msg(log.debug, "package.path is " .. package.path) + if not string.match(package.path, ds.sanitize_lua(path)) then + log.msg(log.debug, "path isn't in package.path, adding...") + package.path = package.path .. ";" .. path .. "/?.lua" + log.msg(log.debug, "new package.path is " .. package.path) end + restore_log_level(old_log_level) end local function scan_scripts(script_dir) local old_log_level = set_log_level(sm.log_level) + local script_count = 0 local find_cmd = "find -L " .. script_dir .. " -name \\*.lua -print | sort" + if dt.configuration.running_os == "windows" then find_cmd = "dir /b/s \"" .. script_dir .. "\\*.lua\" | sort" end + log.msg(log.debug, _("find command is ") .. find_cmd) + -- scan the scripts local output = io.popen(find_cmd) for line in output:lines() do @@ -608,6 +677,7 @@ local function scan_scripts(script_dir) end end end + restore_log_level(old_log_level) return script_count end @@ -646,39 +716,54 @@ end local function update_script_update_choices() local old_log_level = set_log_level(sm.log_level) + local installs = {} local pref_string = "" + for i, repo in ipairs(sm.installed_repositories) do table.insert(installs, repo.name) pref_string = pref_string .. i .. "," .. repo.name .. "," .. repo.directory .. "," end + update_combobox_choices(sm.widgets.update_script_choices, installs, 1) + log.msg(log.debug, "repo pref string is " .. pref_string) pref_write("installed_repos", "string", pref_string) + restore_log_level(old_log_level) end local function scan_repositories() local old_log_level = set_log_level(sm.log_level) + local script_count = 0 local find_cmd = "find -L " .. LUA_DIR .. " -name \\*.git -print | sort" + if dt.configuration.running_os == "windows" then find_cmd = "dir /b/s /a:d " .. LUA_DIR .. PS .. "*.git | sort" end + log.msg(log.debug, _("find command is ") .. find_cmd) + local output = io.popen(find_cmd) + for line in output:lines() do local l = string.gsub(line, ds.sanitize_lua(LUA_DIR) .. PS, "") -- strip the lua dir off - local folder = string.match(l, "(.-)" .. PS) -- get everything to teh first / + local folder = string.match(l, "(.-)" .. PS) -- get everything to the first / + if folder then -- if we have a folder (.git doesn't) + log.msg(log.debug, "found folder " .. folder) + if not string.match(folder, "plugins") and not string.match(folder, "%.git") then -- skip plugins + if #sm.installed_repositories == 1 then log.msg(log.debug, "only 1 repo, adding " .. folder) table.insert(sm.installed_repositories, {name = folder, directory = LUA_DIR .. PS .. folder}) else log.msg(log.debug, "more than 1 repo, we have to search the repos to make sure it's not there") local found = nil + for _, repo in ipairs(sm.installed_repositories) do if string.match(repo.name, ds.sanitize_lua(folder)) then log.msg(log.debug, "matched " .. repo.name) @@ -686,19 +771,24 @@ local function scan_repositories() break end end + if not found then table.insert(sm.installed_repositories, {name = folder, directory = LUA_DIR .. PS .. folder}) end + end end end end + update_script_update_choices() + restore_log_level(old_log_level) end local function install_scripts() local old_log_level = set_log_level(sm.log_level) + local url = sm.widgets.script_url.text local folder = sm.widgets.new_folder.text @@ -732,11 +822,13 @@ local function install_scripts() if result == 0 then local count = scan_scripts(LUA_DIR .. PS .. folder) + if count > 0 then update_combobox_choices(sm.widgets.folder_selector, sm.folders, sm.widgets.folder_selector.selected) dt.print(_("scripts successfully installed into folder ") .. folder) table.insert(sm.installed_repositories, {name = folder, directory = LUA_DIR .. PS .. folder}) update_script_update_choices() + for i = 1, #sm.widgets.folder_selector do if string.match(sm.widgets.folder_selector[i], ds.sanitize_lua(folder)) then log.msg(log.debug, "setting folder selector to " .. i) @@ -745,6 +837,7 @@ local function install_scripts() end i = i + 1 end + log.msg(log.debug, "clearing text fields") sm.widgets.script_url.text = "" sm.widgets.new_folder.text = "" @@ -753,6 +846,7 @@ local function install_scripts() dt.print(_("No scripts found to install")) log.msg(log.error, "scan_scripts returned " .. count .. " scripts found. Not adding to folder_selector") end + else dt.print(_("failed to download scripts")) end @@ -763,47 +857,59 @@ end local function clear_button(number) local old_log_level = set_log_level(sm.log_level) + local button = sm.widgets.buttons[number] local label = sm.widgets.labels[number] + button.image = BLANK_ICON button.tooltip = "" button.sensitive = false label.label = "" button.name = "" + restore_log_level(old_log_level) end local function find_script(folder, name) local old_log_level = set_log_level(sm.log_level) + log.msg(log.debug, "looking for script " .. name .. " in folder " .. folder) + for _, script in ipairs(sm.scripts[folder]) do if string.match(script.name, "^" .. ds.sanitize_lua(name) .. "$") then return script end end + restore_log_level(old_log_level) return nil end local function populate_buttons(folder, first, last) local old_log_level = set_log_level(sm.log_level) + log.msg(log.debug, "folder is " .. folder .. " and first is " .. first .. " and last is " .. last) + local button_num = 1 + for i = first, last do local script = sm.scripts[folder][i] local button = sm.widgets.buttons[button_num] local label = sm.widgets.labels[button_num] + if script.running == true then button.name = "pb_on" else button.name = "pb_off" end + button.image = POWER_ICON label.label = script.name label.name = "pb_label" button.ellipsize = "end" button.sensitive = true label.tooltip = script.metadata and script.metadata or script.doc + button.clicked_callback = function (this) local cb_script = script local state = nil @@ -822,23 +928,30 @@ local function populate_buttons(folder, first, last) end end end + button_num = button_num + 1 end + if button_num <= sm.page_status.num_buttons then for i = button_num, sm.page_status.num_buttons do clear_button(i) end end + restore_log_level(old_log_level) end local function paginate(direction) local old_log_level = set_log_level(sm.log_level) + local folder = sm.page_status.folder log.msg(log.debug, "folder is " .. folder) + local num_scripts = #sm.scripts[folder] log.msg(log.debug, "num_scripts is " .. num_scripts) + local max_pages = math.ceil(num_scripts / sm.page_status.num_buttons) + local cur_page = sm.page_status.current_page log.msg(log.debug, "max pages is " .. max_pages) @@ -860,7 +973,9 @@ local function paginate(direction) log.msg(log.debug, "took path 2") cur_page = 1 end + log.msg(log.debug, "cur_page is " .. cur_page .. " and max_pages is " .. max_pages) + if cur_page == max_pages and cur_page == 1 then sm.widgets.page_forward.sensitive = false sm.widgets.page_back.sensitive = false @@ -876,20 +991,25 @@ local function paginate(direction) end sm.page_status.current_page = cur_page + first = (cur_page * sm.page_status.num_buttons) - (sm.page_status.num_buttons - 1) + if first + sm.page_status.num_buttons > num_scripts then last = num_scripts else last = first + sm.page_status.num_buttons - 1 end + sm.widgets.page_status.label = _("Page ") .. cur_page .. _(" of ") .. max_pages populate_buttons(folder, first, last) + restore_log_level(old_log_level) end local function change_folder(folder) local old_log_level = set_log_level(sm.log_level) + if not folder then log.msg(log.debug "setting folder to selector value " .. sm.widgets.folder_selector.value) sm.page_status.folder = sm.widgets.folder_selector.value @@ -899,20 +1019,25 @@ local function change_folder(folder) end paginate(2) + restore_log_level(old_log_level) end local function change_num_buttons() local old_log_level = set_log_level(sm.log_level) - -- set_log_level(log.debug) + cur_buttons = sm.page_status.num_buttons new_buttons = sm.widgets.num_buttons.value + pref_write("num_buttons", "integer", new_buttons) + if new_buttons < cur_buttons then log.msg(log.debug, "took new is less than current branch") + for i = 1, cur_buttons - new_buttons do table.remove(sm.widgets.scripts) end + log.msg(log.debug, "finished removing widgets, now there are " .. #sm.widgets.buttons) elseif new_buttons > cur_buttons then log.msg(log.debug, "took new is greater than current branch") @@ -920,7 +1045,9 @@ local function change_num_buttons() log.msg(log.debug, "number of buttons is " .. #sm.widgets.buttons) log.msg(log.debug, "number of labels is " .. #sm.widgets.labels) log.msg(log.debug, "number of boxes is " .. #sm.widgets.boxes) + if new_buttons > sm.page_status.buttons_created then + for i = sm.page_status.buttons_created + 1, new_buttons do log.msg(log.debug, "i is " .. i) table.insert(sm.widgets.buttons, dt.new_widget("button"){}) @@ -934,73 +1061,97 @@ local function change_num_buttons() log.msg(log.debug, "inserted new box") sm.page_status.buttons_created = sm.page_status.buttons_created + 1 end + end + log.msg(log.debug, "cur_buttons is " .. cur_buttons .. " and new_buttons is " .. new_buttons) log.msg(log.debug, #sm.widgets.buttons .. " buttons are available") + for i = cur_buttons + 1, new_buttons do log.msg(log.debug, "inserting button " .. i .. " into scripts widget") table.insert(sm.widgets.scripts, sm.widgets.boxes[i]) end + log.msg(log.debug, "finished adding widgets, now there are " .. #sm.widgets.buttons) else -- no change log.msg(log.debug, "no change, just returning") return end + sm.page_status.num_buttons = new_buttons log.msg(log.debug, "num_buttons set to " .. sm.page_status.num_buttons) paginate(2) -- force the buttons to repopulate sm.widgets.main_menu.selected = 3 -- jump back to start/stop scripts + restore_log_level(old_log_level) end local function load_preferences() local old_log_level = set_log_level(sm.log_level) + -- load the prefs and update settings -- update_script_choices + local pref_string = pref_read("installed_repos", "string") local entries = du.split(pref_string, ",") + while #entries > 2 do local num = table.remove(entries, 1) local name = table.remove(entries, 1) local directory = table.remove(entries, 1) + if not string.match(sm.installed_repositories[1].name, "^" .. ds.sanitize_lua(name) .. "$") then table.insert(sm.installed_repositories, {name = name, directory = directory}) end + end + update_script_update_choices() log.msg(log.debug, "updated installed scripts") + -- folder selector local val = pref_read("folder_selector", "integer") + if val == 0 then val = 1 end + sm.widgets.folder_selector.selected = val sm.page_status.folder = sm.widgets.folder_selector.value log.msg(log.debug, "updated folder selector and set it to " .. sm.widgets.folder_selector.value) + -- num_buttons local val = pref_read("num_buttons", "integer") + if val == 0 then val = DEFAULT_BUTTONS_PER_PAGE end + sm.widgets.num_buttons.value = val log.msg(log.debug, "set page buttons to " .. val) + change_num_buttons() log.msg(log.debug, "paginated") + -- main menu local val = pref_read("main_menu_action", "integer") log.msg(log.debug, "read " .. val .. " for main menu") + if val == 0 then val = 3 end + sm.widgets.main_menu.selected = val log.msg(log.debug, "set main menu to val " .. val .. " which is " .. sm.widgets.main_menu.value) log.msg(log.debug, "set main menu to " .. sm.widgets.main_menu.value) + restore_log_level(old_log_level) end local function install_module() local old_log_level = set_log_level(sm.log_level) + if not sm.module_installed then dt.register_lib( "script_manager", -- Module name @@ -1014,6 +1165,7 @@ local function install_module() ) sm.module_installed = true end + sm.run = true sm.use_color = pref_read("use_color", "bool") log.msg(log.debug, "set run to true, loading preferences") @@ -1030,6 +1182,7 @@ local function install_module() dt.control.sleep(5000) dt.print_log("setting sm expanded true") dt.gui.libs["script_manager"].expanded = true]] + restore_log_level(old_log_level) end @@ -1048,22 +1201,28 @@ if check_for_updates then local repo = LUA_DIR if current_branch then + if sm.executables.git and clean and + (current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches local branches = get_repo_branches(LUA_DIR) + if current_branch ~= LUA_API_VER and current_branch ~= "master" then -- probably upgraded from an earlier api version so get back to master -- to use the latest version of script_manager to get the proper API checkout_repo_branch(repo, "master") log.msg(log.screen, "lua API version reset, please restart darktable") + elseif LUA_API_VER == current_branch then -- do nothing, we are fine log.msg(log.debug, "took equal branch, doing nothing") + elseif string.match(LUA_API_VER, "dev") then -- we are on a dev API version, so checkout the dev -- api version or checkout/stay on master log.msg(log.debug, "took the dev branch") local match = false + for _, branch in ipairs(branches) do log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER) if LUA_API_VER == branch then @@ -1072,6 +1231,7 @@ if check_for_updates then checkout_repo_branch(repo, branch) end end + if not match then if current_branch == "master" then log.msg(log.info, "staying on master, no dev branch yet") @@ -1080,25 +1240,33 @@ if check_for_updates then checkout_repo_branch(repo, "master") end end + elseif #branches > 0 and LUA_API_VER > branches[#branches] then log.msg(log.info, "no newer branches, staying on master") -- stay on master + else -- checkout the appropriate branch for API version if it exists log.msg(log.info, "checking out the appropriate API branch") + local match = false + for _, branch in ipairs(branches) do log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER) + if LUA_API_VER == branch then match = true log.msg(log.info, "checking out repo branch " .. branch) checkout_repo_branch(repo, branch) log.msg(log.screen, "you must restart darktable to use the correct version of the lua") end + end + if not match then log.msg(log.warn, "no matching branch found for " .. LUA_API_VER) end + end end end @@ -1216,6 +1384,7 @@ sm.widgets.folder_selector = dt.new_widget("combobox"){ sm.widgets.buttons ={} sm.widgets.labels = {} sm.widgets.boxes = {} + for i =1, DEFAULT_BUTTONS_PER_PAGE do table.insert(sm.widgets.buttons, dt.new_widget("button"){}) table.insert(sm.widgets.labels, dt.new_widget("label"){}) @@ -1228,6 +1397,7 @@ local page_back = "<" local page_forward = ">" sm.widgets.page_status = dt.new_widget("label"){label = _("Page:")} + sm.widgets.page_back = dt.new_widget("button"){ label = page_back, clicked_callback = function(this) @@ -1297,6 +1467,7 @@ sm.widgets.color = dt.new_widget("check_button"){ sm.use_color = this.value end } + table.insert(sm.widgets.configure, sm.widgets.color) -- stack for the options From ddf0c8940208bfe79c5a67aa2aa43ac71ad87ac1 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 6 Apr 2024 21:28:58 -0400 Subject: [PATCH 06/12] tools/script_manager - cleaned up layout of panels and added some spacing so what is being operated on is more appearent --- tools/script_manager.lua | 44 +++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index 435768c3..6e60af3b 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -1351,14 +1351,25 @@ sm.widgets.disable_scripts = dt.new_widget("button"){ sm.widgets.install_update = dt.new_widget("box"){ orientation = "vertical", - dt.new_widget("section_label"){label = _("update scripts")}, + dt.new_widget("section_label"){label = _(" ")}, + dt.new_widget("label"){label = " "}, + dt.new_widget("label"){label = _("update scripts")}, + dt.new_widget("label"){label = " "}, sm.widgets.update_script_choices, sm.widgets.update, - dt.new_widget("section_label"){label = _("add more scripts")}, + dt.new_widget("section_label"){label = " "}, + dt.new_widget("label"){label = " "}, + dt.new_widget("label"){label = _("add more scripts")}, + dt.new_widget("label"){label = " "}, sm.widgets.add_scripts, - dt.new_widget("section_label"){label = _("disable scripts")}, + dt.new_widget("section_label"){label = " "}, + dt.new_widget("label"){label = " "}, + dt.new_widget("label"){label = _("disable scripts")}, + dt.new_widget("label"){label = " "}, sm.widgets.allow_disable, - sm.widgets.disable_scripts + sm.widgets.disable_scripts, + dt.new_widget("section_label"){label = " "}, + dt.new_widget("label"){label = " "}, } -- manage the scripts @@ -1425,10 +1436,12 @@ sm.widgets.page_control = dt.new_widget("box"){ sm.widgets.scripts = dt.new_widget("box"){ orientation = vertical, + dt.new_widget("section_label"){label = _(" ")}, + dt.new_widget("label"){label = " "}, dt.new_widget("label"){label = _("Scripts")}, sm.widgets.folder_selector, sm.widgets.page_control, - table.unpack(sm.widgets.boxes) + table.unpack(sm.widgets.boxes), } -- configure options @@ -1452,13 +1465,6 @@ sm.widgets.change_buttons = dt.new_widget("button"){ end } -sm.widgets.configure = dt.new_widget("box"){ - orientation = "vertical", - dt.new_widget("label"){label = _("Configuration")}, - sm.widgets.num_buttons, - sm.widgets.change_buttons, -} - sm.widgets.color = dt.new_widget("check_button"){ label = _("use color interface?"), value = pref_read("use_color", "bool"), @@ -1468,7 +1474,21 @@ sm.widgets.color = dt.new_widget("check_button"){ end } +sm.widgets.configure = dt.new_widget("box"){ + orientation = "vertical", + dt.new_widget("section_label"){label = " "}, + dt.new_widget("label"){label = " "}, + dt.new_widget("label"){label = _("Configuration")}, + dt.new_widget("label"){label = " "}, + sm.widgets.num_buttons, + dt.new_widget("label"){label = " "}, + sm.widgets.change_buttons, + dt.new_widget("label"){label = " "}, +} + table.insert(sm.widgets.configure, sm.widgets.color) +table.insert(sm.widgets.configure, dt.new_widget("section_label"){label = " "}) +table.insert(sm.widgets.configure, dt.new_widget("label"){label = " "}) -- stack for the options From b1b3392b92ae816502ca7fd97528d2ab7ce4e9a0 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Tue, 9 Apr 2024 21:41:42 -0400 Subject: [PATCH 07/12] tools/script_manager removed color interface check button. Color can be specified in the CSS using the tags that are present if desired. Cleaned up formatting of configuration items. Added a few debugging messages. --- tools/script_manager.lua | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index 6e60af3b..2313e309 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -184,9 +184,6 @@ sm.page_status.buttons_created = 0 sm.page_status.current_page = 0 sm.page_status.folder = "" --- use color in the interface? -sm.use_color = false - -- installed script repositories sm.installed_repositories = { {name = "lua-scripts", directory = LUA_DIR}, @@ -630,7 +627,8 @@ local function ensure_lib_in_search_path(line) return end - local path = string.match(line, "(.+)/lib/.+lua") + local pattern = dt.configuration.running_os == "windows" and "(.+)\\lib\\.+lua" or "(.+)/lib/.+lua" + local path = string.match(line, pattern) log.msg(log.debug, "extracted path is " .. path) log.msg(log.debug, "package.path is " .. package.path) @@ -657,11 +655,12 @@ local function scan_scripts(script_dir) find_cmd = "dir /b/s \"" .. script_dir .. "\\*.lua\" | sort" end - log.msg(log.debug, _("find command is ") .. find_cmd) + log.msg(log.debug, "find command is " .. find_cmd) -- scan the scripts local output = io.popen(find_cmd) for line in output:lines() do + log.msg(log.debug, "line is " .. line) local l = string.gsub(line, ds.sanitize_lua(LUA_DIR) .. PS, "") -- strip the lua dir off local script_file = l:sub(1,-5) -- strip off .lua\n if not string.match(script_file, "script_manager") then -- let's not include ourself @@ -1334,6 +1333,8 @@ sm.widgets.allow_disable = dt.new_widget("check_button"){ clicked_callback = function(this) if this.value == true then sm.widgets.disable_scripts.sensitive = true + else + sm.widgets.disable_scripts.sensitive = false end end, } @@ -1368,7 +1369,6 @@ sm.widgets.install_update = dt.new_widget("box"){ dt.new_widget("label"){label = " "}, sm.widgets.allow_disable, sm.widgets.disable_scripts, - dt.new_widget("section_label"){label = " "}, dt.new_widget("label"){label = " "}, } @@ -1465,15 +1465,6 @@ sm.widgets.change_buttons = dt.new_widget("button"){ end } -sm.widgets.color = dt.new_widget("check_button"){ - label = _("use color interface?"), - value = pref_read("use_color", "bool"), - clicked_callback = function(this) - pref_write("use_color", "bool", this.value) - sm.use_color = this.value - end -} - sm.widgets.configure = dt.new_widget("box"){ orientation = "vertical", dt.new_widget("section_label"){label = " "}, @@ -1486,10 +1477,6 @@ sm.widgets.configure = dt.new_widget("box"){ dt.new_widget("label"){label = " "}, } -table.insert(sm.widgets.configure, sm.widgets.color) -table.insert(sm.widgets.configure, dt.new_widget("section_label"){label = " "}) -table.insert(sm.widgets.configure, dt.new_widget("label"){label = " "}) - -- stack for the options sm.widgets.main_stack = dt.new_widget("stack"){ From f6916c3a15f0b57721501934dbc48a063787ecd6 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Wed, 15 May 2024 14:51:14 -0400 Subject: [PATCH 08/12] tools/script_manager - lower cased mixed case buttons and headings --- tools/script_manager.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index 2313e309..28bd1d98 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -1328,7 +1328,7 @@ sm.widgets.add_scripts = dt.new_widget("box"){ } sm.widgets.allow_disable = dt.new_widget("check_button"){ - label = _('Enable "Disable Scripts" button'), + label = _('enable "disable scripts" button'), value = false, clicked_callback = function(this) if this.value == true then @@ -1340,7 +1340,7 @@ sm.widgets.allow_disable = dt.new_widget("check_button"){ } sm.widgets.disable_scripts = dt.new_widget("button"){ - label = _("Disable Scripts"), + label = _("disable scripts"), sensitive = false, clicked_callback = function(this) local LUARC = dt.configuration.config_dir .. PS .. "luarc" @@ -1469,7 +1469,7 @@ sm.widgets.configure = dt.new_widget("box"){ orientation = "vertical", dt.new_widget("section_label"){label = " "}, dt.new_widget("label"){label = " "}, - dt.new_widget("label"){label = _("Configuration")}, + dt.new_widget("label"){label = _("configuration")}, dt.new_widget("label"){label = " "}, sm.widgets.num_buttons, dt.new_widget("label"){label = " "}, From 284c0f971484a367a1ed22bc69587deea4eafcef Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Wed, 15 May 2024 21:33:29 -0400 Subject: [PATCH 09/12] tools/script_manager - fixed metadata decoding to get rid of spurious commas --- tools/script_manager.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index 28bd1d98..b79dbe30 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -60,7 +60,7 @@ local gettext = dt.gettext -- Tell gettext where to find the .mo file translating messages for a particular domain -gettext.bindtextdomain("script_manager",dt.configuration.config_dir.."/lua/locale/") +dt.gettext.bindtextdomain("script_manager",dt.configuration.config_dir.."/lua/locale/") local function _(msgid) return gettext.dgettext("script_manager", msgid) @@ -380,6 +380,10 @@ local function string_dei18n(str) return string.match(str, "%_%((.+)%)") end +local function string_chop(str) + return str:sub(1, -2) +end + ------------------ -- script handling ------------------ @@ -431,6 +435,9 @@ local function get_script_metadata(script) else parts[2] = string_dequote(parts[2]) end + if string.match(parts[2], ",$") then + parts[2] = string_chop(parts[2]) + end metadata = metadata .. string.format("%s%-10s\t%s", first and "" or "\n", parts[1], parts[2]) first = nil end @@ -438,6 +445,7 @@ local function get_script_metadata(script) end restore_log_level(old_log_level) + dt.print_log(metadata) return metadata end From bf138abeb2d21e52839f7c7aa1ef459c3898e46d Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Wed, 15 May 2024 21:36:15 -0400 Subject: [PATCH 10/12] tools/script_manager - removed debugging statement --- tools/script_manager.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index b79dbe30..daaa824e 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -445,7 +445,6 @@ local function get_script_metadata(script) end restore_log_level(old_log_level) - dt.print_log(metadata) return metadata end From 9088bc91441ae4c1a65bd7a4b8a76793fac95465 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Mon, 3 Jun 2024 14:48:44 -0400 Subject: [PATCH 11/12] tools/script_manager - make the constants to ensure they stay that way --- tools/script_manager.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index daaa824e..ed93b963 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -75,27 +75,27 @@ du.check_min_api_version("9.3.0", "script_manager") -- - - - - - - - - - - - - - - - - - - - - - - - -- path separator -local PS = dt.configuration.running_os == "windows" and "\\" or "/" +local PS = dt.configuration.running_os == "windows" and "\\" or "/" -- command separator -local CS = dt.configuration.running_os == "windows" and "&" or ";" +local CS = dt.configuration.running_os == "windows" and "&" or ";" -local MODULE = "script_manager" +local MODULE = "script_manager" -local MIN_BUTTONS_PER_PAGE = 5 -local MAX_BUTTONS_PER_PAGE = 20 -local DEFAULT_BUTTONS_PER_PAGE = 10 +local MIN_BUTTONS_PER_PAGE = 5 +local MAX_BUTTONS_PER_PAGE = 20 +local DEFAULT_BUTTONS_PER_PAGE = 10 -local DEFAULT_LOG_LEVEL = log.error +local DEFAULT_LOG_LEVEL = log.error -local LUA_DIR = dt.configuration.config_dir .. PS .. "lua" -local LUA_SCRIPT_REPO = "https://github.com/darktable-org/lua-scripts.git" +local LUA_DIR = dt.configuration.config_dir .. PS .. "lua" +local LUA_SCRIPT_REPO = "https://github.com/darktable-org/lua-scripts.git" -local LUA_API_VER = "API-" .. dt.configuration.api_version_string +local LUA_API_VER = "API-" .. dt.configuration.api_version_string -- local POWER_ICON = dt.configuration.config_dir .. "/lua/data/data/icons/power.png" -local POWER_ICON = dt.configuration.config_dir .. "/lua/data/icons/path20.png" -local BLANK_ICON = dt.configuration.config_dir .. "/lua/data/icons/blank20.png" +local POWER_ICON = dt.configuration.config_dir .. "/lua/data/icons/path20.png" +local BLANK_ICON = dt.configuration.config_dir .. "/lua/data/icons/blank20.png" -- - - - - - - - - - - - - - - - - - - - - - - - -- P R E F E R E N C E S From 4ff111134141cbdd0adfdacee4643695847465d0 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Fri, 7 Jun 2024 15:23:06 -0400 Subject: [PATCH 12/12] tools/script_manaager added sanitized io.popen and os.execute functions for windows character and space issues. Cleaned up translatable strings to make future translation easier. --- tools/script_manager.lua | 69 +++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index ed93b963..955f4839 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -1,6 +1,6 @@ --[[ This file is part of darktable, - copyright (c) 2018, 2020, 2023 Bill Ferguson + copyright (c) 2018, 2020, 2023, 2024 Bill Ferguson darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -60,7 +60,7 @@ local gettext = dt.gettext -- Tell gettext where to find the .mo file translating messages for a particular domain -dt.gettext.bindtextdomain("script_manager",dt.configuration.config_dir.."/lua/locale/") +dt.gettext.bindtextdomain("script_manager", dt.configuration.config_dir .. "/lua/locale/") local function _(msgid) return gettext.dgettext("script_manager", msgid) @@ -241,7 +241,7 @@ end local function get_repo_status(repo) local old_log_level = set_log_level(sm.log_level) - local p = io.popen("cd " .. repo .. CS .. "git status") + local p = dtsys.io_popen("cd " .. repo .. CS .. "git status") if p then local data = p:read("*a") @@ -259,7 +259,7 @@ local function get_current_repo_branch(repo) local branch = nil - local p = io.popen("cd " .. repo .. CS .. "git branch --all") + local p = dtsys.io_popen("cd " .. repo .. CS .. "git branch --all") if p then local data = p:read("*a") @@ -289,7 +289,7 @@ local function get_repo_branches(repo) local old_log_level = set_log_level(sm.log_level) local branches = {} - local p = io.popen("cd " .. repo .. CS .. "git pull --all" .. CS .. "git branch --all") + local p = dtsys.io_popen("cd " .. repo .. CS .. "git pull --all" .. CS .. "git branch --all") if p then local data = p:read("*a") @@ -329,7 +329,7 @@ local function checkout_repo_branch(repo, branch) log.msg(log.info, "checkout out branch " .. branch .. " from repository " .. repo) - os.execute("cd " .. repo .. CS .. "git checkout " .. branch) + dtsys.os_execute("cd " .. repo .. CS .. "git checkout " .. branch) restore_log_level(old_log_level) end @@ -417,7 +417,7 @@ local function get_script_metadata(script) -- grab the script_data.metadata table description = string.match(content, "script_data%.metadata = %{\r?\n(.-)\r?\n%}") else - log.msg(log.error, _("Cant read from " .. script)) + log.msg(log.error, "cant read from " .. script) end if description then @@ -459,7 +459,7 @@ local function get_script_doc(script) -- assume that the second block comment is the documentation description = string.match(content, "%-%-%[%[.-%]%].-%-%-%[%[(.-)%]%]") else - log.msg(log.error, _("Cant read from " .. script)) + log.msg(log.error, "can't read from " .. script) end if description then restore_log_level(old_log_level) @@ -489,7 +489,7 @@ local function activate(script) if status then pref_write(script.script_name, "bool", true) - log.msg(log.screen, _("Loaded ") .. script.script_name) + log.msg(log.screen, _(string.format("loaded %s", script.script_name))) script.running = true if err ~= true then @@ -503,9 +503,9 @@ local function activate(script) end else - log.msg(log.screen, script.script_name .. _(" failed to load")) - log.msg(log.error, "Error loading " .. script.script_name) - log.msg(log.error, "Error message: " .. err) + log.msg(log.screen, _(string.format("%s failed to load", script.script_name))) + log.msg(log.error, "error loading " .. script.script_name) + log.msg(log.error, "error message: " .. err) end else -- script is a lib and loaded but hidden and the user wants to reload @@ -549,13 +549,13 @@ local function deactivate(script) end log.msg(log.info, "turned off " .. script.script_name) - log.msg(log.screen, script.name .. _(" stopped")) + log.msg(log.screen, _(string.format("%s stopped", script.name))) else script.running = false log.msg(log.info, "setting " .. script.script_name .. " to not start") - log.msg(log.screen, script.name .. _(" will not start when darktable is restarted")) + log.msg(log.screen, _(string.format("%s will not start when darktable is restarted", script.name))) end restore_log_level(old_log_level) @@ -665,7 +665,7 @@ local function scan_scripts(script_dir) log.msg(log.debug, "find command is " .. find_cmd) -- scan the scripts - local output = io.popen(find_cmd) + local output = dtsys.io_popen(find_cmd) for line in output:lines() do log.msg(log.debug, "line is " .. line) local l = string.gsub(line, ds.sanitize_lua(LUA_DIR) .. PS, "") -- strip the lua dir off @@ -695,7 +695,7 @@ local function update_scripts() local git = sm.executables.git if not git then - dt.print(_("ERROR: git not found. Install or specify the location of the git executable.")) + log.msg(log.screen, _("ERROR: git not found. Install or specify the location of the git executable.")) return end @@ -709,7 +709,7 @@ local function update_scripts() end if result == 0 then - dt.print(_("lua scripts successfully updated")) + log.msg(log.screen, _("lua scripts successfully updated")) end restore_log_level(old_log_level) @@ -749,9 +749,9 @@ local function scan_repositories() find_cmd = "dir /b/s /a:d " .. LUA_DIR .. PS .. "*.git | sort" end - log.msg(log.debug, _("find command is ") .. find_cmd) + log.msg(log.debug, "find command is " .. find_cmd) - local output = io.popen(find_cmd) + local output = dtsys.io_popen(find_cmd) for line in output:lines() do local l = string.gsub(line, ds.sanitize_lua(LUA_DIR) .. PS, "") -- strip the lua dir off @@ -799,7 +799,7 @@ local function install_scripts() local folder = sm.widgets.new_folder.text if string.match(du.join(sm.folders, " "), ds.sanitize_lua(folder)) then - log.msg(log.screen, _("folder ") .. folder .. _(" is already in use. Please specify a different folder name.")) + log.msg(log.screen, _(string.format("folder %s is already in use. Please specify a different folder name.", folder))) log.msg(log.error, "folder " .. folder .. " already exists, returning...") restore_log_level(old_log_level) return @@ -810,7 +810,7 @@ local function install_scripts() local git = sm.executables.git if not git then - dt.print(_("ERROR: git not found. Install or specify the location of the git executable.")) + log.msg(log.screen, _("ERROR: git not found. Install or specify the location of the git executable.")) restore_log_level(old_log_level) return end @@ -849,12 +849,12 @@ local function install_scripts() sm.widgets.new_folder.text = "" sm.widgets.main_menu.selected = 3 else - dt.print(_("No scripts found to install")) + log.msg(log.screen, _("No scripts found to install")) log.msg(log.error, "scan_scripts returned " .. count .. " scripts found. Not adding to folder_selector") end else - dt.print(_("failed to download scripts")) + log.msg(log.screen, _("failed to download scripts")) end restore_log_level(old_log_level) @@ -1006,7 +1006,7 @@ local function paginate(direction) last = first + sm.page_status.num_buttons - 1 end - sm.widgets.page_status.label = _("Page ") .. cur_page .. _(" of ") .. max_pages + sm.widgets.page_status.label = _(string.format("page %d of %d", cur_page, max_pages)) populate_buttons(folder, first, last) @@ -1177,17 +1177,6 @@ local function install_module() log.msg(log.debug, "set run to true, loading preferences") load_preferences() scan_repositories() - --[[dt.print_log("\n\nsetting sm visible false\n\n") - dt.gui.libs["script_manager"].visible = false - dt.control.sleep(5000) - dt.print_log("setting sm visible true") - dt.gui.libs["script_manager"].visible = true - --[[dt.control.sleep(5000) - dt.print_log("setting sm expanded false") - dt.gui.libs["script_manager"].expanded = false - dt.control.sleep(5000) - dt.print_log("setting sm expanded true") - dt.gui.libs["script_manager"].expanded = true]] restore_log_level(old_log_level) end @@ -1217,7 +1206,7 @@ if check_for_updates then -- probably upgraded from an earlier api version so get back to master -- to use the latest version of script_manager to get the proper API checkout_repo_branch(repo, "master") - log.msg(log.screen, "lua API version reset, please restart darktable") + log.msg(log.screen, _("lua API version reset, please restart darktable")) elseif LUA_API_VER == current_branch then -- do nothing, we are fine @@ -1353,7 +1342,7 @@ sm.widgets.disable_scripts = dt.new_widget("button"){ local LUARC = dt.configuration.config_dir .. PS .. "luarc" df.file_move(LUARC, LUARC .. ".disabled") log.msg(log.info, "lua scripts disabled") - dt.print(_("lua scripts will not run the next time darktable is started")) + log.msg(log.screen, _("lua scripts will not run the next time darktable is started")) end } @@ -1414,7 +1403,7 @@ end local page_back = "<" local page_forward = ">" -sm.widgets.page_status = dt.new_widget("label"){label = _("Page:")} +sm.widgets.page_status = dt.new_widget("label"){label = _("page:")} sm.widgets.page_back = dt.new_widget("button"){ label = page_back, @@ -1445,7 +1434,7 @@ sm.widgets.scripts = dt.new_widget("box"){ orientation = vertical, dt.new_widget("section_label"){label = _(" ")}, dt.new_widget("label"){label = " "}, - dt.new_widget("label"){label = _("Scripts")}, + dt.new_widget("label"){label = _("scripts")}, sm.widgets.folder_selector, sm.widgets.page_control, table.unpack(sm.widgets.boxes), @@ -1529,7 +1518,7 @@ else function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() - end + end end ) sm.event_registered = true