>>
I wanted to write the UI in GTK, but the manual I had was one thousand pages of pdf- which is really just impossible to use as a reference. You can't flip between pages in an e-document.
So then I thought I'd use python, but it kinda got away from me and I ended up going to do other things.
import wx
import os
import xml.etree.ElementTree as ET
def getXmlTree(var):
tree = ET.parse(var)
xmlroot = tree.getroot()
return xmlroot, tree
def fileBrowse(var):
browse = wx.FileDialog(var, "Choose a file", "", "", "", wx.FD_OPEN)
if browse.ShowModal() == wx.ID_OK:
path = browse.GetPath()
browse.Destroy()
return path
def MonitorInfoFunc():
if wx.Display.GetCount() > 1:
for i in range(wx.Display.GetCount()):
display = wx.Display(i)
if display.IsPrimary():
_, _, width, height = display.GetGeometry()
else:
width, height = wx.GetDisplaySize()
return(width, height)
GlobalXmlFile = str('myface_account_0.01.xml')
GlobalXmlRoot, GlobalXmlTree = getXmlTree(GlobalXmlFile)
class TextEntryDisplay(wx.Frame):
def __init__(self, *args, **kw):
super(TextEntryDisplay, self).__init__(None)
MainPanel = wx.Panel(self)
MainSizer = wx.BoxSizer(wx.VERTICAL)
TextInputPanel = wx.Panel(MainPanel)
TextInputSizer = wx.BoxSizer(wx.VERTICAL)
TextLabelWidj = wx.StaticText(TextInputPanel, -1, "Posting As $Username")
TextInputWidj = wx.TextCtrl(TextInputPanel, -1, style = wx.TE_MULTILINE)
TextInputSizer.Add(TextLabelWidj, 0)
TextInputSizer.Add(TextInputWidj, 1, wx.EXPAND)
TextInputPanel.SetSizer(TextInputSizer)
TextInputPanel.Layout()
OptInputPanel = wx.Panel(MainPanel)
OptInputSizer = wx.BoxSizer(wx.HORIZONTAL)
TitleLabelWidj = wx.StaticText(OptInputPanel, -1, "Topic:")
TitleInputWidj = wx.TextCtrl(OptInputPanel, -1)
OptInputSizer.Add(TitleLabelWidj, 0)
OptInputSizer.Add(TitleInputWidj, 0)
OptInputPanel.SetSizer(OptInputSizer)
OptInputPanel.Layout()
MainSizer.Add(TextInputPanel, 1, wx.EXPAND)
MainSizer.Add(OptInputPanel, 0)
MainPanel.SetSizer(MainSizer)
MainPanel.Layout()
#self.CenterOnScreen()
self.makeMenuBar()
self.CreateStatusBar()
def makeMenuBar(self):
fileMenu = wx.Menu()
FileAttach = fileMenu.Append(-1, "Attach Photo", "Browse")
FilePost = fileMenu.Append(-1, "Post", "Post to Front Page")
FileSave = fileMenu.Append(-1, "Save", "Save to file...")
FileLoad = fileMenu.Append(-1, "Open", "Open file here")
fileMenu.AppendSeparator()
FileExit = fileMenu.Append(wx.ID_EXIT)
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnFileAttach, FileAttach)
self.Bind(wx.EVT_MENU, self.OnFilePost, FilePost)
self.Bind(wx.EVT_MENU, self.OnFileSave, FileSave)
self.Bind(wx.EVT_MENU, self.OnFileLoad, FileLoad)
self.Bind(wx.EVT_MENU, self.OnFileExit, FileExit)
def OnFileAttach(self, event):
#Things And Stuff
"""
"""
def OnFilePost(self, event):
"""
Things
"""
Content = self.TextInputWidj.GetValue()
Title = self.TitleInputWidj.GetValue()
Author = str("namos heerski")
index = len(GlobalXmlRoot.find('threads').findall('thread'))
GlobalXmlRoot.find('threads').append(ET.SubElement(GlobalXmlRoot.find('threads'), 'thread'))
GlobalXmlRoot.find('threads')[index].append(ET.SubElement(GlobalXmlRoot.find('threads')[index], 'title'))
GlobalXmlRoot.find('threads')[index].append(ET.SubElement(GlobalXmlRoot.find('threads')[index], 'author'))
GlobalXmlRoot.find('threads')[index].append(ET.SubElement(GlobalXmlRoot.find('threads')[index], 'content'))
GlobalXmlRoot.find('threads')[index].find('title').text = Title
GlobalXmlRoot.find('threads')[index].find('author').text = Author
GlobalXmlRoot.find('threads')[index].find('content').text = Content
#GlobalXmlTree.write(GlobalXmlFile)
self.Close(True)
def OnFileSave(self, event):
"""
#yup eh
"""
def OnFileLoad(self, event):
"""
#More Things
"""
def OnFileExit(self, event):
#Hold on I got this one, it's right down....
self.Close(True)
class ProfileDisplay(wx.Frame):
def __init__(self, *args, **kw):
super(ProfileDisplay, self).__init__(*args, **kw)
self.MainPanel = wx.Panel(self)
self.MainSizer = wx.BoxSizer(wx.HORIZONTAL)
self.makeMenuBar()
self.PrepProfile()
self.PrepThreads()
self.CreateStatusBar()
self.MainSizer.Add(self.ProfilePanel, 0, wx.ALIGN_LEFT)
self.MainSizer.Add(self.ThreadsPanel, 0, wx.ALIGN_RIGHT)
self.MainPanel.SetSizer(self.MainSizer)
self.MainPanel.Layout()
def makeMenuBar(self):
fileMenu = wx.Menu()
FileOpen = fileMenu.Append(-1, "Open Profile", "Browse")
FileSave = fileMenu.Append(-1, "SaveProfile", "Browse")
FilePost = fileMenu.Append(-1, "Post To Blog", "Browse")
FilePrefs = fileMenu.Append(-1, "Preferences", "Browse")
fileMenu.AppendSeparator()
FileExit = fileMenu.Append(wx.ID_EXIT)
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnFileOpen, FileOpen)
self.Bind(wx.EVT_MENU, self.OnFileSave, FileSave)
self.Bind(wx.EVT_MENU, self.OnFilePost, FilePost)
self.Bind(wx.EVT_MENU, self.OnFilePrefs, FilePrefs)
self.Bind(wx.EVT_MENU, self.OnFileExit, FileExit)
def OnFileOpen(self, event):
"""
Loads an xml file from disk
"""
path = fileBrowse(self)
GlobalXmlRoot = getXmlTree(path)
def OnFileSave(self, event):
"""
Writes all Profile Information to xml on disk
"""
def OnFilePost(self, event):
"""
Opens a text input window
Text input window should update directly to xml
perhaps based on flags calling it. Should Generic
the text input for blogs and comments.
"""
TextInput = TextEntryDisplay(None, title = 'Hello')
TextInput.Show()
def OnFilePrefs(self, event):
"""
Opens configuration window to change specific values
like access permissions, personal info, status?, possibly some
layout management? like sliders for percentage of screen space?
Future rewrites I think...
"""
def OnFileExit(self, event):
self.Close(True)
def PrepProfile(self):
self.ProfilePanel = wx.Panel(self.MainPanel)
ProfileSizer = wx.BoxSizer(wx.VERTICAL)
Username = GlobalXmlRoot.find('profileinfo').find('name').text
ProfilePicDir = GlobalXmlRoot.find('profileinfo').find('pfp').text
#Location = xmlroot.find('profileinfo').find('location').text
Status = GlobalXmlRoot.find('profileinfo').find('status').text
ProfilePic = wx.Image(ProfilePicDir)
ProfilePicCtrl = wx.StaticBitmap(self.ProfilePanel, wx.ID_ANY, wx.Bitmap(ProfilePic))
UsernameCtrl = wx.StaticText(self.ProfilePanel, -1, Username)
StatusCtrl = wx.StaticText(self.ProfilePanel, -1, Status)
ProfileSizer.Add(ProfilePicCtrl, 0, wx.ALIGN_LEFT)
ProfileSizer.Add(UsernameCtrl, 0, wx.ALIGN_LEFT)
ProfileSizer.Add(StatusCtrl, 0, wx.ALIGN_LEFT)
self.ProfilePanel.SetSizer(ProfileSizer)
self.ProfilePanel.Layout()
def PrepThreads(self):
self.ThreadsPanel = wx.Panel(self.MainPanel)
ThreadsSizer = wx.BoxSizer(wx.VERTICAL)
"""
Need to find out how many threads there are
"""
ThreadCount = len(GlobalXmlRoot.find('threads').findall('thread'))
#self.SetStatusText(str(ThreadCount))
for i in range(ThreadCount):
ThreadPanel = wx.Panel(self.ThreadsPanel)
ThreadSizer = wx.BoxSizer(wx.VERTICAL)
Content = GlobalXmlRoot.find('threads')[i].find('content').text
Author = GlobalXmlRoot.find('threads')[i].find('author').text
Title = GlobalXmlRoot.find('threads')[i].find('title').text
ContentCtrl = wx.StaticText(ThreadPanel, -1, Content)
AuthorCtrl = wx.StaticText(ThreadPanel, -1, Author)
TitleCtrl = wx.StaticText(ThreadPanel, -1, Title)
ThreadSizer.Add(ContentCtrl, 0, wx.ALIGN_CENTER_VERTICAL)
ThreadSizer.Add(AuthorCtrl, 0, wx.ALIGN_CENTER_VERTICAL)
ThreadSizer.Add(TitleCtrl, 0, wx.ALIGN_CENTER_VERTICAL)
font = ContentCtrl.GetFont()
font.PointSize += 10
font = font.Bold()
ThreadPanel.SetSizer(ThreadSizer)
ThreadPanel.Layout()
ThreadsSizer.Add(ThreadPanel, 0)
self.ThreadsPanel.SetSizer(ThreadsSizer)
self.ThreadsPanel.Layout()
if __name__ == '__main__':
app = wx.App()
start_frame = ProfileDisplay(None, title = 'MyFace')
start_frame.Show()
app.MainLoop()