Browse Source

Added file/Calendar/DirChooser implementations

pull/61/head
chriskiehl 10 years ago
parent
commit
a9c763ec58
5 changed files with 264 additions and 14 deletions
  1. 140
      gooey/gui/Chooser.py
  2. 25
      gooey/gui/ChooserRunner.py
  3. 44
      gooey/gui/calender_dialog.py
  4. 17
      gooey/gui/components.py
  5. 52
      gooey/mockapplications/qwindelzorf _example.py

140
gooey/gui/Chooser.py

@ -0,0 +1,140 @@
__author__ = 'Chris'
import wx
import styling
from calender_dialog import CalendarDlg
class AbstractChooser(object):
def __init__(self, data):
self.data = data
# parent
self.panel = None
self.button_text = 'Browse'
# Widgets
self.title = None
self.help_msg = None
self.text_box = None
self.button = None
self.panel = None
def build(self, parent):
return self.do_layout(parent)
def do_layout(self, parent):
self.panel = wx.Panel(parent)
self.title = self.CreateNameLabelWidget(self.panel)
self.help_msg = self.CreateHelpMsgWidget(self.panel)
self.text_box = wx.TextCtrl(self.panel)
self.button = wx.Button(self.panel, label=self.button_text, size=(73, 23))
vertical_container = wx.BoxSizer(wx.VERTICAL)
widget_sizer = wx.BoxSizer(wx.HORIZONTAL)
vertical_container.Add(self.title)
vertical_container.AddSpacer(2)
if self.help_msg.GetLabelText():
vertical_container.Add(self.help_msg, 1, wx.EXPAND)
vertical_container.AddSpacer(2)
else:
vertical_container.AddStretchSpacer(1)
widget_sizer.Add(self.text_box, 1, wx.EXPAND)
widget_sizer.AddSpacer(10)
widget_sizer.Add(self.button, 0)
vertical_container.Add(widget_sizer, 0, wx.EXPAND)
self.panel.SetSizer(vertical_container)
self.panel.Bind(wx.EVT_SIZE, self.OnResize)
self.panel.Bind(wx.EVT_BUTTON, self.on_button, self.button)
return self.panel
def CreateHelpMsgWidget(self, parent):
base_text = wx.StaticText(parent, label=self.data['help_msg'])
# if self.data['nargs']:
# base_text.SetLabelText(base_text.GetLabelText() + self.CreateNargsMsg(action))
styling.MakeDarkGrey(base_text)
return base_text
def CreateNameLabelWidget(self, parent):
label = self.data['title'].title()
text = wx.StaticText(parent, label=label)
styling.MakeBold(text)
return text
def OnResize(self, evt):
if self.help_msg is None:
return
container_width, _ = self.panel.Size
text_width, _ = self.help_msg.Size
if text_width != container_width:
self.help_msg.SetLabel(self.help_msg.GetLabelText().replace('\n', ' '))
self.help_msg.Wrap(container_width)
evt.Skip()
def on_button(self, evt):
raise NotImplementedError
class FileChooser(AbstractChooser):
def __init__(self, data):
AbstractChooser.__init__(self, data)
def on_button(self, evt):
dlg = wx.FileDialog(self.panel, style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
result = (dlg.GetPath()
if dlg.ShowModal() == wx.ID_OK
else None)
if result:
self.text_box.SetLabelText(result)
class DirectoryChooser(AbstractChooser):
def __init__(self, data):
AbstractChooser.__init__(self, data)
def on_button(self, evt):
dlg = wx.DirDialog(self.panel, 'Select directory', style=wx.DD_DEFAULT_STYLE)
result = (dlg.GetPath()
if dlg.ShowModal() == wx.ID_OK
else None)
if result:
self.text_box.SetLabelText(result)
class CalendarChooser(AbstractChooser):
def __init__(self, data):
AbstractChooser.__init__(self, data)
self.button_text = 'Choose Date'
def on_button(self, evt):
dlg = CalendarDlg(self.panel)
dlg.ShowModal()
if dlg.GetPath():
self.text_box.SetLabelText(dlg.GetPath())

25
gooey/gui/ChooserRunner.py

@ -0,0 +1,25 @@
__author__ = 'Chris'
import wx
from wx.lib import wordwrap
from Chooser import FileChooser, DirectoryChooser, CalendarChooser
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="test", size=(320, 240))
self.SetBackgroundColour('#ffffff')
sizer = wx.BoxSizer(wx.VERTICAL)
f = CalendarChooser({'title':'cool title', 'help_msg':'cool help msg that is super long and intense and has lots of words!', 'nargs': '+'})
sizer.Add(f.build(self), 0, wx.EXPAND)
self.SetSizer(sizer)
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None)
frame.Show(True)
app.MainLoop()

44
gooey/gui/calender_dialog.py

