Displaying image information in file panel

You want to talk about Far Manager, but don't know where to turn?
User avatar
HaRT
Moderator
Posts: 10863
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Displaying image information in file panel

Post by HaRT »

Latest post of the previous page:

old_gregg wrote: Fri 07 Oct, 2022 00:08 Where do I find macroapi_manual.en.chm?
It's installed with FAR unless you excluded Documentation in the installer.
Фар есть инструмент, а не нянька. © 2009 DrKnS
User avatar
buniak_a_h
Posts: 4262
Joined: Sat 20 Apr, 2013 00:17
Location: Санкт-Петробад
Has thanked: 222 times
Been thanked: 644 times
Contact:

Displaying image information in file panel

Post by buniak_a_h »

old_gregg wrote: Fri 07 Oct, 2022 00:08 Where do I find…
%FarHome%\Encyclopedia, unless you excluded Documentation in the installer.
old_gregg
Posts: 46
Joined: Fri 01 May, 2015 16:04
Has thanked: 10 times
Been thanked: 1 time

Displaying image information in file panel

Post by old_gregg »

I included the documentation, but it's not in there:
Documentation.jpg
old_gregg
Posts: 46
Joined: Fri 01 May, 2015 16:04
Has thanked: 10 times
Been thanked: 1 time

Displaying image information in file panel

Post by old_gregg »

Oh, got it!
User avatar
buniak_a_h
Posts: 4262
Joined: Sat 20 Apr, 2013 00:17
Location: Санкт-Петробад
Has thanked: 222 times
Been thanked: 644 times
Contact:

Displaying image information in file panel

Post by buniak_a_h »

This script perform sorting by picture width and height:
  1. -- PictureSort.lua
  2.  
  3. local ffi = require"ffi"
  4.  
  5. local C = ffi.C
  6.  
  7. local wsize = ffi.sizeof"wchar_t"
  8.  
  9. local F = far.Flags
  10.  
  11. local U8 = win.Utf16ToUtf8
  12.  
  13. local function String(cStr)
  14.  
  15.   if tostring(cStr) == "cdata<const unsigned short *>: NULL" then return nil end
  16.  
  17.   return U8(ffi.string(cStr,C.wcslen(cStr)*wsize))
  18.  
  19. end
  20.  
  21. ------------------------------------------------
  22.  
  23. local FILE_ATTRIBUTE_DIRECTORY = 0x00000010
  24.  
  25. local MediaInfo_GUID = '919C1FC6-A571-4642-99DF-BDACE840ED18'
  26.  
  27. ------------------------------------------------
  28.  
  29. local aSortData = {w={}; h={}}
  30.  
  31. local function GetMedia(FName)
  32.  
  33.   local ok, n, _, Vals = Plugin.SyncCall(MediaInfo_GUID, FName,'{Width,Height}')
  34.  
  35.   if ok and n == 2 then
  36.  
  37.     return tonumber( (Vals[1]:gsub("%D",'')) ), tonumber( (Vals[2]:gsub("%D",'')) )
  38.  
  39.   end
  40.  
  41. end
  42.  
  43. local function InitSort(Options)
  44.  
  45.   aSortData = {w={}; h={}}
  46.  
  47.   for i=1,APanel.ItemCount do
  48.  
  49.     if band(Panel.Item(0,i,2), FILE_ATTRIBUTE_DIRECTORY) == 0 then
  50.  
  51.       local fn = Panel.Item(0,i,0)
  52.  
  53.       local w,h = GetMedia(fn)
  54.  
  55.       if w then aSortData.w[fn], aSortData.h[fn] = w,h end
  56.  
  57.     end
  58.  
  59.   end
  60.  
  61. end
  62.  
  63. local function Compare(sWH, Pi1, Pi2, Options) -- sWH = 'w' or 'h'
  64.  
  65.   local function Sign(arg) return arg < 0 and -1 or (arg > 0 and 1 or 0) end
  66.  
  67.   local Fn1, Fn2 = String(Pi1.FileName), String(Pi2.FileName)
  68.  
  69.   return Sign( (aSortData[sWH][Fn1] or math.huge) - (aSortData[sWH][Fn2] or math.huge) )
  70.  
  71. end
  72.  
  73. --------------------------------------------------------------------
  74.  
  75. Panel.LoadCustomSortMode (F.SM_USER+100, nil)
  76.  
  77. Panel.LoadCustomSortMode (F.SM_USER+100, {
  78.  
  79.   InitSort = InitSort;
  80.  
  81.   Compare = function(...) return Compare('w', ...) end;
  82.  
  83.   Indicator = 'ŵŴ'; --'wW';
  84.  
  85.   Description = 'Picture width'; --'По ширине изображения';
  86.  
  87. })
  88.  
  89. --------------------------------------------------------------------
  90.  
  91. Panel.LoadCustomSortMode (F.SM_USER+101, nil)
  92.  
  93. Panel.LoadCustomSortMode (F.SM_USER+101, {
  94.  
  95.   InitSort = InitSort;
  96.  
  97.   Compare = function(...) return Compare('h', ...) end;
  98.  
  99.   Indicator = 'ĥĤ'; --'hH';
  100.  
  101.   Description = 'Picture height'; --'По высоте изображения';
  102.  
  103. })
Shmuel
Posts: 6836
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 530 times

Displaying image information in file panel

Post by Shmuel »

Probably if tostring(cStr) == "cdata<const unsigned short *>: NULL"
can be replaced by if cStr == nil
User avatar
buniak_a_h
Posts: 4262
Joined: Sat 20 Apr, 2013 00:17
Location: Санкт-Петробад
Has thanked: 222 times
Been thanked: 644 times
Contact:

Displaying image information in file panel

Post by buniak_a_h »

Shmuel,
Volodya
Posts: 268
Joined: Thu 31 Mar, 2005 19:41
Has thanked: 30 times

Displaying image information in file panel

Post by Volodya »

Is it possible to add this mode to the Left/Right (F9) and assign some letters? For example, Ctrl+S
Shmuel
Posts: 6836
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 530 times

Displaying image information in file panel

Post by Shmuel »

Volodya,
  1. It is already added ("Picture width" and "Picture height")
  2. Assigning a key shortcut is possible via a macro that calls Panel.SetCustomSortMode
User avatar
buniak_a_h
Posts: 4262
Joined: Sat 20 Apr, 2013 00:17
Location: Санкт-Петробад
Has thanked: 222 times
Been thanked: 644 times
Contact:

Displaying image information in file panel

Post by buniak_a_h »

Volodya wrote: Fri 07 Oct, 2022 17:47 Is it possible to add this mode to the Left/Right (F9) and assign some letters? For example, Ctrl+S
This small script shows menu for choice user defined view mode
  1. -- Shell.RCtrlF12.lua
  2.  
  3. package.nounload.ljsqlite3 = true
  4.  
  5. local sql = require "ljsqlite3"
  6.  
  7.  
  8.  
  9. Macro{
  10.  
  11.   id="B63AF65B-94DF-4808-903D-59D6CA16CC2D";
  12.  
  13.   area="Shell";
  14.  
  15.   key="RCtrlF12";
  16.  
  17.   description="Выбор режима просмотра из определённых пользователем";
  18.  
  19.   action=function(data)
  20.  
  21.    local fname = win.GetEnv("farprofile").."\\panelmodes.db"
  22.  
  23.    local conn = assert(sql.open(fname, "ro"))
  24.  
  25.    local tt =  conn:exec([[SELECT value FROM table_values WHERE key_id > 11 and name='Name']]) or {value={}}
  26.  
  27.    local n, iCh = #tt.value
  28.  
  29.    if n == 0 then iCh = 0
  30.  
  31.    elseif n == 1 then iCh = 1
  32.  
  33.    else
  34.  
  35.     local curr = panel.GetPanelInfo(nil,1).ViewMode
  36.  
  37.     if curr >= 10 then curr = curr-9 else curr = 0 end
  38.  
  39.     iCh = Menu.Show(table.concat(tt.value,'\n'),nil,0x8, curr) end
  40.  
  41.    if iCh > 0 then
  42.  
  43.     panel.SetViewMode(nil,1,iCh+9)
  44.  
  45.    end
  46.  
  47.   end;
  48.  
  49. }
Last edited by buniak_a_h on Sat 08 Oct, 2022 01:32, edited 1 time in total.
Post Reply

Return to “General Discussions”