#!/usr/bin/python
# -*- coding: UTF-8 -*-
import wx
from itertools import izip
from library import i18n
_ = i18n.i18n()
class ModifyFaxData(wx.Frame):
""" Modify the fax data.
"""
def __init__(self, prnt, field_name, field_data, f_read_only, cb, order=None):
""" Pass me the dict with the data to modify and optionally the order
"""
super(ModifyFaxData, self).__init__(prnt)
if order is None:
order = sorted(field_name)
self._order = order
self._lst_txt = []
self._call_back = cb
#widget part
parent = wx.Panel(self)
sz_txt = wx.FlexGridSizer(1, 2)
sz_all = wx.BoxSizer(wx.VERTICAL)
for name, value, read_only in izip(order, field_data, f_read_only):
lbl = wx.StaticText(parent, label=field_name[name])
txt = wx.TextCtrl(parent, value=value, size=(150, -1))
if read_only:
txt.Enable(False)
self._lst_txt.append(txt)
flg = wx.ALL | wx.ALIGN_CENTER
sz_txt.Add(lbl, 0, flg, 7)
sz_txt.Add(txt, 0, flg, 7)
bt = wx.Button(parent, 0, _("bt_save"))
bt.Bind(wx.EVT_BUTTON, self._onSave)
sz_all.Add(sz_txt, 1, wx.EXPAND)
sz_all.Add(bt, 0, wx.ALIGN_CENTER | wx.ALL, 15)
parent.SetSizerAndFit(sz_all)
self.SetClientSize(sz_all.GetSize())
self.CenterOnParent()
self.Show()
wx.CallAfter(self._lst_txt[0].SetFocus)
def get_parameters(self):
""" Return the dict with my data
"""
return dict( (dta_name, widg.GetValue()) for dta_name, widg in izip(self._order, self._lst_txt) )
def _onSave(self, evt):
""" Get the values and call callback
"""
self._call_back(self.get_parameters())
wx.CallAfter(self.Close)
|