Skip to content

Commit

Permalink
Merge pull request #2413 from CommandPost/issue/2411-resolve-api
Browse files Browse the repository at this point in the history
Initial update of Resolve API
  • Loading branch information
latenitefilms committed Aug 17, 2020
2 parents a19f8cc + f6a54e7 commit db927ba
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 172 deletions.
54 changes: 21 additions & 33 deletions src/extensions/cp/blackmagic/resolve/color/Color.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--- === cp.blackmagic.resolve.Color ===
--- === cp.blackmagic.resolve.color.Color ===
---
--- Color Module.

Expand All @@ -7,17 +7,17 @@ local require = require
--local log = require "hs.logger".new "Color"

local axutils = require "cp.ui.axutils"
local Element = require "cp.ui.Element"
local CheckBox = require "cp.ui.CheckBox"
local Group = require "cp.ui.Group"

local Tracker = require("cp.blackmagic.resolve.color.Tracker")
local Tracker = require "cp.blackmagic.resolve.color.Tracker"

local childrenWithRole = axutils.childrenWithRole
local childWithDescription = axutils.childWithDescription
local childMatching = axutils.childMatching

local Color = Element:subclass "cp.blackmagic.resolve.Color"
local Color = Group:subclass("cp.blackmagic.resolve.color.Color")

--- cp.apple.finalcutpro.main.Color(app) -> Color
Color.static.DESCRIPTION = "Color"

--- cp.blackmagic.resolve.color.Color(app) -> Color
--- Constructor
--- Creates a new `Color` instance.
---
Expand All @@ -26,43 +26,31 @@ local Color = Element:subclass "cp.blackmagic.resolve.Color"
---
--- Returns:
--- * The new `Color`.
function Color:initialize(app)
self._app = app
end

--- cp.blackmagic.resolve.main.Color:app() -> cp.blackmagic.resolve
--- Method
--- Returns the application object.
---
--- Parameters:
--- * None
---
--- Returns:
--- * The app instance.
function Color:app()
return self._app
function Color:initialize(primaryWindow)
local UI = primaryWindow.UI:mutate(function(original)
if self:isShowing() then
return childMatching(original(), Group.matches)
end
end)
Group.initialize(self, primaryWindow, UI)
end

function Color.lazy.method:checkBox()
return CheckBox(self, function()
local primaryWindow = self:app():primaryWindow():UI()
local children = primaryWindow and childrenWithRole(primaryWindow, "AXCheckBox")
return childWithDescription(children, "Color")
end)
function Color.lazy.value:active()
return self:parent().colorActive
end

function Color:isShowing()
return self:checkBox():checked() or false
function Color.lazy.prop:isShowing()
return self.active.checked
end

function Color:show()
if not self:isShowing() then
self:checkBox():click()
self.active:click()
end
return self
end

function Color:tracker()
function Color.lazy.value:tracker()
return Tracker(self)
end

Expand Down
102 changes: 41 additions & 61 deletions src/extensions/cp/blackmagic/resolve/color/Tracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,28 @@ local require = require

local axutils = require "cp.ui.axutils"
local CheckBox = require "cp.ui.CheckBox"
local Element = require "cp.ui.Element"
local Group = require "cp.ui.Group"
local MenuButton = require "cp.ui.MenuButton"
local StaticText = require "cp.ui.StaticText"

local childrenWithRole = axutils.childrenWithRole
local cache = axutils.cache
local childFromTop = axutils.childFromTop
local childMatching = axutils.childMatching
local childrenMatching = axutils.childrenMatching
local childWithDescription = axutils.childWithDescription
local childWithTitle = axutils.childWithTitle

local Tracker = Element:subclass "cp.blackmagic.resolve.color.Tracker"
local Tracker = Group:subclass("cp.blackmagic.resolve.color.Tracker")

Tracker.static.TITLE = "Tracker"

function Tracker.static.matches(element)
if Group.matches(element) then
local title = childFromTop(element, 1, StaticText.matches)
return title and title:attributeValue("AXTitle") == Tracker.TITLE
end
return false
end

