Last active
May 30, 2018 05:24
-
-
Save pythonsuezo/e4d7145a08928bf54e13f7164f8aebbf to your computer and use it in GitHub Desktop.
なんやかんや通信する奴その5 フレームの表示と設定の保存
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
########################################################################### | |
## Python code generated with wxFormBuilder (version Nov 6 2017) | |
## http://www.wxformbuilder.org/ | |
## | |
## PLEASE DO *NOT* EDIT THIS FILE! | |
########################################################################### | |
import wx | |
import wx.xrc | |
########################################################################### | |
## Class MyFrame1 | |
########################################################################### | |
class MyFrame1 ( wx.Frame ): | |
def __init__( self, parent ): | |
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"なんやかんや通信する奴", pos = wx.DefaultPosition, size = wx.Size( 820,520 ), style = wx.DEFAULT_FRAME_STYLE|wx.RESIZE_BORDER|wx.TAB_TRAVERSAL ) | |
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) | |
bSizer1 = wx.BoxSizer( wx.VERTICAL ) | |
self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.NO_BORDER ) | |
self.m_panel1.SetForegroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INFOTEXT ) ) | |
self.m_panel1.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_3DLIGHT ) ) | |
bSizer27 = wx.BoxSizer( wx.VERTICAL ) | |
bSizer28 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_staticText11 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"接続先:", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText11.Wrap( -1 ) | |
bSizer28.Add( self.m_staticText11, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_staticText12 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"IPアドレス", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText12.Wrap( -1 ) | |
bSizer28.Add( self.m_staticText12, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_staticText13 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"ポート", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText13.Wrap( -1 ) | |
bSizer28.Add( self.m_staticText13, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_staticText14 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"他の情報", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText14.Wrap( -1 ) | |
bSizer28.Add( self.m_staticText14, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer27.Add( bSizer28, 0, wx.EXPAND, 5 ) | |
bSizer42 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_staticText34 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"送信データをtxtファイルから読み出す:", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText34.Wrap( -1 ) | |
bSizer42.Add( self.m_staticText34, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_filePicker1 = wx.FilePickerCtrl( self.m_panel1, wx.ID_ANY, wx.EmptyString, u"Select a file", u"*.*", wx.DefaultPosition, wx.DefaultSize, wx.FLP_DEFAULT_STYLE ) | |
bSizer42.Add( self.m_filePicker1, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer27.Add( bSizer42, 0, wx.EXPAND, 5 ) | |
bSizer29 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_staticText251 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"ログは接続先+日時で保存されます", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText251.Wrap( -1 ) | |
bSizer29.Add( self.m_staticText251, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer29.Add( ( 0, 0), 1, wx.EXPAND, 5 ) | |
self.m_staticText19 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"送信文字数(バイト)", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText19.Wrap( -1 ) | |
bSizer29.Add( self.m_staticText19, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_textCtrl8 = wx.TextCtrl( self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY ) | |
self.m_textCtrl8.SetMaxLength( 30 ) | |
bSizer29.Add( self.m_textCtrl8, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer27.Add( bSizer29, 0, wx.EXPAND, 5 ) | |
bSizer32 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_staticText20 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"送信データ", wx.DefaultPosition, wx.DefaultSize, 0|wx.SUNKEN_BORDER ) | |
self.m_staticText20.Wrap( -1 ) | |
bSizer32.Add( self.m_staticText20, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_staticText21 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"改行コード変換", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText21.Wrap( -1 ) | |
bSizer32.Add( self.m_staticText21, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox6Choices = [ u"No", u"CR", u"LF", u"CRLF", u"HEX" ] | |
self.m_comboBox6 = wx.ComboBox( self.m_panel1, wx.ID_ANY, u"No", wx.DefaultPosition, wx.DefaultSize, m_comboBox6Choices, 0 ) | |
bSizer32.Add( self.m_comboBox6, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_button14 = wx.Button( self.m_panel1, wx.ID_ANY, u"送信クリア", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
bSizer32.Add( self.m_button14, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_staticText22 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"自動送信間隔", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText22.Wrap( -1 ) | |
bSizer32.Add( self.m_staticText22, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox7Choices = [ u"No", u"100ms", u"500ms", u"1s", u"5s", u"10s", wx.EmptyString ] | |
self.m_comboBox7 = wx.ComboBox( self.m_panel1, wx.ID_ANY, u"No", wx.DefaultPosition, wx.DefaultSize, m_comboBox7Choices, 0 ) | |
bSizer32.Add( self.m_comboBox7, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer32.Add( ( 0, 0), 1, wx.EXPAND, 5 ) | |
self.m_button15 = wx.Button( self.m_panel1, wx.ID_ANY, u"送信", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
bSizer32.Add( self.m_button15, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer27.Add( bSizer32, 0, wx.EXPAND, 5 ) | |
bSizer33 = wx.BoxSizer( wx.VERTICAL ) | |
self.m_textCtrl9 = wx.TextCtrl( self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE ) | |
bSizer33.Add( self.m_textCtrl9, 1, wx.EXPAND, 5 ) | |
bSizer27.Add( bSizer33, 1, wx.EXPAND, 5 ) | |
bSizer34 = wx.BoxSizer( wx.HORIZONTAL ) | |
bSizer36 = wx.BoxSizer( wx.VERTICAL ) | |
self.m_staticText24 = wx.StaticText( self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText24.Wrap( -1 ) | |
bSizer36.Add( self.m_staticText24, 0, wx.ALL, 5 ) | |
self.m_staticText25 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"ASCII表示では、0x00Hは「~」に変換されます", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText25.Wrap( -1 ) | |
bSizer36.Add( self.m_staticText25, 0, wx.ALL, 5 ) | |
bSizer34.Add( bSizer36, 1, wx.EXPAND, 5 ) | |
bSizer37 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_button16 = wx.Button( self.m_panel1, wx.ID_ANY, u"ポート選択", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
bSizer37.Add( self.m_button16, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_staticText26 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"読出し間隔タイムアウト:", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText26.Wrap( -1 ) | |
bSizer37.Add( self.m_staticText26, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer37.Add( ( 0, 0), 1, wx.EXPAND, 5 ) | |
self.m_textCtrl10 = wx.TextCtrl( self.m_panel1, wx.ID_ANY, u"20", wx.DefaultPosition, wx.DefaultSize, wx.TE_RIGHT ) | |
self.m_textCtrl10.SetMaxSize( wx.Size( 50,-1 ) ) | |
bSizer37.Add( self.m_textCtrl10, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_staticText28 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"ms", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText28.Wrap( -1 ) | |
bSizer37.Add( self.m_staticText28, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer34.Add( bSizer37, 1, wx.EXPAND, 5 ) | |
bSizer27.Add( bSizer34, 0, wx.EXPAND, 5 ) | |
bSizer39 = wx.BoxSizer( wx.HORIZONTAL ) | |
bSizer40 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_staticText29 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"受信データ", wx.DefaultPosition, wx.DefaultSize, 0|wx.SUNKEN_BORDER ) | |
self.m_staticText29.Wrap( -1 ) | |
bSizer40.Add( self.m_staticText29, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) | |
self.m_staticText30 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"表示形式", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText30.Wrap( -1 ) | |
bSizer40.Add( self.m_staticText30, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox8Choices = [ u"ASCII", u"ASCIIcrlf", u"HEX", u"HEXcrlf" ] | |
self.m_comboBox8 = wx.ComboBox( self.m_panel1, wx.ID_ANY, u"I", wx.DefaultPosition, wx.DefaultSize, m_comboBox8Choices, 0 ) | |
self.m_comboBox8.SetSelection( 0 ) | |
bSizer40.Add( self.m_comboBox8, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_button17 = wx.Button( self.m_panel1, wx.ID_ANY, u"受信クリア", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
bSizer40.Add( self.m_button17, 0, wx.ALL, 5 ) | |
bSizer39.Add( bSizer40, 1, wx.EXPAND, 5 ) | |
bSizer41 = wx.BoxSizer( wx.HORIZONTAL ) | |
bSizer41.Add( ( 0, 0), 1, wx.EXPAND, 5 ) | |
self.m_staticText32 = wx.StaticText( self.m_panel1, wx.ID_ANY, u"受信ボックス内文字数(バイト)", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText32.Wrap( -1 ) | |
bSizer41.Add( self.m_staticText32, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_textCtrl12 = wx.TextCtrl( self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY ) | |
bSizer41.Add( self.m_textCtrl12, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) | |
bSizer39.Add( bSizer41, 1, wx.EXPAND, 5 ) | |
bSizer27.Add( bSizer39, 0, wx.EXPAND, 5 ) | |
bSizer38 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_textCtrl11 = wx.TextCtrl( self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY ) | |
bSizer38.Add( self.m_textCtrl11, 1, wx.EXPAND, 5 ) | |
bSizer27.Add( bSizer38, 1, wx.EXPAND, 5 ) | |
self.m_panel1.SetSizer( bSizer27 ) | |
self.m_panel1.Layout() | |
bSizer27.Fit( self.m_panel1 ) | |
bSizer1.Add( self.m_panel1, 1, wx.EXPAND, 5 ) | |
self.SetSizer( bSizer1 ) | |
self.Layout() | |
self.m_menubar1 = wx.MenuBar( 0 ) | |
self.m_menu1 = wx.Menu() | |
self.m_menuItem1 = wx.MenuItem( self.m_menu1, wx.ID_ANY, u"シリアル設定", wx.EmptyString, wx.ITEM_NORMAL ) | |
self.m_menu1.Append( self.m_menuItem1 ) | |
self.m_menubar1.Append( self.m_menu1, u"設定" ) | |
self.SetMenuBar( self.m_menubar1 ) | |
self.Centre( wx.BOTH ) | |
# Connect Events | |
self.Bind( wx.EVT_CLOSE, self.ExitHandler ) | |
self.Bind( wx.EVT_MENU, self.Serial_option, id = self.m_menuItem1.GetId() ) | |
def __del__( self ): | |
pass | |
# Virtual event handlers, overide them in your derived class | |
def ExitHandler( self, event ): | |
event.Skip() | |
def Serial_option( self, event ): | |
event.Skip() | |
########################################################################### | |
## Class MyDialog1 | |
########################################################################### | |
class MyDialog1 ( wx.Dialog ): | |
def __init__( self, parent ): | |
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"なんやかんや通信する奴", pos = wx.DefaultPosition, size = wx.Size( 490,309 ), style = wx.DEFAULT_DIALOG_STYLE ) | |
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) | |
bSizer1 = wx.BoxSizer( wx.VERTICAL ) | |
self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) | |
self.m_panel1.SetForegroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INFOTEXT ) ) | |
self.m_panel1.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INFOBK ) ) | |
bSizer2 = wx.BoxSizer( wx.VERTICAL ) | |
sbSizer2 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel1, wx.ID_ANY, wx.EmptyString ), wx.HORIZONTAL ) | |
bSizer8 = wx.BoxSizer( wx.VERTICAL ) | |
self.m_checkBox1 = wx.CheckBox( sbSizer2.GetStaticBox(), wx.ID_ANY, u"TCP/IP", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_checkBox1.SetValue(True) | |
bSizer8.Add( self.m_checkBox1, 0, wx.ALL, 5 ) | |
sbSizer2.Add( bSizer8, 0, wx.EXPAND, 5 ) | |
bSizer9 = wx.BoxSizer( wx.HORIZONTAL ) | |
bSizer10 = wx.BoxSizer( wx.VERTICAL ) | |
self.m_staticText3 = wx.StaticText( sbSizer2.GetStaticBox(), wx.ID_ANY, u"ホスト:", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText3.Wrap( -1 ) | |
bSizer10.Add( self.m_staticText3, 0, wx.ALL, 5 ) | |
self.m_staticText7 = wx.StaticText( sbSizer2.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText7.Wrap( -1 ) | |
bSizer10.Add( self.m_staticText7, 0, wx.ALL, 3 ) | |
self.m_staticText8 = wx.StaticText( sbSizer2.GetStaticBox(), wx.ID_ANY, u"サービス:", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText8.Wrap( -1 ) | |
bSizer10.Add( self.m_staticText8, 0, wx.ALL, 5 ) | |
bSizer9.Add( bSizer10, 0, wx.EXPAND, 5 ) | |
bSizer11 = wx.BoxSizer( wx.VERTICAL ) | |
bSizer12 = wx.BoxSizer( wx.VERTICAL ) | |
m_comboBox1Choices = [] | |
self.m_comboBox1 = wx.ComboBox( sbSizer2.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, m_comboBox1Choices, wx.CB_DROPDOWN ) | |
bSizer12.Add( self.m_comboBox1, 0, wx.EXPAND, 5 ) | |
bSizer11.Add( bSizer12, 0, wx.EXPAND, 5 ) | |
bSizer14 = wx.BoxSizer( wx.HORIZONTAL ) | |
bSizer15 = wx.BoxSizer( wx.VERTICAL ) | |
self.m_checkBox3 = wx.CheckBox( sbSizer2.GetStaticBox(), wx.ID_ANY, u"履歴を残す", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
bSizer15.Add( self.m_checkBox3, 0, wx.ALL, 5 ) | |
self.m_radioBtn5 = wx.RadioButton( sbSizer2.GetStaticBox(), wx.ID_ANY, u"Telnet", wx.DefaultPosition, wx.DefaultSize, wx.RB_SINGLE ) | |
self.m_radioBtn5.SetValue( True ) | |
bSizer15.Add( self.m_radioBtn5, 0, wx.ALL, 5 ) | |
bSizer14.Add( bSizer15, 1, wx.EXPAND, 5 ) | |
bSizer16 = wx.BoxSizer( wx.VERTICAL ) | |
bSizer17 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_staticText4 = wx.StaticText( sbSizer2.GetStaticBox(), wx.ID_ANY, u"TCPポート:", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText4.Wrap( -1 ) | |
bSizer17.Add( self.m_staticText4, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) | |
self.m_textCtrl1 = wx.TextCtrl( sbSizer2.GetStaticBox(), wx.ID_ANY, u"22", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_textCtrl1.SetMaxLength( 5 ) | |
bSizer17.Add( self.m_textCtrl1, 1, wx.ALL|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer16.Add( bSizer17, 1, wx.ALIGN_RIGHT, 5 ) | |
bSizer18 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_staticText5 = wx.StaticText( sbSizer2.GetStaticBox(), wx.ID_ANY, u"SSHバージョン:", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText5.Wrap( -1 ) | |
self.m_staticText5.Hide() | |
bSizer18.Add( self.m_staticText5, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_textCtrl2 = wx.TextCtrl( sbSizer2.GetStaticBox(), wx.ID_ANY, u"まだむり", wx.DefaultPosition, wx.DefaultSize, wx.TE_READONLY ) | |
self.m_textCtrl2.Hide() | |
bSizer18.Add( self.m_textCtrl2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer16.Add( bSizer18, 1, wx.EXPAND, 5 ) | |
bSizer19 = wx.BoxSizer( wx.HORIZONTAL ) | |
self.m_staticText6 = wx.StaticText( sbSizer2.GetStaticBox(), wx.ID_ANY, u"プロトコル:", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText6.Wrap( -1 ) | |
self.m_staticText6.Hide() | |
bSizer19.Add( self.m_staticText6, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox2Choices = [ u"UNSPEC", u"IPv6", u"IPv4" ] | |
self.m_comboBox2 = wx.ComboBox( sbSizer2.GetStaticBox(), wx.ID_ANY, u"UNSPEC", wx.DefaultPosition, wx.DefaultSize, m_comboBox2Choices, 0 ) | |
self.m_comboBox2.Hide() | |
bSizer19.Add( self.m_comboBox2, 1, wx.ALL, 5 ) | |
bSizer16.Add( bSizer19, 1, wx.EXPAND, 5 ) | |
bSizer14.Add( bSizer16, 1, wx.EXPAND, 5 ) | |
bSizer11.Add( bSizer14, 1, wx.EXPAND, 5 ) | |
bSizer9.Add( bSizer11, 1, wx.EXPAND, 5 ) | |
sbSizer2.Add( bSizer9, 1, wx.EXPAND, 5 ) | |
bSizer2.Add( sbSizer2, 1, wx.ALL|wx.EXPAND, 5 ) | |
sbSizer3 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel1, wx.ID_ANY, wx.EmptyString ), wx.HORIZONTAL ) | |
self.m_checkBox2 = wx.CheckBox( sbSizer3.GetStaticBox(), wx.ID_ANY, u"シリアル", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
sbSizer3.Add( self.m_checkBox2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
self.m_staticText9 = wx.StaticText( sbSizer3.GetStaticBox(), wx.ID_ANY, u"ポート", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText9.Wrap( -1 ) | |
sbSizer3.Add( self.m_staticText9, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox3Choices = [] | |
self.m_comboBox3 = wx.ComboBox( sbSizer3.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, m_comboBox3Choices, wx.CB_READONLY ) | |
sbSizer3.Add( self.m_comboBox3, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
bSizer2.Add( sbSizer3, 0, wx.ALL|wx.EXPAND, 5 ) | |
m_sdbSizer1 = wx.StdDialogButtonSizer() | |
self.m_sdbSizer1OK = wx.Button( self.m_panel1, wx.ID_OK ) | |
m_sdbSizer1.AddButton( self.m_sdbSizer1OK ) | |
self.m_sdbSizer1Cancel = wx.Button( self.m_panel1, wx.ID_CANCEL ) | |
m_sdbSizer1.AddButton( self.m_sdbSizer1Cancel ) | |
self.m_sdbSizer1Help = wx.Button( self.m_panel1, wx.ID_HELP ) | |
m_sdbSizer1.AddButton( self.m_sdbSizer1Help ) | |
m_sdbSizer1.Realize(); | |
bSizer2.Add( m_sdbSizer1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5 ) | |
self.m_panel1.SetSizer( bSizer2 ) | |
self.m_panel1.Layout() | |
bSizer2.Fit( self.m_panel1 ) | |
bSizer1.Add( self.m_panel1, 1, wx.EXPAND, 5 ) | |
self.SetSizer( bSizer1 ) | |
self.Layout() | |
self.Centre( wx.BOTH ) | |
# Connect Events | |
self.m_checkBox1.Bind( wx.EVT_CHECKBOX, self.Checked_IP ) | |
self.m_comboBox1.Bind( wx.EVT_COMBOBOX, self.IP_Set ) | |
self.m_checkBox2.Bind( wx.EVT_CHECKBOX, self.Checked_Serial ) | |
self.m_sdbSizer1OK.Bind( wx.EVT_BUTTON, self.Dialog_ok ) | |
def __del__( self ): | |
pass | |
# Virtual event handlers, overide them in your derived class | |
def Checked_IP( self, event ): | |
event.Skip() | |
def IP_Set( self, event ): | |
event.Skip() | |
def Checked_Serial( self, event ): | |
event.Skip() | |
def Dialog_ok( self, event ): | |
event.Skip() | |
########################################################################### | |
## Class MyDialog2 | |
########################################################################### | |
class MyDialog2 ( wx.Dialog ): | |
def __init__( self, parent ): | |
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 258,370 ), style = wx.DEFAULT_DIALOG_STYLE ) | |
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) | |
bSizer28 = wx.BoxSizer( wx.VERTICAL ) | |
self.m_panel3 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SUNKEN_BORDER ) | |
bSizer31 = wx.BoxSizer( wx.VERTICAL ) | |
fgSizer1 = wx.FlexGridSizer( 0, 2, 5, 10 ) | |
fgSizer1.SetFlexibleDirection( wx.BOTH ) | |
fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED ) | |
self.m_staticText26 = wx.StaticText( self.m_panel3, wx.ID_ANY, u"COMポート", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText26.Wrap( -1 ) | |
fgSizer1.Add( self.m_staticText26, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox7Choices = [ u"COM1" ] | |
self.m_comboBox7 = wx.ComboBox( self.m_panel3, wx.ID_ANY, u"COM1", wx.DefaultPosition, wx.DefaultSize, m_comboBox7Choices, 0 ) | |
fgSizer1.Add( self.m_comboBox7, 0, wx.ALL|wx.EXPAND, 5 ) | |
self.m_staticText30 = wx.StaticText( self.m_panel3, wx.ID_ANY, u"ボーレート", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText30.Wrap( -1 ) | |
fgSizer1.Add( self.m_staticText30, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox8Choices = [ u"50", u"75", u"110", u"134", u"150", u"200", u"300", u"600", u"1200", u"1800", u"2400", u"4800", u"9600", u"19200", u"38400", u"57600", u"115200" ] | |
self.m_comboBox8 = wx.ComboBox( self.m_panel3, wx.ID_ANY, u"9600", wx.DefaultPosition, wx.DefaultSize, m_comboBox8Choices, 0 ) | |
self.m_comboBox8.SetSelection( 12 ) | |
fgSizer1.Add( self.m_comboBox8, 0, wx.ALL|wx.EXPAND, 5 ) | |
self.m_staticText31 = wx.StaticText( self.m_panel3, wx.ID_ANY, u"データビット", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText31.Wrap( -1 ) | |
fgSizer1.Add( self.m_staticText31, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox9Choices = [ u"5", u"6", u"7", u"8" ] | |
self.m_comboBox9 = wx.ComboBox( self.m_panel3, wx.ID_ANY, u"8", wx.DefaultPosition, wx.DefaultSize, m_comboBox9Choices, 0 ) | |
self.m_comboBox9.SetSelection( 3 ) | |
fgSizer1.Add( self.m_comboBox9, 0, wx.ALL|wx.EXPAND, 5 ) | |
self.m_staticText32 = wx.StaticText( self.m_panel3, wx.ID_ANY, u"パリティ", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText32.Wrap( -1 ) | |
fgSizer1.Add( self.m_staticText32, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox10Choices = [ u"No", u"Odd", u"Even" ] | |
self.m_comboBox10 = wx.ComboBox( self.m_panel3, wx.ID_ANY, u"No", wx.DefaultPosition, wx.DefaultSize, m_comboBox10Choices, 0 ) | |
self.m_comboBox10.SetSelection( 0 ) | |
fgSizer1.Add( self.m_comboBox10, 0, wx.ALL|wx.EXPAND, 5 ) | |
self.m_staticText33 = wx.StaticText( self.m_panel3, wx.ID_ANY, u"ストップビット", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText33.Wrap( -1 ) | |
fgSizer1.Add( self.m_staticText33, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox11Choices = [ u"1", u"1.5", u"2" ] | |
self.m_comboBox11 = wx.ComboBox( self.m_panel3, wx.ID_ANY, u"1", wx.DefaultPosition, wx.DefaultSize, m_comboBox11Choices, 0 ) | |
self.m_comboBox11.SetSelection( 0 ) | |
fgSizer1.Add( self.m_comboBox11, 0, wx.ALL|wx.EXPAND, 5 ) | |
self.m_staticText34 = wx.StaticText( self.m_panel3, wx.ID_ANY, u"フロー制御", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText34.Wrap( -1 ) | |
fgSizer1.Add( self.m_staticText34, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) | |
m_comboBox12Choices = [ u"No", u"HardWare", u"Xon/Xoff" ] | |
self.m_comboBox12 = wx.ComboBox( self.m_panel3, wx.ID_ANY, u"No", wx.DefaultPosition, wx.DefaultSize, m_comboBox12Choices, 0 ) | |
self.m_comboBox12.SetSelection( 0 ) | |
fgSizer1.Add( self.m_comboBox12, 0, wx.ALL|wx.EXPAND, 5 ) | |
self.m_staticText35 = wx.StaticText( self.m_panel3, wx.ID_ANY, u"受信タイムアウト時間", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
self.m_staticText35.Wrap( -1 ) | |
fgSizer1.Add( self.m_staticText35, 0, wx.ALL, 5 ) | |
self.m_spinCtrl1 = wx.SpinCtrl( self.m_panel3, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 20,-1 ), wx.SP_ARROW_KEYS, 0, 50, 20 ) | |
fgSizer1.Add( self.m_spinCtrl1, 0, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT, 5 ) | |
self.m_button61 = wx.Button( self.m_panel3, wx.ID_ANY, u"デフォルト", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
fgSizer1.Add( self.m_button61, 0, wx.ALL, 5 ) | |
self.m_button6 = wx.Button( self.m_panel3, wx.ID_ANY, u"保存", wx.DefaultPosition, wx.DefaultSize, 0 ) | |
fgSizer1.Add( self.m_button6, 0, wx.ALL|wx.ALIGN_RIGHT, 5 ) | |
bSizer31.Add( fgSizer1, 1, wx.EXPAND, 5 ) | |
self.m_panel3.SetSizer( bSizer31 ) | |
self.m_panel3.Layout() | |
bSizer31.Fit( self.m_panel3 ) | |
bSizer28.Add( self.m_panel3, 1, wx.EXPAND, 5 ) | |
self.SetSizer( bSizer28 ) | |
self.Layout() | |
self.Centre( wx.BOTH ) | |
# Connect Events | |
self.m_button61.Bind( wx.EVT_BUTTON, self.option_reset ) | |
self.m_button6.Bind( wx.EVT_BUTTON, self.Serial_save ) | |
def __del__( self ): | |
pass | |
# Virtual event handlers, overide them in your derived class | |
def option_reset( self, event ): | |
event.Skip() | |
def Serial_save( self, event ): | |
event.Skip() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wx | |
import teraframe | |
import configparser | |
import os, sys | |
import datetime | |
from collections import OrderedDict | |
"""---------------------------------------------- | |
通信用ソフト | |
グローバル定数 | |
path : 実行ファイルのディレクトリ | |
today : 今日の日付 | |
now : 今の時間 | |
INI : 設定ファイルの場所 | |
----------------------------------------------""" | |
path = os.path.dirname( sys.argv[0] ) | |
INI = path + "/INI.conf" | |
conf = configparser.SafeConfigParser() | |
conf.read(INI) | |
if not os.path.exists( INI ): | |
conf["DEFAULT"] = {"host":"localhost", | |
"port":"23", | |
"serial":"COM1", | |
"baudrate":"9600", | |
"data_bit":"8", | |
"parity":"No", | |
"stopbit":"1", | |
"flow_ctrl":"No", | |
"timeout":"20"} | |
if not "option" in conf: | |
conf.add_section("option") | |
default = conf["DEFAULT"] | |
option = conf["option"] | |
print("設定を読み出す") | |
for key in option: | |
print(key) | |
print(option[key]) | |
with open(INI,"w") as configfile: | |
conf.write(configfile) | |
now = datetime.datetime.now() | |
today = now.strftime( "%Y/%m/%d" ) # 日付 YYYY/MM/DD | |
now = now.strftime( "%H:%M:%S" ) # 時刻 HH:MM:SS | |
class Mainframe( teraframe.MyFrame1 ): | |
def __init__( self, parent ): | |
teraframe.MyFrame1.__init__( self, parent ) | |
IP_log = os.path.join( path, "IP_log.txt") | |
subframe = MyDialog1( None ) | |
result = subframe.ShowModal() | |
if result == wx.ID_OK: | |
print("OK") | |
option["host"] = subframe.m_comboBox1.GetValue() | |
option["port"] = subframe.m_textCtrl1.GetValue() | |
option["serial"] = subframe.m_comboBox3.GetValue() | |
print(option["host"]) | |
IP = option["host"] | |
port = option["port"] | |
service = subframe.m_checkBox1.GetValue() | |
com = option["serial"] | |
with open(INI,"w") as configfile: | |
conf.write(configfile) | |
with open(IP_log, "a") as iplog: | |
iplog.write( IP + "," + port + "\n" ) | |
if service: | |
self.m_staticText12.SetLabel( IP ) # IP | |
self.m_staticText13.SetLabel( port ) # ポート | |
self.m_staticText14.SetLabel( "telnet" ) | |
else: | |
self.m_staticText12.SetLabel( "シリアル" ) # IP | |
self.m_staticText13.SetLabel( com ) # ポート | |
self.m_staticText14.SetLabel( option["baudrate"]+"bps" +', data_bit : ' + option["data_bit"] +', parity : ' + option["parity"] +', stopbit : ' + option["stopbit"] +', flow_ctrl : ' + option["flow_ctrl"] +', timeout : ' + option["timeout"] ) | |
else: | |
exit() | |
def Serial_option( self, event ): | |
option_dlg = MyDialog2( None ) | |
result = option_dlg.ShowModal() | |
def ExitHandler( self, event ): | |
dlg = wx.MessageDialog( None, '通信ソフトを終了します。\nよろしいですか?', | |
"通信ソフト", style = wx.YES_NO ) | |
result = dlg.ShowModal() #ダイアログの表示 | |
if result == wx.ID_YES: #はいを押した時終了 | |
sys.exit() #プログラム終了 | |
else: #いいえの時は何もしない | |
return | |
class MyDialog1( teraframe.MyDialog1 ): | |
def __init__( self, parent ): | |
teraframe.MyDialog1.__init__( self, parent ) | |
IP_log = os.path.join( path, "IP_log.txt") | |
port_array = ["COM"+str(i+1) for i in range(32)] | |
self.m_comboBox3.SetItems(port_array) | |
self.m_comboBox3.SetValue(option["serial"]) | |
print("host:",option["host"]) | |
if os.path.exists( IP_log ): | |
self.IP_Dict = OrderedDict() | |
self.IP_Dict = self.txt_list( IP_log ) # 接続ログを呼んで辞書型{IP:port}にする | |
IP_list = list( self.IP_Dict.keys() )[::-1] # 辞書のキーをリストにするのと最近の物を上にする | |
self.m_comboBox1.SetItems( IP_list ) # コンボボックスに追加する | |
self.m_comboBox1.SetStringSelection(option["host"]) # 選択する | |
key = self.m_comboBox1.GetValue() | |
try: | |
self.m_textCtrl1.SetValue(self.IP_Dict[key]) | |
except: | |
self.m_textCtrl1.SetValue(option["port"]) | |
else: | |
with open( IP_log, "w") as file: | |
file.write("") | |
def IP_Set(self,event): | |
key = self.m_comboBox1.GetValue() | |
self.m_textCtrl1.SetValue(self.IP_Dict[key]) | |
def txt_list( self, txt_file ): # テキストファイルを読み取ってリストにする | |
IP_Dict = OrderedDict() | |
file = open(txt_file,"r") | |
data = file.read() | |
file.close() | |
lines = data.split("\n") | |
for x in lines: | |
if (x.count(",") == 1): | |
data = x.split(",") | |
IP = data[0] | |
port = data[1] | |
IP_Dict[IP] = port | |
return IP_Dict | |
def Checked_IP(self,event): | |
self.m_checkBox1.SetValue(True) | |
self.m_checkBox2.SetValue(False) | |
def Checked_Serial(self,event): | |
self.m_checkBox1.SetValue(False) | |
self.m_checkBox2.SetValue(True) | |
class MyDialog2( teraframe.MyDialog2 ): | |
def __init__( self, parent ): | |
teraframe.MyDialog2.__init__( self, parent ) | |
port_array = ["COM"+str(i+1) for i in range(32)] | |
self.m_comboBox7.SetItems(port_array) | |
self.m_comboBox7.SetValue(option["serial"]) | |
self.m_comboBox8.SetValue(option["baudrate"]) | |
self.m_comboBox9.SetValue(option["data_bit"]) | |
self.m_comboBox10.SetValue(option["parity"]) | |
self.m_comboBox11.SetValue(option["stopbit"]) | |
self.m_comboBox12.SetValue(option["flow_ctrl"]) | |
self.m_spinCtrl1.SetValue(int(option["timeout"])) | |
def Serial_save( self, event ): | |
option["serial"] = self.m_comboBox7.GetValue() | |
option["baudrate"] = self.m_comboBox8.GetValue() | |
option["data_bit"] = self.m_comboBox9.GetValue() | |
option["parity"] = self.m_comboBox10.GetValue() | |
option["stopbit"] = self.m_comboBox11.GetValue() | |
option["flow_ctrl"] = self.m_comboBox12.GetValue() | |
option["timeout"] = str(self.m_spinCtrl1.GetValue()) | |
with open(INI,"w") as configfile: | |
conf.write(configfile) | |
self.Destroy() | |
def option_reset( self, event ): | |
self.m_comboBox8.SetValue(default["baudrate"]) | |
self.m_comboBox9.SetValue(default["data_bit"]) | |
self.m_comboBox10.SetValue(default["parity"]) | |
self.m_comboBox11.SetValue(default["stopbit"]) | |
self.m_comboBox12.SetValue(default["flow_ctrl"]) | |
self.m_spinCtrl1.SetValue(int(default["timeout"])) | |
app = wx.App( False ) | |
frame = Mainframe( None ) | |
frame.Show(True) | |
app.MainLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment