濫情▎り

文章 评论 浏览 29

濫情▎り 2025-02-15 18:10:56

卸载当前版本的PYYAML:

pip uninstall PyYaml

并安装所需的版本3.12:

pip install -U PyYaml==3.12

自Python3.3以来,Hashable被移至Collections.ABC模块,因此您可以通过在顶部添加以下几行来强制兼容性,以便强制兼容性。

import collections.abc
collections.Hashable = collections.abc.Hashable

uninstall the current version of PyYAML:

pip uninstall PyYaml

and install the required version 3.12:

pip install -U PyYaml==3.12

Since Python3.3, Hashable was moved to the collections.abc module, so you can force compatibility, as a workaround, by adding the following lines at top:

import collections.abc
collections.Hashable = collections.abc.Hashable

Chatterbot模块错误('AttributeError:Module' Collections'没有属性' hashable;

濫情▎り 2025-02-15 15:08:12

只需安装此功能,一切都可以正常工作。

!wget 'http://storage.googleapis.com/tensorflow-serving-apt/pool/tensorflow-model-server-universal-2.8.0/t/tensorflow-model-server-universal/tensorflow-model-server-universal_2.8.0_all.deb'
!dpkg -i tensorflow-model-server-universal_2.8.0_all.deb

Just install this and everything will work ok .

!wget 'http://storage.googleapis.com/tensorflow-serving-apt/pool/tensorflow-model-server-universal-2.8.0/t/tensorflow-model-server-universal/tensorflow-model-server-universal_2.8.0_all.deb'
!dpkg -i tensorflow-model-server-universal_2.8.0_all.deb

在使用TensorFlow Model Server时,我会遇到此错误:版本`glibc_2.28'未找到

濫情▎り 2025-02-15 08:12:32

我认为@bgporter在正确的轨道上,但是缺少语法可执行性,以下模式有助于完成:

from abc import abstractmethod
from typing import final

class Parent:

    def __init__(self):
        self.value = 1

    def before_start(self):
        self.value += 1
    
    @abstractmethod
    def on_start(self):
        ...

    def after_start(self):
        pass

    @final
    def start(self):
        self.before_start()
        self.on_start()
        self.after_start()


class Child(Parent): 
    """
    mypy, pylance and and pycharm will warn about 
    unimplemented abstract method if on_start is missing.
    Child can now override before_start and after_start behaviors, but they cannot override the start method. 
    This pattern is often seen in state machines so perhaps that's what you are after. 
    """ 
    def on_start(self):
        self.value += 1


child = Child()
child.start()
print(child.value) # prints 3

I think @bgporter was on the right track, but it is missing syntax enforceability which the following pattern helps accomplish:

from abc import abstractmethod
from typing import final

class Parent:

    def __init__(self):
        self.value = 1

    def before_start(self):
        self.value += 1
    
    @abstractmethod
    def on_start(self):
        ...

    def after_start(self):
        pass

    @final
    def start(self):
        self.before_start()
        self.on_start()
        self.after_start()


class Child(Parent): 
    """
    mypy, pylance and and pycharm will warn about 
    unimplemented abstract method if on_start is missing.
    Child can now override before_start and after_start behaviors, but they cannot override the start method. 
    This pattern is often seen in state machines so perhaps that's what you are after. 
    """ 
    def on_start(self):
        self.value += 1


child = Child()
child.start()
print(child.value) # prints 3

强迫儿童课程覆盖父级的方法

濫情▎り 2025-02-14 18:26:08

attributeError 是由于 dataframe.tolist()而引起的。看来代码假设 df(data ['审核']) series ,但实际上是 dataframe

df = DataFrame(data['Review'])
translated_reviews = sep.join(df[0].tolist()).translate(mapping_table).split(sep)

目前尚不清楚 data 是否是 dataframe 。如果是这样,只需在 join()中使用它,而无需调用 tolist()或实例化新的 dataframe

translated_reviews = sep.join(data['Review']).translate(mapping_table).split(sep)

The AttributeError is caused because DataFrame.tolist() doesn't exist. It looks like the code assumes that df(data['Review']) is a Series, but it is actually a DataFrame.

df = DataFrame(data['Review'])
translated_reviews = sep.join(df[0].tolist()).translate(mapping_table).split(sep)

It's unclear whether data is a DataFrame. If it is, just use it in the join() without calling tolist() or instantiating a new DataFrame.

translated_reviews = sep.join(data['Review']).translate(mapping_table).split(sep)

如何正确使用.translate()以删除非字母顺序的两个数值字符?

濫情▎り 2025-02-14 16:05:06

这里的答案是有关等待/异步的一般指导。它们还包含一些有关如何等待/异步有线的细节。我想与您分享一些实用经验,在使用这种设计模式之前,您应该知道。

“等待”一词是字面意思,因此无论您称之为什么线程,都将等待该方法的结果。在前景线上,这是 灾难 。前景线程承担构建应用程序的负担,包括视图,查看模型,初始动画以及其他与这些元素启动的其他内容。因此,当您等待前景线程时,您 停止 该应用程序。用户等待并等待什么都没有发生。这提供了负面的用户体验。

您当然可以使用各种方式等待背景线程:

Device.BeginInvokeOnMainThread(async () => { await AnyAwaitableMethod(); });

// Notice that we do not await the following call, 
// as that would tie it to the foreground thread.
try
{
Task.Run(async () => { await AnyAwaitableMethod(); });
}
catch
{}

这些备注的完整代码位于。请参阅称为agatyncantipattern.sln的解决方案。

GitHub网站还提供了有关此主题更详细讨论的链接。

The answers here are useful as a general guidance about await/async. They also contain some detail about how await/async is wired. I would like to share some practical experience with you that you should know before using this design pattern.

The term "await" is literal, so whatever thread you call it on will wait for the result of the method before continuing. On the foreground thread, this is a disaster. The foreground thread carries the burden of constructing your app, including views, view models, initial animations, and whatever else you have boot-strapped with those elements. So when you await the foreground thread, you stop the app. The user waits and waits when nothing appears to happen. This provides a negative user experience.

You can certainly await a background thread using a variety of means:

Device.BeginInvokeOnMainThread(async () => { await AnyAwaitableMethod(); });

// Notice that we do not await the following call, 
// as that would tie it to the foreground thread.
try
{
Task.Run(async () => { await AnyAwaitableMethod(); });
}
catch
{}

The complete code for these remarks is at https://github.com/marcusts/xamarin-forms-annoyances. See the solution called AwaitAsyncAntipattern.sln.

The GitHub site also provides links to a more detailed discussion on this topic.

如何以及何时使用‘ async’和‘等待’

濫情▎り 2025-02-14 13:55:21

您可以在所有子女上递归循环,并获取 与目标键匹配的键,如果他们的任何祖先都匹配了一个目标键。

const data = [
  {
    title: "0-0",
    key: "0-0",
    children: [
      {
        title: "0-0-0",
        key: "0-0-0",
        children: [
          { title: "0-0-0-0", key: "0-0-0-0" },
          { title: "0-0-0-1", key: "0-0-0-1" },
          { title: "0-0-0-2", key: "0-0-0-2" },
        ],
      },
      {
        title: "0-0-1",
        key: "0-0-1",
        children: [
          { title: "0-0-1-0", key: "0-0-1-0" },
          { title: "0-0-1-1", key: "0-0-1-1" },
          { title: "0-0-1-2", key: "0-0-1-2" },
        ],
      },
      {
        title: "0-0-2",
        key: "0-0-2",
      },
    ],
  },
  {
    title: "0-1",
    key: "0-1",
    children: [
      { title: "0-1-0-0", key: "0-1-0-0" },
      { title: "0-1-0-1", key: "0-1-0-1" },
      { title: "0-1-0-2", key: "0-1-0-2" },
    ],
  },
  {
    title: "0-2",
    key: "0-2",
  },
];

function getKeys(data, targetKeys) {
  const targetKeysSet = new Set(targetKeys);
  const outputKeys = [];
  function getKeysHelper(data, hasParentMatched = false) {
    data?.forEach((d) => {
      if (targetKeysSet.has(d.key) || hasParentMatched) {
        outputKeys.push(d.key);
        getKeysHelper(d.children, true);
      } else {
        getKeysHelper(d.children);
      }
    });
  }
  getKeysHelper(data);
  return outputKeys;
}

getKeys(data, ["0-0-0"]);

相关文档:

You can recursively loop over all the children and get the keys that either match one of the target keys or if any of their ancestors have matched one the target keys.

const data = [
  {
    title: "0-0",
    key: "0-0",
    children: [
      {
        title: "0-0-0",
        key: "0-0-0",
        children: [
          { title: "0-0-0-0", key: "0-0-0-0" },
          { title: "0-0-0-1", key: "0-0-0-1" },
          { title: "0-0-0-2", key: "0-0-0-2" },
        ],
      },
      {
        title: "0-0-1",
        key: "0-0-1",
        children: [
          { title: "0-0-1-0", key: "0-0-1-0" },
          { title: "0-0-1-1", key: "0-0-1-1" },
          { title: "0-0-1-2", key: "0-0-1-2" },
        ],
      },
      {
        title: "0-0-2",
        key: "0-0-2",
      },
    ],
  },
  {
    title: "0-1",
    key: "0-1",
    children: [
      { title: "0-1-0-0", key: "0-1-0-0" },
      { title: "0-1-0-1", key: "0-1-0-1" },
      { title: "0-1-0-2", key: "0-1-0-2" },
    ],
  },
  {
    title: "0-2",
    key: "0-2",
  },
];

function getKeys(data, targetKeys) {
  const targetKeysSet = new Set(targetKeys);
  const outputKeys = [];
  function getKeysHelper(data, hasParentMatched = false) {
    data?.forEach((d) => {
      if (targetKeysSet.has(d.key) || hasParentMatched) {
        outputKeys.push(d.key);
        getKeysHelper(d.children, true);
      } else {
        getKeysHelper(d.children);
      }
    });
  }
  getKeysHelper(data);
  return outputKeys;
}

getKeys(data, ["0-0-0"]);

Relevant documentations:

在深嵌套阵列对象中通过特定键查找所有儿童的键

濫情▎り 2025-02-14 10:34:07

<代码>虽然:循环永远运行,直到明确迫使循环结束为止。 可以使用 break 语句来完成。

例如,

def spell_count():
    for key, value in dnd_attributes.CharSpells.items():
        print(key, sep='\n')
    new_spell_dict = dict((k.lower(), v) for k, v in dnd_attributes.CharSpells.items())
    while True:
        spell_input = input("Which spell would you like to use? Would you like to see the Values? Or would you like "
                            "to reset/go back? ").lower()
        if spell_input in new_spell_dict:
            print(new_spell_dict[spell_input])
            if new_spell_dict[spell_input] == 0:
                print("Out of spells for this level")
                break    # here
            else:
                new_spell_dict[spell_input] -= 1
                print(new_spell_dict[spell_input])
        elif spell_input == 'values':
            for key, value in new_spell_dict.items():
                print(key + ': ', value)
        elif spell_input == 'reset':
            new_spell_dict = dict((k.lower(), v) for k, v in dnd_attributes.CharSpells.items())
        elif spell_input == 'back':
            print("Front Page!!")
            break  # here
        else:
            break


spell_count()

A while True: loop runs forever until you explicitly force the loop to end. This can be done with break statements

For example.

def spell_count():
    for key, value in dnd_attributes.CharSpells.items():
        print(key, sep='\n')
    new_spell_dict = dict((k.lower(), v) for k, v in dnd_attributes.CharSpells.items())
    while True:
        spell_input = input("Which spell would you like to use? Would you like to see the Values? Or would you like "
                            "to reset/go back? ").lower()
        if spell_input in new_spell_dict:
            print(new_spell_dict[spell_input])
            if new_spell_dict[spell_input] == 0:
                print("Out of spells for this level")
                break    # here
            else:
                new_spell_dict[spell_input] -= 1
                print(new_spell_dict[spell_input])
        elif spell_input == 'values':
            for key, value in new_spell_dict.items():
                print(key + ': ', value)
        elif spell_input == 'reset':
            new_spell_dict = dict((k.lower(), v) for k, v in dnd_attributes.CharSpells.items())
        elif spell_input == 'back':
            print("Front Page!!")
            break  # here
        else:
            break


spell_count()

除非输入两次,否则无法脱离时循环

濫情▎り 2025-02-14 05:25:54

我也有503错误,
原来是API网关超时问题。

I got the 503 error as well,
turns out to be the Api Gateway timeout problem.

enter image description here

AWS Lambda:503服务不可用

濫情▎り 2025-02-14 03:01:44

以这种方式尝试循环:

for (var i = 0; i < ar.length; i++) {
  result += "<tr>";
  for (var j = 0; j < ar[i].length; j++) {
    result += (j === 4 && ar[i][j] != '') ? "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'><a href='" + ar[i][j] + "' target='_blank'>Link</a>" : "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'>" + ar[i][j] + "</td>";
    result += (j === 8 && ar[i][j] == true) ? "<td><input type='checkbox' name='checkboxrow1' value=" + ar[i][j] + " checked='checked'/></td>" : "<td><input type='checkbox' name='checkboxrow1' value='false' checked='unchecked'/></td>";
  }
  result += "</tr>";
}

我尚未对此进行测试:

function loadClientTasks(client) {
  google.script.run.withSuccessHandler(function(ar) {
    if (ar == 'No tasks were found') {
      var div = document.getElementById('search-results');
      div.innerHTML = "There are no tasks for this client yet!";
      return;
    }
    if (ar && ar.length) {
      var result = "<div class='card'><table class='table table-borderless table-hover' id='dtable'>" +
        "<thead style='white-space: nowrap'>" + "<tr>" + "<th style='width: 4%' class='text-center'>Client ID</th>" + "<th style='width: 4%' class='text-center'>Task No</th>" + "<th style='width: 25%' class='text-center'>Task</th>" + "<th style='width: 4%' class='text-center'>Date Assigned</th>" + "<th style='width: 3%' class='text-center'>Link To File</th>" + "<th style='width: 17%' class='text-center'>Notes</th>" + "<th style='width: 12%' class='text-center'>Approval</th>" + "<th style='width: 24%' class='text-center'>Comments</th>" + "<th style='width: 24%' class='text-center'>Request Approval</th>" + "</tr>" + "</thead>" + "<tbody>";
      for (var i = 0; i < ar.length; i++) {
        result += "<tr>";
        for (var j = 0; j < ar[i].length; j++) { 
          result += (j === 4 && ar[i][j] != '') ?  "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'><a href='" + ar[i][j] + "' target='_blank'>Link</a>" : "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'>" + ar[i][j] + "</td>";

         result += (j === 8 && ar[i][j] == true )? "<td><input type='checkbox' name='checkboxrow1' value=" + ar[i][j] + " checked='checked'/></td>" : "<td><input type='checkbox' name='checkboxrow1' value='false' checked='unchecked'/></td>" //This is where I think is not right.
        }
        result += "</tr>";
      }
      result += "</tbody></table></div><br>";
      var div = document.getElementById('search-results');
      div.innerHTML = result;
      showAddTaskBtn();//Presumably this is another client side function
    } else {
      var div = document.getElementById('search-results');
      div.innerHTML = "There are no tasks for this client.";
      return;
    }
  }).getClientTasks(client);
}

Try the loop this way:

for (var i = 0; i < ar.length; i++) {
  result += "<tr>";
  for (var j = 0; j < ar[i].length; j++) {
    result += (j === 4 && ar[i][j] != '') ? "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'><a href='" + ar[i][j] + "' target='_blank'>Link</a>" : "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'>" + ar[i][j] + "</td>";
    result += (j === 8 && ar[i][j] == true) ? "<td><input type='checkbox' name='checkboxrow1' value=" + ar[i][j] + " checked='checked'/></td>" : "<td><input type='checkbox' name='checkboxrow1' value='false' checked='unchecked'/></td>";
  }
  result += "</tr>";
}

I have not tested this:

function loadClientTasks(client) {
  google.script.run.withSuccessHandler(function(ar) {
    if (ar == 'No tasks were found') {
      var div = document.getElementById('search-results');
      div.innerHTML = "There are no tasks for this client yet!";
      return;
    }
    if (ar && ar.length) {
      var result = "<div class='card'><table class='table table-borderless table-hover' id='dtable'>" +
        "<thead style='white-space: nowrap'>" + "<tr>" + "<th style='width: 4%' class='text-center'>Client ID</th>" + "<th style='width: 4%' class='text-center'>Task No</th>" + "<th style='width: 25%' class='text-center'>Task</th>" + "<th style='width: 4%' class='text-center'>Date Assigned</th>" + "<th style='width: 3%' class='text-center'>Link To File</th>" + "<th style='width: 17%' class='text-center'>Notes</th>" + "<th style='width: 12%' class='text-center'>Approval</th>" + "<th style='width: 24%' class='text-center'>Comments</th>" + "<th style='width: 24%' class='text-center'>Request Approval</th>" + "</tr>" + "</thead>" + "<tbody>";
      for (var i = 0; i < ar.length; i++) {
        result += "<tr>";
        for (var j = 0; j < ar[i].length; j++) { 
          result += (j === 4 && ar[i][j] != '') ?  "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'><a href='" + ar[i][j] + "' target='_blank'>Link</a>" : "<td class='align-middle' style='word-wrap: break-word;max-width: 160px;text-align:center'>" + ar[i][j] + "</td>";

         result += (j === 8 && ar[i][j] == true )? "<td><input type='checkbox' name='checkboxrow1' value=" + ar[i][j] + " checked='checked'/></td>" : "<td><input type='checkbox' name='checkboxrow1' value='false' checked='unchecked'/></td>" //This is where I think is not right.
        }
        result += "</tr>";
      }
      result += "</tbody></table></div><br>";
      var div = document.getElementById('search-results');
      div.innerHTML = result;
      showAddTaskBtn();//Presumably this is another client side function
    } else {
      var div = document.getElementById('search-results');
      div.innerHTML = "There are no tasks for this client.";
      return;
    }
  }).getClientTasks(client);
}

为什么在构建此HTML表时,为什么在所有列中插入复选框?

濫情▎り 2025-02-13 12:11:16

您是否与HTML文件同一文件夹中有 Sketch.js

- main
  - libraries
    - p5 and stuff

  - page0
    - maybe assets
    - code
      - index.html
      - sketch.js ???

您也可以替换

  <script src="sketch.js" type="text/javascript"></script>

为:

  <script>
  function setup() {
    createCanvas(700, 700);
    noFill();
    console.log("Hello World!");
  }

  function draw() {
    ellipse(mouseX, mouseY, 40, 80);
  }
  </script>

您也可以将Sketch.js放入&lt; body&gt; 中,我认为这确实没有帮助,但这可能是Dunno。

要使P5.j在本地计算机上工作:

您应该有1个,(2,3)+文件:

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />
    <script src="sketch.js"></script>
  </head>
  <body>
  </body>
</html>

您也可以在自己的计算机上存储P5.js库,它只是JavaScript文件,但是我从 editor.p5js.org

sketch.js:

function setup(){
   // use p5.js stuff here
}
// use everything else here it's all a starting point!

style.css:

body {
    background-color: #111;
}

button {
    width: 100vw;
    height: 2px;
}

这是完全可选的,就像.js文件一样,您可以使用&lt; style&gt; &lt;/style&gt; 而不是。

将所有这些文件(当前)在一个文件夹中。只需打开 index.html 文件即可。

Do you have sketch.js in the same folder as your html file?

- main
  - libraries
    - p5 and stuff

  - page0
    - maybe assets
    - code
      - index.html
      - sketch.js ???

You could also replace

  <script src="sketch.js" type="text/javascript"></script>

with:

  <script>
  function setup() {
    createCanvas(700, 700);
    noFill();
    console.log("Hello World!");
  }

  function draw() {
    ellipse(mouseX, mouseY, 40, 80);
  }
  </script>

And also you might be able to put the sketch.js in <body>, I don't think that really helps, but it might, dunno.

To get p5.js working on your local computer:

You should have 1,(2,3)+ files:

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />
    <script src="sketch.js"></script>
  </head>
  <body>
  </body>
</html>

You can also store the p5.js library on your own computer, It's just a JavaScript file, but I copied this from editor.p5js.org.

sketch.js:

function setup(){
   // use p5.js stuff here
}
// use everything else here it's all a starting point!

style.css:

body {
    background-color: #111;
}

button {
    width: 100vw;
    height: 2px;
}

This is completely optional, just like .js file, you can use <style> </style> instead.

After you have all these files (currently) in a single folder. Just open the index.html file.

Visual Studio代码中的P5.js:Sketch.js“执行”

濫情▎り 2025-02-13 11:09:35

从个人经验来看,我已经使用VSTACK完成了此操作。

VStack{ 
    PinnedItems()
    LazyVStack {
        OtherItems()
    } 
}

然后固定的物品不会滚动,并永久连接到顶部。而且懒惰史塔克仍然可以滚动。

From personal experience, I have done this using a VStack.

VStack{ 
    PinnedItems()
    LazyVStack {
        OtherItems()
    } 
}

Then Pinned items will not scroll and are permanently attached to the top. And the lazyVStack will still be able to scroll underneath.

Swiftui LazyvStack带有固定的视图

濫情▎り 2025-02-13 08:30:18

这是做到这一点的正确方法:

import { Resolver, Mutation, Query, Args, Context, ID } from "@nestjs/graphql";

@Mutation(() => SuccessInfo, { name: "addSubCategory" })
addSub(
    @Args("id", { type: () => ID } ) id: string  // Notice it's string not String
) {
    console.log(id);
    return { status: true } // return anything here which matches the SuccessInfo type
}

Here is the correct way to do it:

import { Resolver, Mutation, Query, Args, Context, ID } from "@nestjs/graphql";

@Mutation(() => SuccessInfo, { name: "addSubCategory" })
addSub(
    @Args("id", { type: () => ID } ) id: string  // Notice it's string not String
) {
    console.log(id);
    return { status: true } // return anything here which matches the SuccessInfo type
}

如何在Nestjs&#x2B中定义ID类型; GraphQl突变args?

濫情▎り 2025-02-13 05:13:39

确实,在Photoshop中,活动听众并不明显。 Photoshop中听众的最佳方法可能是使用Notifier(S)事件处理程序对象。请参阅 photoshop javascript参考以获取更多有关使用信息的信息。

通常,您使用文件&gt;创建通知符;脚本&gt;脚本事件管理器,您可以在其中选择“关闭文档” Photoshop事件,然后在发生时选择脚本或操作。

但是,如果您要创建扩展名并需要通过代码执行此操作,那就有些棘手。最好的选择是为关闭事件创建一个通知符:

var scriptPath = "/c/scripts/server.jsx";

//note the trailing space in "Cls "
var closeEventNotifierRef = app.notifiers.add("Cls ", File(scriptPath)); 

添加该server.jsx文件中服务器需要发生的任何内容。请注意,只有在关闭文档后才调用该文件,因此我不确定仍然可以访问哪些信息。

还要注意,据我所知,添加通知器是持久的,这意味着每次都会每次都会发生密切的通知符和呼叫server.jsx。换句话说,一旦您的server.jsx脚本完成执行,将不会删除关闭事件通知器。

因此,您可能需要在服务器中添加逻辑。但是,这并不那么简单,因为您不再可以访问创建的Notifier参考(CloseEventNotifierRef)。我发现的唯一方法是循环浏览通知器:

var notifiersAll = app.notifiers;
var notifierRefs = [];

for (var i = 0; i < notifiersAll.length; i++){
    
    if  (notifiersAll[i].event == 'Cls ') {
        
        notifierRefs.push(notifiersAll[i]);
        
    }
    
}

for (var r = 0; r < notifierRefs.length; r++){
    
    notifierRefs[r].remove();
    
}

希望这会有所帮助。

Indeed, event listeners are not obvious in Photoshop. Probably the best approach for listeners in Photoshop is to make use of the Notifier(s) event-handler object. See the Photoshop Javascript Reference for more information on usage.

Typically, you create Notifiers using File > Scripts > Scripts Event Manager, where you can choose the "Close Document" Photoshop event and choose a script or an action to run when it happens.

But, if you are creating an extension and need to do this via code, it's a little trickier. Your best bet is to create a Notifier for the close event:

var scriptPath = "/c/scripts/server.jsx";

//note the trailing space in "Cls "
var closeEventNotifierRef = app.notifiers.add("Cls ", File(scriptPath)); 

Add whatever needs to happen with the server in that server.jsx file. Note that the file will only be called after the document is closed, so I am not sure what info will still be accessible.

Also note that, as far as I know, adding notifiers is persistent, meaning that close notifier and the calling of server.jsx will happen every time after. In other words, the close event notifier will not be deleted once your server.jsx script finishes executing.

Because of this, you may want to add logic inside your server.jsx file to take care of removing the close event notifier at the end. However, this is not as simple, since you no longer have access to the notifier reference created (closeEventNotifierRef). The only way I found was to loop through notifiers:

var notifiersAll = app.notifiers;
var notifierRefs = [];

for (var i = 0; i < notifiersAll.length; i++){
    
    if  (notifiersAll[i].event == 'Cls ') {
        
        notifierRefs.push(notifiersAll[i]);
        
    }
    
}

for (var r = 0; r < notifierRefs.length; r++){
    
    notifierRefs[r].remove();
    
}

Hope this helps.

如何使用CEP/JavaScript检测Photoshop文档的关闭?

濫情▎り 2025-02-13 03:55:58

将以下样式应用于元素

单词break:分解;

<div>
   <p style="word-break: break-all">
    {{text}}
   </p>
</div>

否则,您可以编写类添加使用,因为它也可能在其他地方需要。

Apply the following style to the element

word-break: break-all;

<div>
   <p style="word-break: break-all">
    {{text}}
   </p>
</div>

Or else you can write a class add use it since it may needed in other places also.

即使文本不适合

濫情▎り 2025-02-12 21:01:01

使用 thing [:]

>>> a = [1,2]
>>> b = a[:]
>>> a += [3]
>>> a
[1, 2, 3]
>>> b
[1, 2]
>>> 

Use thing[:]

>>> a = [1,2]
>>> b = a[:]
>>> a += [3]
>>> a
[1, 2, 3]
>>> b
[1, 2]
>>> 

我如何克隆列表,以免在分配后意外变化?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文