小编sto*_*hel的帖子

将 MetalView 与 SwiftUI 结合使用?我如何在那里放置一些东西来展示?

我一直坚持使用 SwiftUI 和 Metal,甚至快要放弃了。

我从https://developer.apple.com/forums/thread/119112?answerId=654964022#654964022得到了这个示例:

import MetalKit
struct MetalView: NSViewRepresentable {
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
    func makeNSView(context: NSViewRepresentableContext<MetalView>) -> MTKView {
        let mtkView = MTKView()
        mtkView.delegate = context.coordinator
        mtkView.preferredFramesPerSecond = 60
        mtkView.enableSetNeedsDisplay = true
        if let metalDevice = MTLCreateSystemDefaultDevice() {
            mtkView.device = metalDevice
        }
        mtkView.framebufferOnly = false
        mtkView.clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0)
        mtkView.drawableSize = mtkView.frame.size
        mtkView.enableSetNeedsDisplay = true
        return mtkView
    }
    func updateNSView(_ nsView: MTKView, context: NSViewRepresentableContext<MetalView>) {
    }
    class Coordinator …
Run Code Online (Sandbox Code Playgroud)

macos core-image swift metal swiftui

5
推荐指数
1
解决办法
3996
查看次数

Python:简化try/except代码?

对不起,如果标题不够清晰,但这是我能想到的最好的.这是我的代码的一部分,一个python脚本将文件从Xilog3转换为woodWOP格式(cnc程序).

try:
    print >>woodWOPfile, 'YA="%s"' %xbo['Y']
except KeyError:
    xbo['Y']=xbo_prev['Y']
    print >>woodWOPfile, 'YA="%s"' %xbo['Y']
Run Code Online (Sandbox Code Playgroud)

这会将字典键项打印到输出文件.如果密钥不存在,我想从先前版本的字典xbo_prev加载它,该字典在每个新的行读取周期之前从xbo复制.

使用两次打印规则似乎很愚蠢,但这是我能想到的最好的.有没有办法简化这个?

谢谢 :).

python cnc

1
推荐指数
1
解决办法
94
查看次数

标签 统计

cnc ×1

core-image ×1

macos ×1

metal ×1

python ×1

swift ×1

swiftui ×1