By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,729 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,729 IT Pros & Developers. It's quick & easy.

(OT) wxPython & resizers, html text (code included)

P: n/a
Hi,

i'm trying to convert my java console app to a python gui.
Now, the only problem i seem to have at the moment are the resizers
for the layout. It seems that for the purpose of what i'm trying to do,
specifying the coordinates is easier that fighting with the layout resizers.

1) I have a screen split in 2. Left side is a textcontrol where logging will
end up. All text will be appended to the textcontrol. Ideally this should
allow html tags but the wxHtmlWindow doesn't seem to support just adding
text. Only workaround that i can think off is to maintain a list of message
myself
and then i could set those every time something changes but i don't really
like this as on every change, the whole textcontrol will be refilled.
The reason for html is to easily adjust text from one colour to another and
for
instance some basic formatting like bold, italic etc.
Any ideas?

2) (view with for instance with courier)
-----------------------------------------------
| TextControl | ________ |
| ||________| Combobox |
| | |
| | ________ |
| ||________| |
| | |
| | ________ |
| ||________| Textcontrol |
| | |
-----------------------------------------------

Basically i have a number of button left-aligned in the right part of the
split window and
they are placed vertically with a small gap in between (border). This is
working but then
i would want to add a combobox next to button 1 and saya textcontrol to
button 2.
A gridresizer would work if i would be able to specify what row and column
the component
would have to be in but there doesn't seem to be such a method.
Only sollution i can think of is adding the coordinates of where i want to
component to come.
Is there another sollution as i read that it's best not to add components by
specifying an x
and y value.

Thanks

============== Working snippet below =======================
from wxPython.wx import *
import sys, os

ID_ABOUT=100
ID_EXIT=101

ID_BUTTON_CONNECT=200
ID_BUTTON_CHECK=201
ID_BUTTON_CONNECTIONS=202
ID_BUTTON_SEND=203
ID_BUTTON_HELP=204
ID_BUTTON_EXIT=205

class MainWindow(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self,parent,id,title, style=wxDEFAULT_FRAME_STYLE|
wxNO_FULL_REPAINT_ON_RESIZE)

self.split_window = wxSplitterWindow(self, -1)
self.button_pane = wxPanel(self.split_window, -1,
style=wxTAB_TRAVERSAL|wxNO_FULL_REPAINT_ON_RESIZE)

self.logging_screen = wxTextCtrl(self.split_window, -1, "",
style=wxTE_MULTILINE|wxHSCROLL)
#self.html_window = new wxHtmlWindow( self )

self.connect = wxButton(self.button_pane, ID_BUTTON_CONNECT,
"connect")
self.check = wxButton(self.button_pane, ID_BUTTON_CHECK, "check")
self.connections = wxButton(self.button_pane, ID_BUTTON_CONNECTIONS,
"connections")
self.send = wxButton(self.button_pane, ID_BUTTON_SEND, "send")
self.help = wxButton(self.button_pane, ID_BUTTON_HELP, "help")
self.exit = wxButton(self.button_pane, ID_BUTTON_EXIT, "exit")

#make the combobox for the connections
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
#'this is a long item that needs a scrollbar...',
'six', 'seven', 'eight']

self.cb = wxComboBox(
self.button_pane, 500, "default value", (90, 50),
(95, -1), sampleList, wxCB_DROPDOWN #|wxTE_PROCESS_ENTER
)

# Menu Bar
self.frame_1_menubar = wxMenuBar()
self.SetMenuBar(self.frame_1_menubar)
self.File = wxMenu()
self.File.Append( ID_ABOUT, "&About", "About CheckServer Client" )
self.File.AppendSeparator()
self.File.Append( ID_EXIT, "E&xit", "Leave the application" )
self.frame_1_menubar.Append(self.File, "F&ile")
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.OnExit)

# Menu Bar end

self.statusbar = self.CreateStatusBar(1, wxST_SIZEGRIP)

self.__set_properties()
self.__do_layout()
self.Show(true)

# end wxGlade

def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("CheckServer Client")

_icon = wxEmptyIcon()
_icon.CopyFromBitmap(wxBitmap("D:\\temp\\1anipt1c. gif",
wxBITMAP_TYPE_ANY))
self.SetIcon(_icon)
self.SetSize((723, 533))
self.SetFocus()

self.logging_screen.SetBackgroundColour(wxColour(2 47, 255, 159))
self.logging_screen.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL,
0, "Century Gothic"))
self.logging_screen.SetToolTipString("Here you'll see the result of
the commands you issue to the server")
self.logging_screen.SetDefaultStyle(wxTextAttr(wxC olour(255,0,0)))
self.logging_screen.AppendText("Red text\n");
self.logging_screen.AppendText("<span>Test</span>\n");
self.logging_screen.Enable(0)

self.connect.SetSize((110, 28))
self.connect.SetBackgroundColour(wxColour(143, 188, 143))
self.connect.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.connect.SetToolTipString("Connect to a server")
self.connect.SetFocus()

self.check.SetSize((110, 28))
self.check.SetBackgroundColour(wxColour(143, 188, 143))
self.check.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.check.SetToolTipString("Check server directories")
self.check.Enable(0)

self.connections.SetSize((110, 28))
self.connections.SetBackgroundColour(wxColour(143, 188, 143))
self.connections.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.connections.SetToolTipString("What connections are active")
self.connections.Enable(0)

self.send.SetSize((110, 28))
self.send.SetBackgroundColour(wxColour(143, 188, 143))
self.send.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.send.SetToolTipString("Send a file from the server to local
pc")
self.send.Enable(0)

self.help.SetSize((110, 28))
self.help.SetBackgroundColour(wxColour(143, 188, 143))
self.help.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.help.SetToolTipString("Display help options (command line)")

self.exit.SetSize((110, 28))
self.exit.SetBackgroundColour(wxColour(143, 188, 143))
self.exit.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.exit.SetToolTipString("Exit the application")

self.button_pane.SetFocus()
self.button_pane.SetBackgroundColour(wxBLUE)
self.statusbar.SetStatusWidths([-1])
self.split_window.SetMinimumPaneSize(20)

# statusbar fields
statusbar_fields = ["CheckServer"]
for i in range(len(statusbar_fields)):
self.statusbar.SetStatusText(statusbar_fields[i], i)

# end wxGlade

def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
split_window_sizer = wxBoxSizer(wxVERTICAL)

button_pane_sizer = wxBoxSizer(wxVERTICAL)
button_pane_sizer.Add(self.connect, 0, wxALL, 2)
button_pane_sizer.Add(self.check, 0, wxALL, 2)
button_pane_sizer.Add(self.connections, 0, wxALL, 2)
button_pane_sizer.Add(self.send, 0, wxALL, 2)
button_pane_sizer.Add(self.help, 0, wxALL, 2)
button_pane_sizer.Add(self.exit, 0, wxALL, 2)
button_pane_sizer.Add(self.cb,0, wxALL, 2)
self.button_pane.SetAutoLayout(1)
self.button_pane.SetSizer(button_pane_sizer)
button_pane_sizer.Fit(self.button_pane)
button_pane_sizer.SetSizeHints(self.button_pane)
self.split_window.SplitVertically(self.logging_scr een,
self.button_pane)
split_window_sizer.Add(self.split_window, 1, wxEXPAND, 0)
self.SetAutoLayout(1)
self.SetSizer(split_window_sizer)
self.Layout()
self.Centre()
# end wxGlade

def OnAbout(self,e):
d= wxMessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor", wxOK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.

def OnExit(self,e):
self.Close(true) # Close the frame.

# end of class MyFrame
class App(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
main_window = MainWindow(None, -1, "CheckServer Client")
self.SetTopWindow(main_window)
return true

# end of class App

app = App(0)
app.MainLoop()
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Check out Dabo (www.dabodev.com); they are creating an IDE for wxPython that
uses direct placement. It's still young, but does work.

--

"flupke" <fl****@nonexistingdomain.com> wrote in message
news:lp*********************@hestia.telenet-ops.be...
Hi,

i'm trying to convert my java console app to a python gui.
Now, the only problem i seem to have at the moment are the resizers
for the layout. It seems that for the purpose of what i'm trying to do,
specifying the coordinates is easier that fighting with the layout resizers.
1) I have a screen split in 2. Left side is a textcontrol where logging will end up. All text will be appended to the textcontrol. Ideally this should
allow html tags but the wxHtmlWindow doesn't seem to support just adding
text. Only workaround that i can think off is to maintain a list of message myself
and then i could set those every time something changes but i don't really
like this as on every change, the whole textcontrol will be refilled.
The reason for html is to easily adjust text from one colour to another and for
instance some basic formatting like bold, italic etc.
Any ideas?

2) (view with for instance with courier)
-----------------------------------------------
| TextControl | ________ |
| ||________| Combobox |
| | |
| | ________ |
| ||________| |
| | |
| | ________ |
| ||________| Textcontrol |
| | |
-----------------------------------------------

Basically i have a number of button left-aligned in the right part of the
split window and
they are placed vertically with a small gap in between (border). This is
working but then
i would want to add a combobox next to button 1 and saya textcontrol to
button 2.
A gridresizer would work if i would be able to specify what row and column
the component
would have to be in but there doesn't seem to be such a method.
Only sollution i can think of is adding the coordinates of where i want to component to come.
Is there another sollution as i read that it's best not to add components by specifying an x
and y value.

Thanks

============== Working snippet below =======================
from wxPython.wx import *
import sys, os

ID_ABOUT=100
ID_EXIT=101

ID_BUTTON_CONNECT=200
ID_BUTTON_CHECK=201
ID_BUTTON_CONNECTIONS=202
ID_BUTTON_SEND=203
ID_BUTTON_HELP=204
ID_BUTTON_EXIT=205

class MainWindow(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self,parent,id,title, style=wxDEFAULT_FRAME_STYLE| wxNO_FULL_REPAINT_ON_RESIZE)

self.split_window = wxSplitterWindow(self, -1)
self.button_pane = wxPanel(self.split_window, -1,
style=wxTAB_TRAVERSAL|wxNO_FULL_REPAINT_ON_RESIZE)

self.logging_screen = wxTextCtrl(self.split_window, -1, "",
style=wxTE_MULTILINE|wxHSCROLL)
#self.html_window = new wxHtmlWindow( self )

self.connect = wxButton(self.button_pane, ID_BUTTON_CONNECT,
"connect")
self.check = wxButton(self.button_pane, ID_BUTTON_CHECK, "check")
self.connections = wxButton(self.button_pane, ID_BUTTON_CONNECTIONS, "connections")
self.send = wxButton(self.button_pane, ID_BUTTON_SEND, "send")
self.help = wxButton(self.button_pane, ID_BUTTON_HELP, "help")
self.exit = wxButton(self.button_pane, ID_BUTTON_EXIT, "exit")

#make the combobox for the connections
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
#'this is a long item that needs a scrollbar...',
'six', 'seven', 'eight']

