登录 用户中心() [退出] 后台管理 注册
   
您的位置: 首页 >> CLQ工作室开源代码 >> 主题: [macos/cocoa]原来 python 也可以直接操作 mac 的原始接口 - 参考对比 lazarus 中的实现     [回主站]     [分站链接]
标题
[macos/cocoa]原来 python 也可以直接操作 mac 的原始接口 - 参考对比 lazarus 中的实现
clq
浏览(130) + 2023-09-23 14:10:23 发表 编辑

关键字:

[2023-09-23 14:40:13 最后更新]
[macos/cocoa]原来 python 也可以直接操作 mac 的原始接口 - 参考对比 lazarus 中的实现

--------------------------------------------------------
它们用到的库为 Cocoa ,理论上这个 objectc 的库是可以在 golang 中调用的。参考
https://www.oomake.com/question/1603946
https://github.com/alediaferia/gogoa

ios 用的并不是这个库,不过现在似乎是可以混用 ios 的库用来开发 macos 程序的。

--------------------------------------------------------

研究 lazarus 的 macos 版本源码时意外知道 python 也是可以直接操作 macos 的原始 api 的。

以关键字 "NSRunAlertPanel" 搜索得到以下文章。

https://vimsky.com/examples/detail/python-ex-AppKit-NSApp-runModalForWindow_-method.html

--------------------------------------------------------
Python NSApp.runModalForWindow_方法代码示例

本文整理汇总了Python中AppKit.NSApp.runModalForWindow_方法的典型用法代码示例。如果您正苦于以下问题:Python NSApp.runModalForWindow_方法的具体用法?Python NSApp.runModalForWindow_怎么用?Python NSApp.runModalForWindow_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSApp的用法示例。

在下文中一共展示了NSApp.runModalForWindow_方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: runModal

# 需要导入模块: from AppKit import NSApp [as 别名]
# 或者: from AppKit.NSApp import runModalForWindow_ [as 别名]
def runModal(self):
BlinkLogger().log_info('Starting Enrollment')
self.newDisplayNameText.setStringValue_(NSFullUserName() or "")
self.displayNameText.setStringValue_(NSFullUserName() or "")

self.window.center()
NSApp.runModalForWindow_(self.window)
self.window.orderOut_(self)

开发者ID:bitsworking,项目名称:blink-cocoa,代码行数:10,代码来源:EnrollmentController.py
--------------------------------------------------------

lazarus 的版本在
https://wiki.lazarus.freepascal.org/Using_macOS_Alert_Panels

Example code

The example code below creates an alert panel with three buttons: Cancel, Abort and OK (Tested working on Mojave, Catalina and Big Sur). Cancel returns 0; Abort returns -1 and OK returns 1. The status is displayed in the TForms's caption property.

unit unit1;

{$modeswitch objectivec1}

interface

uses
...
MacOSAll, CocoaAll, LCLType,
...
;

type

{ TForm1 }

TForm1 = class(TForm)
...

private

public

end;

var
Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

...

function ShowAlertPanel(const alertTitle, alertMessage, defButton, altButton, othButton: String) :Integer;
var
tNSStr, mNSStr, defButNSStr, altButNSStr, othButNSStr: NSString;
begin
tNSStr := NSString(CFStringCreateWithPascalString(kCFAllocatorDefault, alertTitle, kCFStringEncodingUTF8));
mNSStr := NSString(CFStringCreateWithPascalString(kCFAllocatorDefault, alertMessage, kCFStringEncodingUTF8));
defButNSStr := NSString(CFStringCreateWithPascalString(kCFAllocatorDefault, defButton, kCFStringEncodingUTF8));
altButNSStr := NSString(CFStringCreateWithPascalString(kCFAllocatorDefault, altButton, kCFStringEncodingUTF8));
othButNSStr := NSString(CFStringCreateWithPascalString(kCFAllocatorDefault, othButton, kCFStringEncodingUTF8));
Result := NSRunAlertPanel(tNSStr, mNSStr, defButNSStr, altButNSStr, othButNSStr);
end;

...

You can replace NSRunAlertPanel() with NSRunInformationalAlertPanel() or NSRunCriticalAlertPanel() which have different visual attributes. In particular, when using NSRunCriticalAlertPanel(), the panel presented to the user is badged with a caution icon. Critical alerts should be used only as specified in the "Alerts" section of the UI Element Guidelines Windows chapter of macOS Human Interface Guidelines.

To call the ShowAlertPanel function from, for example, a menu item:

procedure TForm1.MenuItem1Click(Sender: TObject);
var
status: Integer;
begin
status := ShowAlertPanel('Title', 'Message text', 'OK', 'Cancel', 'Abort');
Caption := 'Status: ' + IntToStr(status);
end;

--------------------------------------------------------
按理说它们调用的应该是动态库,不过从源码似乎是用的原始 c/objectc 接口。改天再研究。


--------------------------------------------------------
这是一个通过 cgo 在 golang 中直接操作 cocoa 的方法。

https://github.com/alediaferia/gogoa/blob/master/application.go

package gogoa

// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
//#include "g_application.h"
import "C"
import "unsafe"


type Application struct {
ptr unsafe.Pointer
}

func SharedApplication() (*Application) {
app := new(Application)
app.ptr = C.SharedApplication()

return app
}

func (this *Application) Run() {
C.Run(this.ptr)
}






总数:0 页次:1/0 首页 尾页  
总数:0 页次:1/0 首页 尾页  


所在合集/目录
cocoa 更多



发表评论:
文本/html模式切换 插入图片 文本/html模式切换


附件:



NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.

Copyright © 2005-2020 clq, All Rights Reserved
版权所有
桂ICP备15002303号-1