使用erlang

时间:2018-08-08 19:20:21

标签: python erlang protocols wxwidgets erlang-ports

我是python的新手,我正在尝试使用python构建GUI。

我正在使用wxGlade生成GUI代码,并通过erlport将其连接到Erlang。

我的问题是我不知道如何同时使用GUI和erlport及其类。启动GUI后,我想用Erlang消息控制显示。

这是GUI代码

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.8.3 on Wed Aug  8 22:17:32 2018
#

import wx

# begin wxGlade: dependencies
# end wxGlade

# begin wxGlade: extracode
# end wxGlade


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((150, 80))
        self.text_ctrl = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_CENTRE | wx.TE_READONLY)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_TEXT, self.edit_text, self.text_ctrl)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("frame")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.text_ctrl, 0, wx.ALIGN_CENTER, 0)
        self.SetSizer(sizer_1)
        self.Layout()
        # end wxGlade

    def edit_text(self, event):  # wxGlade: MyFrame.<event_handler>
        print("Event handler 'edit_text' not implemented!")
        event.Skip()

# end of class MyFrame

class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True

# end of class MyApp

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

这是使用erlport的示例代码

from erlport import Port, Protocol

class HelloProtocol(Protocol):

    def handle_hello(self, name):
        return "Hello, %s" % name

if __name__ == "__main__":
    proto = HelloProtocol()
    proto.run(Port(use_stdio=True))

我想知道如何将两者结合起来,这样我便能够运行GUI并编辑文本,例如使用来自erlang的消息

0 个答案:

没有答案