self.cb = wxComboBox(
self.button_pane, 500, "default value", (90, 50),
(95, -1), sampleList, wxCB_DROPDOWN #|wxTE_PROCESS_ENTER
)

# Menu Bar
self.frame_1_menubar = wxMenuBar()
self.SetMenuBar(self.frame_1_menubar)
self.File = wxMenu()
self.File.Append( ID_ABOUT, "&About", "About CheckServer Client" )
self.File.AppendSeparator()
self.File.Append( ID_EXIT, "E&xit", "Leave the application" )
self.frame_1_menubar.Append(self.File, "F&ile")
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.OnExit)

# Menu Bar end

self.statusbar = self.CreateStatusBar(1, wxST_SIZEGRIP)

self.__set_properties()
self.__do_layout()
self.Show(true)

# end wxGlade

def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("CheckServer Client")

_icon = wxEmptyIcon()
_icon.CopyFromBitmap(wxBitmap("D:\\temp\\1anipt1c. gif",
wxBITMAP_TYPE_ANY))
self.SetIcon(_icon)
self.SetSize((723, 533))
self.SetFocus()

self.logging_screen.SetBackgroundColour(wxColour(2 47, 255, 159))
self.logging_screen.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Century Gothic"))
self.logging_screen.SetToolTipString("Here you'll see the result of the commands you issue to the server")
self.logging_screen.SetDefaultStyle(wxTextAttr(wxC olour(255,0,0)))
self.logging_screen.AppendText("Red text\n");
self.logging_screen.AppendText("<span>Test</span>\n");
self.logging_screen.Enable(0)

