Skip to content

Instantly share code, notes, and snippets.

@driscollis
Created April 18, 2019 21:12
Show Gist options
  • Save driscollis/3ce409c357529cf2304760e537ec919b to your computer and use it in GitHub Desktop.
Save driscollis/3ce409c357529cf2304760e537ec919b to your computer and use it in GitHub Desktop.
import wx
class MyTree(wx.TreeCtrl):
def __init__(self, parent, id, pos, size, style):
wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
class TreePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
main_sizer = wx.BoxSizer(wx.VERTICAL)
self.tree = MyTree(self, wx.ID_ANY, wx.DefaultPosition,
wx.DefaultSize,
wx.TR_HAS_BUTTONS)
self.root = self.tree.AddRoot('Your Websites')
main_sizer.Add(self.tree, 1, wx.EXPAND | wx.ALL, 5)
new_site = wx.Button(self, label='New Site')
new_site.Bind(wx.EVT_BUTTON, self.on_new_site)
main_sizer.Add(new_site, 0, wx.ALL, 5)
self.SetSizer(main_sizer)
def on_new_site(self, event):
item = self.tree.AppendItem(self.root, 'New site')
self.tree.Expand(self.root)
self.tree.EditLabel(item)
class GeneralPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent)
main_sizer = wx.BoxSizer(wx.VERTICAL)
host_sizer = wx.BoxSizer()
lbl_size = (100, -1)
host_lbl = wx.StaticText(self, label='Host:', size=lbl_size)
host_sizer.Add(host_lbl, 0, wx.ALL | wx.CENTER, 5)
self.host = wx.TextCtrl(self)
host_sizer.Add(self.host, 1, wx.ALL | wx.EXPAND, 5)
port_lbl = wx.StaticText(self, label='Port:')
host_sizer.Add(port_lbl, 0, wx.ALL | wx.CENTER, 5)
self.port = wx.TextCtrl(self, size=(50, -1))
host_sizer.Add(self.port, 0, wx.ALL, 5)
main_sizer.Add(host_sizer, 0, wx.EXPAND)
user_sizer = wx.BoxSizer()
user_lbl = wx.StaticText(self, label='User:', size=lbl_size)
user_sizer.Add(user_lbl, 0, wx.ALL | wx.CENTER, 5)
self.user = wx.TextCtrl(self)
user_sizer.Add(self.user, 1, wx.ALL | wx.EXPAND, 5)
main_sizer.Add(user_sizer, 0, wx.EXPAND)
pw_sizer = wx.BoxSizer()
pw_lbl = wx.StaticText(self, label='Password:', size=lbl_size)
pw_sizer.Add(pw_lbl, 0, wx.ALL | wx.CENTER, 5)
self.password = wx.TextCtrl(self, style=wx.TE_PASSWORD)
pw_sizer.Add(self.password, 1, wx.ALL | wx.EXPAND, 5)
main_sizer.Add(pw_sizer, 0, wx.EXPAND)
self.SetSizer(main_sizer)
class MainPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent)
self.create_ui()
def create_ui(self):
"""
Create the XML editor widgets
"""
page_sizer = wx.BoxSizer(wx.VERTICAL)
splitter = wx.SplitterWindow(self)
self.tree_panel = TreePanel(splitter)
notebook = wx.Notebook(splitter)
general_panel = GeneralPanel(notebook)
notebook.AddPage(general_panel, 'General')
splitter.SplitVertically(self.tree_panel, notebook)
splitter.SetMinimumPaneSize(400)
page_sizer.Add(splitter, 1, wx.ALL|wx.EXPAND, 5)
line = wx.StaticLine(self)
page_sizer.Add(line, 0, wx.EXPAND)
connect_btn = wx.Button(self, label='Connect')
page_sizer.Add(connect_btn, 0, wx.ALL | wx.CENTER, 5)
self.SetSizer(page_sizer)
self.Layout()
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, title='Site Manager',
size=(800, 600))
panel = MainPanel(self)
self.Show()
if __name__ == '__main__':
app = wx.App(redirect=False)
frame = MainFrame()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment