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_CONNE CT=200
ID_BUTTON_CHECK =201
ID_BUTTON_CONNE CTIONS=202
ID_BUTTON_SEND= 203
ID_BUTTON_HELP= 204
ID_BUTTON_EXIT= 205
class MainWindow(wxFr ame):
def __init__(self, parent, id, title):
wxFrame.__init_ _(self,parent,i d,title, style=wxDEFAULT _FRAME_STYLE|
wxNO_FULL_REPAI NT_ON_RESIZE)
self.split_wind ow = wxSplitterWindo w(self, -1)
self.button_pan e = wxPanel(self.sp lit_window, -1,
style=wxTAB_TRA VERSAL|wxNO_FUL L_REPAINT_ON_RE SIZE)
self.logging_sc reen = wxTextCtrl(self .split_window, -1, "",
style=wxTE_MULT ILINE|wxHSCROLL )
#self.html_wind ow = new wxHtmlWindow( self )
self.connect = wxButton(self.b utton_pane, ID_BUTTON_CONNE CT,
"connect")
self.check = wxButton(self.b utton_pane, ID_BUTTON_CHECK , "check")
self.connection s = wxButton(self.b utton_pane, ID_BUTTON_CONNE CTIONS,
"connection s")
self.send = wxButton(self.b utton_pane, ID_BUTTON_SEND, "send")
self.help = wxButton(self.b utton_pane, ID_BUTTON_HELP, "help")
self.exit = wxButton(self.b utton_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_pan e, 500, "default value", (90, 50),
(95, -1), sampleList, wxCB_DROPDOWN #|wxTE_PROCESS_ ENTER
)
# Menu Bar
self.frame_1_me nubar = wxMenuBar()
self.SetMenuBar (self.frame_1_m enubar)
self.File = wxMenu()
self.File.Appen d( ID_ABOUT, "&About", "About CheckServer Client" )
self.File.Appen dSeparator()
self.File.Appen d( ID_EXIT, "E&xit", "Leave the application" )
self.frame_1_me nubar.Append(se lf.File, "F&ile")
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.OnExit)
# Menu Bar end
self.statusbar = self.CreateStat usBar(1, wxST_SIZEGRIP)
self.__set_prop erties()
self.__do_layou t()
self.Show(true)
# end wxGlade
def __set_propertie s(self):
# begin wxGlade: MyFrame.__set_p roperties
self.SetTitle(" CheckServer Client")
_icon = wxEmptyIcon()
_icon.CopyFromB itmap(wxBitmap( "D:\\temp\\1ani pt1c.gif",
wxBITMAP_TYPE_A NY))
self.SetIcon(_i con)
self.SetSize((7 23, 533))
self.SetFocus()
self.logging_sc reen.SetBackgro undColour(wxCol our(247, 255, 159))
self.logging_sc reen.SetFont(wx Font(10, wxMODERN, wxNORMAL, wxNORMAL,
0, "Century Gothic"))
self.logging_sc reen.SetToolTip String("Here you'll see the result of
the commands you issue to the server")
self.logging_sc reen.SetDefault Style(wxTextAtt r(wxColour(255, 0,0)))
self.logging_sc reen.AppendText ("Red text\n");
self.logging_sc reen.AppendText ("<span>Test </span>\n");
self.logging_sc reen.Enable(0)
self.connect.Se tSize((110, 28))
self.connect.Se tBackgroundColo ur(wxColour(143 , 188, 143))
self.connect.Se tFont(wxFont(10 , wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.connect.Se tToolTipString( "Connect to a server")
self.connect.Se tFocus()
self.check.SetS ize((110, 28))
self.check.SetB ackgroundColour (wxColour(143, 188, 143))
self.check.SetF ont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.check.SetT oolTipString("C heck server directories")
self.check.Enab le(0)
self.connection s.SetSize((110, 28))
self.connection s.SetBackground Colour(wxColour (143, 188, 143))
self.connection s.SetFont(wxFon t(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.connection s.SetToolTipStr ing("What connections are active")
self.connection s.Enable(0)
self.send.SetSi ze((110, 28))
self.send.SetBa ckgroundColour( wxColour(143, 188, 143))
self.send.SetFo nt(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.send.SetTo olTipString("Se nd a file from the server to local
pc")
self.send.Enabl e(0)
self.help.SetSi ze((110, 28))
self.help.SetBa ckgroundColour( wxColour(143, 188, 143))
self.help.SetFo nt(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.help.SetTo olTipString("Di splay help options (command line)")
self.exit.SetSi ze((110, 28))
self.exit.SetBa ckgroundColour( wxColour(143, 188, 143))
self.exit.SetFo nt(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.exit.SetTo olTipString("Ex it the application")
self.button_pan e.SetFocus()
self.button_pan e.SetBackground Colour(wxBLUE)
self.statusbar. SetStatusWidths ([-1])
self.split_wind ow.SetMinimumPa neSize(20)
# statusbar fields
statusbar_field s = ["CheckServe r"]
for i in range(len(statu sbar_fields)):
self.statusbar. SetStatusText(s tatusbar_fields[i], i)
# end wxGlade
def __do_layout(sel f):
# begin wxGlade: MyFrame.__do_la yout
split_window_si zer = wxBoxSizer(wxVE RTICAL)
button_pane_siz er = wxBoxSizer(wxVE RTICAL)
button_pane_siz er.Add(self.con nect, 0, wxALL, 2)
button_pane_siz er.Add(self.che ck, 0, wxALL, 2)
button_pane_siz er.Add(self.con nections, 0, wxALL, 2)
button_pane_siz er.Add(self.sen d, 0, wxALL, 2)
button_pane_siz er.Add(self.hel p, 0, wxALL, 2)
button_pane_siz er.Add(self.exi t, 0, wxALL, 2)
button_pane_siz er.Add(self.cb, 0, wxALL, 2)
self.button_pan e.SetAutoLayout (1)
self.button_pan e.SetSizer(butt on_pane_sizer)
button_pane_siz er.Fit(self.but ton_pane)
button_pane_siz er.SetSizeHints (self.button_pa ne)
self.split_wind ow.SplitVertica lly(self.loggin g_screen,
self.button_pan e)
split_window_si zer.Add(self.sp lit_window, 1, wxEXPAND, 0)
self.SetAutoLay out(1)
self.SetSizer(s plit_window_siz er)
self.Layout()
self.Centre()
# end wxGlade
def OnAbout(self,e) :
d= wxMessageDialog ( self, " A sample editor \n"
" in wxPython","Abou t 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):
wxInitAllImageH andlers()
main_window = MainWindow(None , -1, "CheckServe r Client")
self.SetTopWind ow(main_window)
return true
# end of class App
app = App(0)
app.MainLoop()
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_CONNE CT=200
ID_BUTTON_CHECK =201
ID_BUTTON_CONNE CTIONS=202
ID_BUTTON_SEND= 203
ID_BUTTON_HELP= 204
ID_BUTTON_EXIT= 205
class MainWindow(wxFr ame):
def __init__(self, parent, id, title):
wxFrame.__init_ _(self,parent,i d,title, style=wxDEFAULT _FRAME_STYLE|
wxNO_FULL_REPAI NT_ON_RESIZE)
self.split_wind ow = wxSplitterWindo w(self, -1)
self.button_pan e = wxPanel(self.sp lit_window, -1,
style=wxTAB_TRA VERSAL|wxNO_FUL L_REPAINT_ON_RE SIZE)
self.logging_sc reen = wxTextCtrl(self .split_window, -1, "",
style=wxTE_MULT ILINE|wxHSCROLL )
#self.html_wind ow = new wxHtmlWindow( self )
self.connect = wxButton(self.b utton_pane, ID_BUTTON_CONNE CT,
"connect")
self.check = wxButton(self.b utton_pane, ID_BUTTON_CHECK , "check")
self.connection s = wxButton(self.b utton_pane, ID_BUTTON_CONNE CTIONS,
"connection s")
self.send = wxButton(self.b utton_pane, ID_BUTTON_SEND, "send")
self.help = wxButton(self.b utton_pane, ID_BUTTON_HELP, "help")
self.exit = wxButton(self.b utton_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_pan e, 500, "default value", (90, 50),
(95, -1), sampleList, wxCB_DROPDOWN #|wxTE_PROCESS_ ENTER
)
# Menu Bar
self.frame_1_me nubar = wxMenuBar()
self.SetMenuBar (self.frame_1_m enubar)
self.File = wxMenu()
self.File.Appen d( ID_ABOUT, "&About", "About CheckServer Client" )
self.File.Appen dSeparator()
self.File.Appen d( ID_EXIT, "E&xit", "Leave the application" )
self.frame_1_me nubar.Append(se lf.File, "F&ile")
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.OnExit)
# Menu Bar end
self.statusbar = self.CreateStat usBar(1, wxST_SIZEGRIP)
self.__set_prop erties()
self.__do_layou t()
self.Show(true)
# end wxGlade
def __set_propertie s(self):
# begin wxGlade: MyFrame.__set_p roperties
self.SetTitle(" CheckServer Client")
_icon = wxEmptyIcon()
_icon.CopyFromB itmap(wxBitmap( "D:\\temp\\1ani pt1c.gif",
wxBITMAP_TYPE_A NY))
self.SetIcon(_i con)
self.SetSize((7 23, 533))
self.SetFocus()
self.logging_sc reen.SetBackgro undColour(wxCol our(247, 255, 159))
self.logging_sc reen.SetFont(wx Font(10, wxMODERN, wxNORMAL, wxNORMAL,
0, "Century Gothic"))
self.logging_sc reen.SetToolTip String("Here you'll see the result of
the commands you issue to the server")
self.logging_sc reen.SetDefault Style(wxTextAtt r(wxColour(255, 0,0)))
self.logging_sc reen.AppendText ("Red text\n");
self.logging_sc reen.AppendText ("<span>Test </span>\n");
self.logging_sc reen.Enable(0)
self.connect.Se tSize((110, 28))
self.connect.Se tBackgroundColo ur(wxColour(143 , 188, 143))
self.connect.Se tFont(wxFont(10 , wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.connect.Se tToolTipString( "Connect to a server")
self.connect.Se tFocus()
self.check.SetS ize((110, 28))
self.check.SetB ackgroundColour (wxColour(143, 188, 143))
self.check.SetF ont(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.check.SetT oolTipString("C heck server directories")
self.check.Enab le(0)
self.connection s.SetSize((110, 28))
self.connection s.SetBackground Colour(wxColour (143, 188, 143))
self.connection s.SetFont(wxFon t(10, wxMODERN, wxNORMAL, wxNORMAL, 0,
"Arial Black"))
self.connection s.SetToolTipStr ing("What connections are active")
self.connection s.Enable(0)
self.send.SetSi ze((110, 28))
self.send.SetBa ckgroundColour( wxColour(143, 188, 143))
self.send.SetFo nt(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.send.SetTo olTipString("Se nd a file from the server to local
pc")
self.send.Enabl e(0)
self.help.SetSi ze((110, 28))
self.help.SetBa ckgroundColour( wxColour(143, 188, 143))
self.help.SetFo nt(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.help.SetTo olTipString("Di splay help options (command line)")
self.exit.SetSi ze((110, 28))
self.exit.SetBa ckgroundColour( wxColour(143, 188, 143))
self.exit.SetFo nt(wxFont(10, wxMODERN, wxNORMAL, wxNORMAL, 0, "Arial
Black"))
self.exit.SetTo olTipString("Ex it the application")
self.button_pan e.SetFocus()
self.button_pan e.SetBackground Colour(wxBLUE)
self.statusbar. SetStatusWidths ([-1])
self.split_wind ow.SetMinimumPa neSize(20)
# statusbar fields
statusbar_field s = ["CheckServe r"]
for i in range(len(statu sbar_fields)):
self.statusbar. SetStatusText(s tatusbar_fields[i], i)
# end wxGlade
def __do_layout(sel f):
# begin wxGlade: MyFrame.__do_la yout
split_window_si zer = wxBoxSizer(wxVE RTICAL)
button_pane_siz er = wxBoxSizer(wxVE RTICAL)
button_pane_siz er.Add(self.con nect, 0, wxALL, 2)
button_pane_siz er.Add(self.che ck, 0, wxALL, 2)
button_pane_siz er.Add(self.con nections, 0, wxALL, 2)
button_pane_siz er.Add(self.sen d, 0, wxALL, 2)
button_pane_siz er.Add(self.hel p, 0, wxALL, 2)
button_pane_siz er.Add(self.exi t, 0, wxALL, 2)
button_pane_siz er.Add(self.cb, 0, wxALL, 2)
self.button_pan e.SetAutoLayout (1)
self.button_pan e.SetSizer(butt on_pane_sizer)
button_pane_siz er.Fit(self.but ton_pane)
button_pane_siz er.SetSizeHints (self.button_pa ne)
self.split_wind ow.SplitVertica lly(self.loggin g_screen,
self.button_pan e)
split_window_si zer.Add(self.sp lit_window, 1, wxEXPAND, 0)
self.SetAutoLay out(1)
self.SetSizer(s plit_window_siz er)
self.Layout()
self.Centre()
# end wxGlade
def OnAbout(self,e) :
d= wxMessageDialog ( self, " A sample editor \n"
" in wxPython","Abou t 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):
wxInitAllImageH andlers()
main_window = MainWindow(None , -1, "CheckServe r Client")
self.SetTopWind ow(main_window)
return true
# end of class App
app = App(0)
app.MainLoop()
Comment