I’ve pretty mutch worked out the errors in my code so far in the current segment, However there is one issue in my code. I can run the code in bmud.py without any error but but no Frame or top level window of any kind appeered. I checked to see if maybe it’d started in another process, even thow I haden’t coded it to do that, just to see if that was built-in behavior but there was nothing new besides my instance of command prompt. In order to close the program’s loop I had to terminate my command prompt session. Yet when I checked the log, I saw nothing but empty curly braces and no trace or error message.
Things I tried:
In my original code, I had the call to window.Show after I declared window to be a Frame. So I commented it out and added it in just before my call to app.MainLoop. That did nothing. I even checked the log again but just saw a second set of braces Underneeth the first. Again no error. I’m thinking it might be because I’m running it from the command line, But I’m not sure.
I also saw people passing True to the Show method so I changed it from window.Show() to window.Show(True). It didn’t seem to make a difference. I am blind, and am using NVDA as my screenreader, but I don’t think that’s the issue because NVDA’s menus and dialog boxes were writen with wxpython, I’d think It wood be able to read other gui’s created with it.
Using python 3.9 with the latest wxpython, on windows 11 x64
I am using py_setenv for environment variable manipulation.
I have imported telnetlib but haven’t used it yet in this segment.
Note, I have a broken if statement with old code and definitions witch doesn’t execute write now because I have another one writen in the initialization segment witch sets the environment variable. The else statement contains the clean new function. The point was to make it so that the Add button is the only thing in the Frame until the user as created a character. I plan on fixing it before bringing it into beta stage.
File: bmud.py:
import os
from py_setenv import setenv
import telnetlib
import wx
from ast import literal_eval
name = mud = host = port = None
if "chars" in os.environ:
first_run = 0
else:
first_run = 1
if first_run == 0:
setenv("chars", value = "{}")
chars = literal_eval(setenv("chars"))
app = wx.App(1, "bmud.log")
window = wx.Frame()
#window.Show()
window.Title = "character list"
pnl = wx.Panel(window)
#chars = setenv("chars")
if len(setenv("chars")) < 1:
def new():
dlg = wx.Dialog(window)
try:
dlg.Title = "New character"
except:
setenv("errors", value = ["Title Error"])
pnl2 = wx.Panel(dlg)
#chars = os.environ[chars]
class edit(wx.Button()):
#a text control with label support
def __init__(self, parent, id, value, pos, size, style, label = ""):
return wx.TextCtrl(parent, id = id, value = value, size = size, pos = pos, style = style)
if len(label) > 0:
self.SetLabel(label)
name = edit(pnl2, -1, "name")
mud = edit(pnl2, -1, "mud name")
host = edit(pnl2, -1, "host")
port = edit(pnl2, -1, "port")
ok = wx.Button(pnl2, label = "ok")
ok.Bind(wx.EVT_BUTTON(), dlg.destroy())
def erase():
setenv("abort", value = 1)
dlg.destroy()
cancel = wx.Button(pnl2, label = "Cancel")
cancel.Bind(wx.EVT_BUTTON, erase())
dlg.ShowModal()
add = wx.Button(pnl, label = "add")
add.Bind(wx.EVT_BUTTON(), new())
else:
def new():
dlg = wx.Dialog()
try: #I didn't think it wood work.
dlg.Title = "New character"
except:
setenv("errors", value = ["Title Error"])
pnl2 = wx.Panel(dlg)
#chars = os.environ[chars]
#creating a text control inside a static box as a solution to not having a label parameter.
lname = wx.StaticBox(pnl2, id = -1, label = "Character name")
name = wx.TextCtrl(lname, id = -1, value = "")
lmud = wx.StaticBox(pnl2, id = -1, label = "mud name")
mud = wx.TextCtrl(lmud, id = -1, value = "")
lhost = wx.StaticBox(pnl2, id = -1, label = "host")
host = wx.TextCtrl(lhost, id = -1, value = "")
lport = wx.StaticBox(pnl2, id = -1, label = "port")
port = wx.TextCtrl(lport, id = -1, value = "")
ok = wx.Button(pnl2, label = "ok")
ok.Bind(wx.EVT_BUTTON, handler = dlg.Destroy)
def erase():
setenv("abort", value = 1)
dlg.Destroy()
cancel = wx.Button(pnl2, label = "Cancel")
cancel.Bind(wx.EVT_BUTTON, handler = erase)
dlg.ShowModal()
def get_names():
names = []
for I in chars:
names.append(I)
return names
charlist = wx.ComboBox(pnl, choices = get_names(), style = wx.CB_READONLY)
add = wx.Button(pnl, label = "add")
add.Bind(wx.EVT_BUTTON, new())
window.Show(True)
app.MainLoop()
file bmud.log:
{}