wxPython + multiprocessing:检查颜色字符串是否合法

时间:2022-07-29 07:13:41

I have a wxPython program with two processes: A primary and a secondary one (I'm using the multiprocessing module.) The primary one runs the wxPython GUI, the secondary one does not. However, there is something I would like to do from the secondary process: Given a string that describes a color, to check whether this would be legitimate color for wxPython. That means, whether I can create a wx.Pen(color_string) or not.

我有一个带有两个进程的wxPython程序:一个主进程和一个进程(我正在使用多处理模块。)主要运行wxPython GUI,而辅助运行没有。但是,我想从辅助过程中做一些事情:给定一个描述颜色的字符串,检查这是否是wxPython的合法颜色。这意味着,我是否可以创建一个wx.Pen(color_string)。

How do I do this?

我该怎么做呢?

(I tried making a wx.Pen and comparing its color to the null color, but that required to create a wx.App in the second process, and when I did create one the program raised an error in some special wxPython window.)

(我尝试制作一个wx.Pen并将其颜色与空颜色进行比较,但是需要在第二个进程中创建一个wx.App,当我创建一个时,程序在一些特殊的wxPython窗口中引发了一个错误。)

1 个解决方案

#1


You could make two Queues between the two processes and have the second one delegate wx-related functionality to the first one (by pushing on the first queue the parameters of the task to perform, and waiting for the result on the second one).

您可以在两个进程之间创建两个队列,并让第二个队列将与wx相关的功能委派给第一个队列(通过在第一个队列中按下要执行的任务的参数,并在第二个队列上等待结果)。

#1


You could make two Queues between the two processes and have the second one delegate wx-related functionality to the first one (by pushing on the first queue the parameters of the task to perform, and waiting for the result on the second one).

您可以在两个进程之间创建两个队列,并让第二个队列将与wx相关的功能委派给第一个队列(通过在第一个队列中按下要执行的任务的参数,并在第二个队列上等待结果)。