self.connect.SetSize((110, 28))
self.connect.SetBackgroundColour(wxColour(143, 188, 143))
self.connect.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.connect.SetToolTipString("Connect to a server")
self.connect.SetFocus()

self.check.SetSize((110, 28))
self.check.SetBackgroundColour(wxColour(143, 188, 143))
self.check.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.check.SetToolTipString("Check server directories")
self.check.Enable(0)

self.connections.SetSize((110, 28))
self.connections.SetBackgroundColour(wxColour(143, 188, 143))
self.connections.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial Black"))
self.connections.SetToolTipString("What connections are active")
self.connections.Enable(0)

self.send.SetSize((110, 28))
self.send.SetBackgroundColour(wxColour(143, 188, 143))
self.send.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial Black"))
self.send.SetToolTipString("Send a file from the server to local
pc")
self.send.Enable(0)

self.help.SetSize((110, 28))
self.help.SetBackgroundColour(wxColour(143, 188, 143))
self.help.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial Black"))
self.help.SetToolTipString("Display help options (command line)")

self.exit.SetSize((110, 28))
self.exit.SetBackgroundColour(wxColour(143, 188, 143))
self.exit.SetFont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial Black"))
self.exit.SetToolTipString("Exit the application")

self.button_pane.SetFocus()
self.button_pane.SetBackgroundColour(wxBLUE)
self.statusbar.SetStatusWidths([-1])
self.split_window.SetMinimumPaneSize(20)

# statusbar fields
statusbar_fields = ["CheckServer"]
for i in range(len(statusbar_fields)):
self.statusbar.SetStatusText(statusbar_fields[i], i)

# end wxGlade

def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
split_window_sizer = wxBoxSizer(wxVERTICAL)

button_pane_sizer = wxBoxSizer(wxVERTICAL)
button_pane_sizer.Add(self.connect, 0, wxALL, 2)
button_pane_sizer.Add(self.check, 0, wxALL, 2)
button_pane_sizer.Add(self.connections, 0, wxALL, 2)
button_pane_sizer.Add(self.send, 0, wxALL, 2)
button_pane_sizer.Add(self.help, 0, wxALL, 2)
button_pane_sizer.Add(self.exit, 0, wxALL, 2)
button_pane_sizer.Add(self.cb,0, wxALL, 2)
self.button_pane.SetAutoLayout(1)
self.button_pane.SetSizer(button_pane_sizer)
button_pane_sizer.Fit(self.button_pane)
button_pane_sizer.SetSizeHints(self.button_pane)
self.split_window.SplitVertically(self.logging_scr een,
self.button_pane)
split_window_sizer.Add(self.split_window, 1, wxEXPAND, 0)
self.SetAutoLayout(1)
self.SetSizer(split_window_sizer)
self.Layout()
self.Centre()
# end wxGlade

def OnAbout(self,e):
d= wxMessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor", wxOK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.

def OnExit(self,e):
self.Close(true) # Close the frame.

# end of class MyFrame
class App(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
main_window = MainWindow(None, -1, "CheckServer Client")
self.SetTopWindow(main_window)
return true

# end of class App

app = App(0)
app.MainLoop()

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.