kopia lustrzana https://github.com/fellesverkstedet/fabmodules
171 wiersze
4.6 KiB
Python
Executable File
171 wiersze
4.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
# fab
|
|
# GUI wrapper wrapper
|
|
#
|
|
# Neil Gershenfeld
|
|
# CBA MIT
|
|
date = "10/4/13"
|
|
#
|
|
# (c) Massachusetts Institute of Technology 2012
|
|
# Permission granted for experimental and personal use;
|
|
# license for commercial sale available from MIT.
|
|
#
|
|
# imports
|
|
#
|
|
import wx, sys, os, os.path
|
|
from fab_mods import set_workflows
|
|
#
|
|
# defaults
|
|
#
|
|
input_file = '""'
|
|
size = '400'
|
|
#
|
|
# command line
|
|
#
|
|
print "command line: fab [input_file [size]]"
|
|
print " input_file = input file (optional)"
|
|
print " size = image panel size (optional)"
|
|
#
|
|
# start wx
|
|
#
|
|
app = wx.App()
|
|
#
|
|
# set up frame
|
|
#
|
|
frame = wx.Frame(None, -1, 'fab')
|
|
frame_sizer = wx.GridBagSizer(10,10)
|
|
frame.SetSizer(frame_sizer)
|
|
bold_font = wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.BOLD)
|
|
#
|
|
# quit routine
|
|
#
|
|
def quit(event):
|
|
sys.exit()
|
|
#
|
|
# labels
|
|
#
|
|
format_text = wx.StaticText(frame,label="from format:")
|
|
format_text.SetFont(bold_font)
|
|
frame_sizer.Add(format_text,(0,0),flag=(wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL))
|
|
#
|
|
process_text = wx.StaticText(frame,label="to process:")
|
|
process_text.SetFont(bold_font)
|
|
frame_sizer.Add(process_text,(0,1),flag=(wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL))
|
|
#
|
|
program_text = wx.StaticText(frame,label="with program:")
|
|
program_text.SetFont(bold_font)
|
|
frame_sizer.Add(program_text,(0,2),flag=(wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL))
|
|
#
|
|
# menu event handler
|
|
#
|
|
def handler(event):
|
|
selected_format = frame.formats.GetValue()
|
|
selected_process = frame.processes.GetValue()
|
|
if ((selected_format == "format") | (selected_process == "process")):
|
|
return
|
|
key = selected_format + ' : ' + selected_process
|
|
if workflows.has_key(key):
|
|
frame.program = workflows[key]
|
|
frame.programs.SetLabel(frame.program)
|
|
frame.Layout()
|
|
frame.Fit()
|
|
else:
|
|
frame.program = ""
|
|
frame.programs.SetLabel("not defined")
|
|
frame.Layout()
|
|
frame.Fit()
|
|
#
|
|
# program call
|
|
#
|
|
frame.program = ""
|
|
def call_program(event):
|
|
if (frame.program != ""):
|
|
command = frame.program + ' ' + input_file + ' ' + size_control.GetValue() + '&'
|
|
print command
|
|
os.system(command)
|
|
#
|
|
# menus
|
|
#
|
|
frame.formats = wx.ComboBox(frame,value='format',style=wx.CB_READONLY)
|
|
frame.formats.Bind(wx.EVT_COMBOBOX,handler)
|
|
frame_sizer.Add(frame.formats,(1,0))
|
|
#
|
|
frame.processes = wx.ComboBox(frame,value='process',style=wx.CB_READONLY)
|
|
frame.processes.Bind(wx.EVT_COMBOBOX,handler)
|
|
frame_sizer.Add(frame.processes,(1,1))
|
|
#
|
|
frame.programs = wx.Button(frame,label='program')
|
|
frame.programs.Bind(wx.EVT_BUTTON,call_program)
|
|
frame_sizer.Add(frame.programs,(1,2),flag=(wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL))
|
|
#
|
|
# set workflows
|
|
#
|
|
workflows = {}
|
|
formats = []
|
|
set_workflows(frame,formats,workflows)
|
|
#
|
|
# controls
|
|
#
|
|
control_panel = wx.Panel(frame)
|
|
control_sizer = wx.GridBagSizer(10,10)
|
|
control_panel.SetSizer(control_sizer)
|
|
#
|
|
control_sizer.Add(wx.StaticText(control_panel,label=' GUI size (pixels):'),(0,0),flag=(wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL))
|
|
#
|
|
size_control = wx.TextCtrl(control_panel,-1,size)
|
|
control_sizer.Add(size_control,(0,1),flag=(wx.ALIGN_LEFT))
|
|
#
|
|
control_sizer.Add(wx.StaticText(control_panel,label="fab modules version: "+date),(0,2),flag=(wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL))
|
|
#
|
|
d = 4
|
|
w = 1
|
|
l = 6*d+2*w
|
|
def logo_paint(event):
|
|
dc = wx.PaintDC(logo_panel)
|
|
dc.SetBrush(wx.Brush('white'))
|
|
dc.SetPen(wx.Pen('white', 0))
|
|
dc.DrawRectangleRect((0, 0, l, l))
|
|
dc.SetBrush(wx.Brush('red'))
|
|
dc.DrawCircle(d,d,d)
|
|
dc.DrawCircle(3*d+w,3*d+w,d)
|
|
dc.SetBrush(wx.Brush('blue'))
|
|
dc.DrawRectangleRect((2*d+w,0,2*d,2*d))
|
|
dc.DrawRectangleRect((4*d+2*w,0,2*d,2*d))
|
|
dc.DrawRectangleRect((0,2*d+w,2*d,2*d))
|
|
dc.DrawRectangleRect((4*d+2*w,2*d+w,2*d,2*d))
|
|
dc.DrawRectangleRect((0,4*d+2*w,2*d,2*d))
|
|
dc.DrawRectangleRect((2*d+w,4*d+2*w,2*d,2*d))
|
|
dc.DrawRectangleRect((4*d+2*w,4*d+2*w,2*d,2*d))
|
|
logo_panel = wx.Panel(control_panel,size=(l,l))
|
|
logo_panel.Bind(wx.EVT_PAINT,logo_paint)
|
|
control_sizer.Add(logo_panel,(0,3))
|
|
#
|
|
control_quit = wx.Button(control_panel,label='quit')
|
|
control_quit.Bind(wx.EVT_BUTTON,quit)
|
|
control_sizer.Add(control_quit,(0,4))
|
|
#
|
|
control_sizer.Add(wx.StaticText(control_panel,label=" "),(0,5),flag=(wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL))
|
|
#
|
|
control_panel.Fit()
|
|
frame_sizer.Add(control_panel,(2,0),span=(1,3),flag=wx.ALIGN_CENTER_HORIZONTAL)
|
|
#
|
|
# fit and show frame
|
|
#
|
|
frame.Fit()
|
|
frame.Show()
|
|
#
|
|
# process command line
|
|
#
|
|
if (len(sys.argv) > 1):
|
|
input_file = sys.argv[1]
|
|
ext = os.path.splitext(input_file)[1]
|
|
if (formats.count(ext) != 0):
|
|
frame.formats.SetSelection(formats.index(ext))
|
|
if (len(sys.argv) > 2):
|
|
size = sys.argv[2]
|
|
#
|
|
# start mainloop
|
|
#
|
|
app.MainLoop()
|