@ -0,0 +1,44 @@
__author__ = 'Chris'
import wx
import styling
class CalendarDlg(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.SetBackgroundColour('#ffffff')
self.ok_button = wx.Button(self, label='Ok')
self.datepicker = wx.DatePickerCtrl(self, style=wx.DP_DROPDOWN)
vertical_container = wx.BoxSizer(wx.VERTICAL)
vertical_container.AddSpacer(10)
vertical_container.Add(styling.H1(self, label='Select a Date'), 0, wx.LEFT | wx.RIGHT, 15)
vertical_container.AddSpacer(10)
vertical_container.Add(self.datepicker, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 15)
vertical_container.AddSpacer(10)
button_sizer = wx.BoxSizer(wx.HORIZONTAL)
button_sizer.AddStretchSpacer(1)
button_sizer.Add(self.ok_button, 0)
vertical_container.Add(button_sizer, 0, wx.LEFT | wx.RIGHT, 15)
vertical_container.AddSpacer(20)
self.SetSizerAndFit(vertical_container)
self.Bind(wx.EVT_BUTTON, self.OnOkButton, self.ok_button)
def OnOkButton(self, event):
self.Close()
return wx.ID_OK
def OnCancellButton(self, event):
try:
return None
except:
self.Close()
def GetPath(self):
return str(self.datepicker.GetValue()).split(' ')[0]

17
gooey/gui/components.py

@ -58,9 +58,11 @@ class AbstractComponent(object):
''' Must construct the main widget type for the Action ''' ''' Must construct the main widget type for the Action '''
pass pass
def HasHelpMsg(self, action): def HasHelpMsg(self, action):
return action.help is not None return action.help is not None
def CreateHelpMsgWidget(self, parent, action): def CreateHelpMsgWidget(self, parent, action):
base_text = wx.StaticText(parent, label=action.help) base_text = wx.StaticText(parent, label=action.help)
if self.HasNargs(action): if self.HasNargs(action):
@ -88,18 +90,22 @@ class AbstractComponent(object):
styling.MakeBold(text) styling.MakeBold(text)
return text return text
def AssertInitialization(self, clsname): def AssertInitialization(self, clsname):
if not self._widget: if not self._widget:
raise BuildException('%s was not correctly initialized' % clsname) raise BuildException('%s was not correctly initialized' % clsname)
def __str__(self): def __str__(self):
return str(self._action) return str(self._action)
@abstractmethod @abstractmethod
def GetValue(self): def GetValue(self):
''' Returns the state of the given widget ''' ''' Returns the state of the given widget '''
pass pass
def Update(self, size): def Update(self, size):
''' '''
Manually word wraps the StaticText help objects which would Manually word wraps the StaticText help objects which would
@ -129,6 +135,7 @@ class AbstractComponent(object):
self._msg.Wrap(content_area) self._msg.Wrap(content_area)
class Positional(AbstractComponent): class Positional(AbstractComponent):
""" """
Represents a positional argument in a program Represents a positional argument in a program
@ -192,6 +199,7 @@ class Choice(AbstractComponent):
class Optional(AbstractComponent): class Optional(AbstractComponent):
def __init__(self, action): def __init__(self, action):
self._action = action self._action = action
self._widget = None self._widget = None
@ -323,6 +331,15 @@ class Counter(AbstractComponent):
repeated_args = arg * int(dropdown_value) repeated_args = arg * int(dropdown_value)
return '-' + repeated_args return '-' + repeated_args
class Group(AbstractComponent):
def __init__(self, action):
self._action = action
self._widget = None
self.contents = None
if __name__ == '__main__': if __name__ == '__main__':
pass pass

52
gooey/mockapplications/qwindelzorf _example.py

@ -1,25 +1,49 @@
import argparse
"""inline"""
import argparse
from gooey import Gooey from gooey import Gooey
x = '''random line'''
y = """
Buncha text here
and here
and here
and here
"""
@Gooey @Gooey
def main(): def main():
"""This is my main module"""
parser = argparse.ArgumentParser('Get my users') parser = argparse.ArgumentParser('Get my users')
parser.add_argument('-type', "--type", type=str, action='store', dest='type', help= "type Query")
parser.add_argument('-dst', "--datestart", type=str, action='store', dest='date_start', help= "from Date")
parser.add_argument('-dsp', "--datestop", type=str, action='store', dest='date_stop', help= "to Date")
parser.add_argument('-n',"--IDuser", type=str, action='store', dest='idu', help="IDuser")
parser.add_argument('-t',"--text", type=str, action='store', dest='text', help="find Text")
parser.add_argument('-f',"--file", type=str, action='store', dest='filepath', help="File Save")
verbosity = parser.add_mutually_exclusive_group()
verbosity.add_argument('-v', '--verbose', dest='verbose', action="store_true", help="Show more details")
verbosity.add_argument('-q', '--quiet', dest='quiet', action="store_true", help="Only output on error")
args = parser.parse_args() args = parser.parse_args()
query_type = args.type
date_start=args.date_start
date_stop=args.date_stop
userid=args.idu
input_data = args.text
path_to_file = args.filepath
print path_to_file
def moo(asdf):
'''single quoted inline comment'''
a = 1
def foo():
"""Double quoted inline comment """
a = 1
def bar():
"""
Double quoted
multiline comment
"""
a = 1
def baz():
'''
Double quoted
multiline comment
'''
a = 1
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Loading…
Cancel
Save