--- cp.apple.finalcutpro.main.Color(app) -> Color
--- Constructor
Expand All @@ -28,93 +41,60 @@ local Tracker = Element:subclass "cp.blackmagic.resolve.color.Tracker"
--- Returns:
--- * The new `Color`.
function Tracker:initialize(parent)
self._parent = parent
end

--- cp.blackmagic.resolve.color.Tracker:parent() -> parent
--- Method
--- Returns the parent object.
---
--- Parameters:
--- * None
---
--- Returns:
--- * The parent object.
function Tracker:parent()
return self._parent
end

function Tracker:app()
return self:parent():app()
local UI = parent.UI:mutate(function(original)
return cache(self, "_ui", function()
return childMatching(original(), Tracker.matches)
end)
end)
Group.initialize(self, parent, UI)
end

function Tracker.lazy.method:checkBox()
function Tracker.lazy.value:active()
return CheckBox(self, function()
local primaryWindow = self:app():primaryWindow():UI()
local group = childrenWithRole(primaryWindow, "AXGroup")
local children = group and group[1] childrenWithRole(group[1], "AXCheckBox")
return childWithDescription(children, "Tracker")
return childWithDescription(childrenMatching(self:parent():UI(), CheckBox.matches), Tracker.TITLE)
end)
end

function Tracker:isShowing()
return self:checkBox():checked() or false
end

function Tracker:show()
if not self:isShowing() then
self:checkBox():click()
self.active:checked(true)
end
return self
end

function Tracker.lazy.method:group()
return Group(self, function()
local primaryWindow = self:app():primaryWindow():UI()
local group = childrenWithRole(primaryWindow, "AXGroup")
local groups = group and group[1] and childrenWithRole(group[1], "AXGroup")
for _, child in pairs(groups) do
local staticText = childrenWithRole(child, "AXStaticText")
if staticText and staticText[1] and staticText[1]:attributeValue("AXTitle") == "Tracker" then
return child
end
end
end)
end

function Tracker.lazy.method:pan()
function Tracker.lazy.value:pan()
return CheckBox(self, function()
local groupUI = self:group():UI()
return groupUI and childWithTitle(groupUI, "Pan")
local ui = self:UI()
return ui and childWithTitle(ui, "Pan")
end)
end

function Tracker.lazy.method:tilt()
function Tracker.lazy.value:tilt()
return CheckBox(self, function()
local groupUI = self:group():UI()
return groupUI and childWithTitle(groupUI, "Tilt")
local ui = self:UI()
return ui and childWithTitle(ui, "Tilt")
end)
end

function Tracker.lazy.method:zoom()
function Tracker.lazy.value:zoom()
return CheckBox(self, function()
local groupUI = self:group():UI()
return groupUI and childWithTitle(groupUI, "Zoom")
local ui = self:UI()
return ui and childWithTitle(ui, "Zoom")
end)
end

function Tracker.lazy.method:perspective3D()
function Tracker.lazy.value:perspective3D()
return CheckBox(self, function()
local groupUI = self:group():UI()
return groupUI and childWithTitle(groupUI, "Perspective 3D")
local ui = self:UI()
return ui and childWithTitle(ui, "Perspective 3D")
end)
end

function Tracker.lazy.method:menuButton()
function Tracker.lazy.value:menuButton()
return MenuButton(self, function()
local groupUI = self:group():UI()
local menus = childrenWithRole(groupUI, "AXMenuButton")
return groupUI and childWithTitle(menus, "")
local ui = self:UI()
local menus = childrenMatching(ui, MenuButton.matches)
return ui and childWithTitle(menus, "")
end)
end

Expand Down
14 changes: 4 additions & 10 deletions src/extensions/cp/blackmagic/resolve/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,10 @@ end
--
----------------------------------------------------------------------------------------

--- cp.blackmagic.resolve:primaryWindow() -> primaryWindow object
--- Method
--- Returns the DaVinci Resolve Primary Window.
---
--- Parameters:
--- * None
---
--- Returns:
--- * The Primary Window
function resolve.lazy.method:primaryWindow()
--- cp.blackmagic.resolve.primaryWindow <PrimaryWindow>
--- Field
--- The DaVinci Resolve Primary Window.
function resolve.lazy.value:primaryWindow()
return PrimaryWindow(self)
end

Expand Down

0 comments on commit db927ba

Please sign in to comment.