Ironpython Studio 形式

发布于 2024-07-09 20:36:42 字数 703 浏览 7 评论 0原文

这是一个由两部分组成的问题。 一个愚蠢的技术问题和一个更广泛的问题,关于我学习用我不熟悉的语言做一些事情的可能错误的方法。

我只是在使用一些 Python GUI 库(主要是 wxPython 和 IronPython)来完成我想要在开源应用程序上做的一些工作,只是为了提高我的技能等等。

白天,我是一个非常标准的 C# 开发者,使用一套非常普通的基于 MS 的工具,并且我正在研究 Python 来给我一个新的视角。 因此,使用 Ironpython Studio 可能有点作弊(好吧,很多)。 这似乎并不重要,因为无论它多么试图看起来像一个 Visual Studio 项目等。有一个简单的行为我可能太笨而无法实现。

IE 如何将我的表单保存在漂亮的单独代码文件中,就像我一直以来的 c# 猴子一样,但又可以相互调用它们? 我尝试将要调用的表单导入到主表单中,但我似乎无法将表单识别为对象以外的任何内容。 新表单似乎是其自己的代码文件中的表单对象,我正在导入 clr. 我正在尝试调用表单的“显示”方法。 这不对吗?

我已经尝试了几种(在我看来不太可能)解决此问题的方法,但问题似乎很棘手。 这是我没有看到的东西,还是实际上对我来说更合适的是改变我对 GUI 脚本的思考方式以适应 Python(在这种情况下,我可能会切换回 wxPython,它似乎从 Pythonic 更容易接近)的观点)而不是尝试从 Visual Studio shell 的安全性来看待 Python?

This is a two part question. A dumb technical query and a broader query about my possibly faulty approach to learning to do some things in a language I'm new to.

I'm just playing around with a few Python GUI libraries (mostly wxPython and IronPython) for some work I'm thinking of doing on an open source app, just to improve my skills and so forth.

By day I am a pretty standard c# bod working with a pretty normal set of MS based tools and I am looking at Python to give me a new perspective. Thus using Ironpython Studio is probably cheating a bit (alright, a lot). This seems not to matter because however much it attempts to look like a Visual Studio project etc. There's one simple behaviour I'm probably being too dumb to implement.

I.E. How do I keep my forms in nice separate code files, like the c# monkey I have always been ,and yet invoke them from one another? I've tried importing the form to be invoked to the main form but I just can't seem to get the form to be recognized as anything other than an object. The new form appears to be a form object in its own code file, I am importing the clr. I am trying to invoke a form's 'Show' method. Is this not right?

I've tried a few (to my mind more unlikely) ways around this but the problem seems intractable. Is this something I'm just not seeing or would it in fact be more appropriate for me to change the way I think about my GUI scripting to fit round Python (in which case I may switch back to wxPython which seemed more approachable from a Pythonic point of view) rather than try to look at Python from the security of the Visual Studio shell?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℡Ms空城旧梦 2024-07-16 20:36:42

我对这个问题并不完全清楚。 当然,您可以在 IronPython 的一个模块中定义 System.Windows.Forms.Form 的子类,然后在其他模块中导入该表单子类:

# in form.py
from System.Windows.Forms import Form, Button, MessageBox
class TrivialForm(Form):
   def __init__(self):
       button = Button(Parent=self, Text='Click!')
       button.Click += self.show_message

   def show_message(self, sender, args):
       MessageBox.Show('Stop that!')

# in main.py
import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Application
from form import TrivialForm
if __name__ == '__main__':
   f = TrivialForm()
   Application.Run(f)

IronPython Studio 的表单设计器/代码生成器不会吗?不让你这样构造你的代码吗? (我从来没有用过它。)

I'm not totally clear on the problem. You can certainly define a subclass of System.Windows.Forms.Form in IronPython in one module, and then import the form subclass in some other module:

# in form.py
from System.Windows.Forms import Form, Button, MessageBox
class TrivialForm(Form):
   def __init__(self):
       button = Button(Parent=self, Text='Click!')
       button.Click += self.show_message

   def show_message(self, sender, args):
       MessageBox.Show('Stop that!')

# in main.py
import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Application
from form import TrivialForm
if __name__ == '__main__':
   f = TrivialForm()
   Application.Run(f)

Is it that IronPython Studio's form designer/code generator won't let you structure your code like that? (I've never used it.)

绅刃 2024-07-16 20:36:42

最后就更简单了。

我试图这样调用子表单:

f = frmSubform()
f.Show()

但我实际上需要这样做

f = frmSubform()
Form.Show(f)

Form.ShowDialog(f) 也有效; 当然是对话框格式。

这是一个很简单的错误,但在你了解之前,你是不知道的。

我不能百分百确定我在这个阶段明白为什么什么有效,但我确信我会通过经验学习。

In the end it was even simpler.

I was trying to invoke the subform thus:

f = frmSubform()
f.Show()

But I actually needed to do it this way

f = frmSubform()
Form.Show(f)

Form.ShowDialog(f) worked also; in a Dialog format of course.

A simple enough error but until you know you, well, don't know.

I'm not 100% sure I understand at this stage why what works, works, but I'm sure I shall learn with experience.

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