admin.py :  » Business-Application » OpenRMS » openres-0.2.1 » client » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » OpenRMS 
OpenRMS » openres 0.2.1 » client » admin.py
from widgets import *

#### App frames go here
class classframe(appframe):
  def __init__(self, master, reservation = None):
    """ Gets all classes for the listbox as the default """
    rclass=openrms.r_class('', '', '', 0, '', '', '')
    self.classes = rclass.SearchByPrice('>')
    appframe.__init__(self, master)
  def create_widgets(self):
    self.ListGrid = None
    self.CreateClassPane(self)
  def CreateClassPane(self, master):
    self._ClassPane = rowframe(master)
    self.ClassPane = colframe(self._ClassPane)

    self.SmokeRow = rowframe(self.ClassPane)
    self.SmokeLbl = unilabel(self.SmokeRow, lang.Smoking)
    self.SmokeLbl.pack(side = 'left')
    self.Smokebtns = ynna_radiobutton(self.SmokeRow)
    self.Smokebtns.pack(side = 'right')

    self.BathRow = rowframe(self.ClassPane)
    self.BathLbl = unilabel(self.BathRow, lang.PrivateBath)
    self.BathLbl.pack(side = 'left')
    self.BathBtns = ynna_radiobutton(self.BathRow)
    self.BathBtns.pack(side = 'right')

    self.FeatRow = rowframe(self.ClassPane)
    self.bedarray = openrms._bed_type.ReturnLabelArray()
    labels = []
    for k, item in self.bedarray.items():
      labels.append(item)
    self.BedTypeMenu = ExtOptionMenu(self.FeatRow, lang.BedTypes, 
        lang.NA, labels)
    self.BedTypeMenu.pack(side = 'left')
    self.SearchByFeatures = Button(self.FeatRow)
    apply_config(self.SearchByFeatures)
    self.SearchByFeatures['text'] = lang.FeatureSearch
    self.SearchByFeatures['command'] = self.OnFeatSearch
    self.SearchByFeatures.pack(side = 'left', padx = 3)
    self.FeatSpacer = spacerrow(self.ClassPane)

    self.PriceRow = rowframe(self.ClassPane)
    self.PriceLbl = unilabel(self.PriceRow, lang.Price)
    self.PriceEntry = FloatEntry(self.PriceRow)
    self.PriceEntry['width'] = 10
    self.PriceLbl.pack(side = 'left')
    price_ops = ['=', '<', '>', '<>', '<=', '>=']
    self.PriceOp = ExtOptionMenu(self.PriceRow, '=', price_ops)
    self.PriceOp.pack(side = 'left')
    self.PriceEntry.pack(side = 'left')
    self.PriceSearch = Button(self.PriceRow)
    apply_config(self.PriceSearch)
    self.PriceSearch['text'] = lang.PriceSearch
    self.PriceSearch['command'] = self.OnPriceSearch
    self.PriceSearch.pack(side = 'left')

    self.GridRow = rowframe(self.ClassPane)
    self.ShowListGrid(list(self.classes))

    self.btnrow = rowframe(self.ClassPane)

    self.btn_new = Button(self.btnrow)
    apply_config(self.btn_new)
    self.btn_new['text'] = lang.New
    self.btn_new['command'] = self.new_class
    self.btn_new.pack(side = 'left')

    self.btn_edit = Button(self.btnrow)
    apply_config(self.btn_edit)
    self.btn_edit['text'] = lang.Edit
    self.btn_edit['command'] = self.edit_class
    self.btn_edit.pack(side = 'left')

    self.btn_del = Button(self.btnrow)
    apply_config(self.btn_del)
    self.btn_del['text'] = lang.Delete
    self.btn_del['command'] = self.del_class
    self.btn_del.pack(side = 'left')
    self.del_confirm = Unicheckbutton(self.btnrow, lang.Confirm)
    self.del_confirm.pack(side = 'left')

    self.CreateCurClassPane(self._ClassPane)

  def CreateCurClassPane(self, master):
    self._CurClassPane = colframe(master)
    self.CurClassPane = rowframe(self._CurClassPane)
    self._CurClassPane.config(relief = 'groove', bd = '2')

    self.CurClassSmokeRow = rowframe(self.CurClassPane)
    self.CurClassSmokelbl = unilabel(self.CurClassSmokeRow,
      "%s: " % lang.Smoking)
    self.CurClassSmoking = unilabel(self.CurClassSmokeRow, ' ')
    self.CurClassSmokelbl.pack(side = 'left')
    self.CurClassSmoking.pack(side = 'left')

    self.CurClassBathRow = rowframe(self.CurClassPane)
    self.CurClassBathlbl = unilabel(self.CurClassBathRow,
      '%s: ' % lang.PrivateBath)
    self.CurClassPrivBath = unilabel(self.CurClassBathRow, ' ')
    self.CurClassBathlbl.pack(side = 'left')
    self.CurClassPrivBath.pack(side = 'left')

    self.CurClassPriceRow = rowframe(self.CurClassPane)
    self.CurClassPricelbl = unilabel(self.CurClassPriceRow, 
      '%s: ' % lang.Price)
    self.CurClassPrice = unilabel(self.CurClassPriceRow, ' ')
    self.CurClassPricelbl.pack(side = 'left')
    self.CurClassPrice.pack(side = 'left')

    self.CurClassDescRow = rowframe(self.CurClassPane)
    self.CurClassDesclbl = unilabel(self.CurClassDescRow, 
      '%s: ' % lang.Description)
    self.CurClassDesclbl.pack(side = 'left')

    self.CurClassDescRow2 = rowframe(self.CurClassPane)
    self.CurClassDescription = unilabel(self.CurClassDescRow2, ' ')
    self.CurClassDescription['wraplength'] = 200
    self.CurClassDescription.pack(side = 'left')

  def ShowListGrid(self, class_list):
    if hasattr(self, '_beds') == 0:
      self._beds = {}
    if hasattr(self, '_classes') == 0:
      self._classes = {}

    if self.ListGrid:
      self.ListGrid.destroy()
    self.ListGrid = grid_listbox(self.GridRow,
      [10, 10, 6, 10],
      [lang.Price, lang.Smoking, lang.Bath, lang.Bed])
    self.ListGrid.OnSelect = self.UpdateCurClassPane
    self.ListGrid.OnDoubleClick = self.edit_class

    for entry in class_list:
      bed_keys = self._beds.keys()
      class_keys = self._classes.keys()

      if class_keys.count(entry.id) == 0:
        self._classes[entry.id] = entry
      if bed_keys.count(entry.bed_type) == 0:
        bed = entry.GetBedType()
        self._beds[bed.id] = bed
      else:
        bed = self._beds[entry.bed_type]

      if DBAL.is_true(entry.smoking):
        Smoking = lang.Y
      else:
        Smoking = lang.N

      if DBAL.is_true(entry.priv_bath):
        Bath = lang.Y
      else:
        Bath = lang.N
      self.ListGrid.AddRow(entry.id,
        [entry.price, Smoking, Bath, bed.label])
        
  def OnPriceSearch(self):
    r_class = openrms.r_class(None, None, None, 
      self.PriceEntry.get(), 
      None, None, None)
    rclass_list = r_class.SearchByPrice(self.PriceOp.get())
    self.ShowListGrid(rclass_list)
  def OnFeatSearch(self):
    BedType = None;
    bed_lbl = self.BedTypeMenu.get()
    for k, v in self.bedarray.items():
      if bed_lbl == v:
        BedType = k
    r_class = openrms.r_class(None, self.Smokebtns.get(), BedType, 
      None, self.BathBtns.get(), None, None)
    rclass_list = r_class.SearchByFeatures()
    self.ShowListGrid(rclass_list)
  def UpdateCurClassPane(self, id):
    self._class_id = id
    r_class = self._classes[int(id)]
    if DBAL.is_true(r_class.smoking):
      smoking = lang.Y
    else:
      smoking = lang.N
    if DBAL.is_true(r_class.priv_bath):
      bath = lang.Y
    else:
      bath = lang.N
    self.CurClassSmoking.set(smoking)
    self.CurClassPrivBath.set(bath)
    self.CurClassPrice.set(r_class.price)
    self.CurClassDescription.set(r_class.description)
  def OnClassUpdate(self, id):
    if self.reservation:
      self.reservation.class_id = id
      self.reservation._InitPrice()
      self.reservation.commit()
      appframe = reseditframe(self.master, self.reservation)
      self.master.ChangeApp(appframe)
    else:
      self.master.ChangeClass(id)
      self.exit()

  def new_class(self):
    app = editclassframe(self.master)
    self.master.ChangeApp(app)

  def edit_class(self):
    rclass = self._classes[int(self._class_id)]
    app = editclassframe(self.master, rclass)
    self.master.ChangeApp(app)

  def del_class(self):
    print self._class_id
    print self._classes.keys()
    if (hasattr(self, '_class_id')):
      rclass = self._classes[int(self._class_id)]
      if (self.del_confirm.get() == '1'):
        rclass.delete()

class editclassframe(appframe):
  def __init__(self, master, rclass = None):
    self.rclass = rclass
    appframe.__init__(self, master)
  def create_widgets(self):
    self.idrow = rowframe(self)
    self.idlbl = unilabel(self.idrow, lang.ID)
    self.idlbl.pack(side='left')
    if (hasattr (self.rclass, 'id')):
      self.id = unilabel(self.idrow, self.rclass.id)
      self.id.pack(side='left')
      self.has_class = True;
      smoke_default = self.rclass.smoking
      bath_default = self.rclass.priv_bath
    else:
      self.has_class = False;
      smoke_default = None
      bath_default = None

    self.featrow = rowframe(self)
    self.lblSmoke = unilabel(self.featrow, lang.Smoking)
    self.lblSmoke.pack(side='left')
    self.smoke = yn_radiobutton(self.featrow, 
      default = smoke_default)
    self.smoke.pack(side='left')

    self.lblBath = unilabel(self.featrow, lang.PrivateBath)
    self.bath = yn_radiobutton(self.featrow,
      default = bath_default)
    self.bath.pack(side='right')
    self.lblBath.pack(side='right')

    self.bedrow = rowframe(self)
    self.bedtype = self.__bed_btn(self.bedrow)
    self.bedtype.pack(side='left')

    self.Price = FloatEntry(self.bedrow)
    self.Price.pack(side='right')

    self.PriceLbl = unilabel(self.bedrow, lang.Price + ": " +
      lang.CURRENCYSYM) 
    self.PriceLbl.pack(side='right')
    # self.OccLbl = unilabel(self.bedrow, lang.Occupancy)
    # self.Occupancy = TextEntry(self.bedrow)
    # self.Occupancy.pack(side='right')
    # self.OccLbl.pack(side='right')

    self.obrow = rowframe(self)
    self.overbklbl = unilabel(self.obrow, lang.PercentOverbooking)
    self.overbklbl.pack(side='left')
    self.Overbook = NumberEntry(self.obrow)
    self.Overbook['width'] = 4
    self.Overbook.pack(side='left')
    self.poblbl = unilabel(self.obrow, '%')
    self.poblbl.pack(side='left')

    self.DescLblRow = rowframe(self)
    self.DescLbl = unilabel(self.DescLblRow, lang.Description)
    self.DescLbl.pack(side='left')

    self.DescRow = rowframe(self)
    self.Description = Text(self.DescRow)
    self.Description.config(height= 10, width = 46, wrap = 'word')
    apply_config(self.Description)
    self.Description.pack()

    self.btnrow = rowframe(self)
    self.savebtn = Button(self.btnrow)
    self.savebtn['text'] = lang.Save
    self.savebtn['command'] = self.__Save
    apply_config(self.savebtn)
    self.savebtn.pack(side='left')

    if (self.has_class):
      self.smoke.StrVar.set(
        openrms.DBAL.is_true(self.rclass.smoking))
      self.bath.StrVar.set(
        openrms.DBAL.is_true(self.rclass.priv_bath))
      self.Price.set(self.rclass.price)
      self.Overbook.set(self.rclass.percent_overbooking)
      self.Description.insert('end', self.rclass.description)
    
  def __bed_btn(self, master):
    bt_list = openrms._bed_type.GetTypes()
    btlbls = []
    for v in bt_list:
      btlbls.append(v.label)
    return ExtOptionMenu(master, lang.BedType, btlbls)
  def __Save(self):
    if (self.has_class):
      cid = self.rclass.id
    else:
      cid = None

    bedtype = openrms._bed_type.GetByLabel(self.bedtype.get())
    new_class = openrms.r_class(cid, self.smoke.get(), 
      bedtype.id,
      self.Price.get(), 
      self.bath.get(), 
      self.Overbook.get(),
      self.Description.get('1.0', 'end'))

    new_class.commit()

class roomframe(appframe):
  def create_widgets(self):
    pass

class rateframe(appframe):
  def create_widgets(self):
    pass
class bedframe(appframe):
  def create_widgets(self):
    pass

#### Begin execution here

appdict = {
  lang.Classes: classframe,
  lang.Rooms: roomframe,
  lang.RateChange: rateframe,
  lang.BedTypes: bedframe,
  lang.Configuration: configframe
}

defaultframe = classframe
openrms.SetConnection(DBAL.connect(config.dsn, config.user, config.password))
app = main_window(appdict, defaultframe)
app.mainloop()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.