def update_answers(self, answers, none_answer = None):
     """
     \brief set new answers set
     \param answers list of tuples like for \ref __init__
     \param none_answer - value to return when empty item is selected
     """
     if answers == None:
         return
     if len(answers) == 0:
         m = gtk.ListStore(int, str)
         self.combobox.set_model(m)
         if self.use_completion and isinstance(self.combobox.get_child(), gtk.Entry):
             self.combobox.get_child().set_completion(None)
         return
     self.none_answer = none_answer
     val = self.get_value()
     m = gtk.ListStore(isinstance(answers[0][0], basestring) and str or type(answers[0][0]), str)
     for a in answers:
         m.append(a)
     if none_answer != None:
         m.append((none_answer, ""))
     self.combobox.set_model(m)
     if self.use_completion and isinstance(self.combobox.get_child(), gtk.Entry):
         ent = self.combobox.get_child()
         completion = gtk.EntryCompletion()
         completion.set_model(m)
         completion.set_text_column(1)
         completion.set_inline_completion(True)
         ent.set_completion(completion)
         self.combobox.set_entry_text_column(1)
     if val != None:
         fnd = find_in_list(lambda a: a[0] == val, answers)
         if fnd != None:
             self.combobox.set_active(fnd)
示例#2
0
 def remove_drawer(self, drawer):
     """\brief remove drawer from the list
     \param drawer
     """
     ind = find_in_list(lambda obj: obj == drawer, self._drawers)
     if ind <> None:
         del self._drawers[ind]
示例#3
0
 def get_forts_deals(self, domparsed):
     """\brief return list of deals for forts report type
     \param domparsed
     \return list of \ref report_deal objects
     """
     report = domparsed.getElementsByTagName('report')[0]
     deals = report.getElementsByTagName('common_deal')[0].getElementsByTagName('item')
     report_deals = []
     for deal in deals:
         d = report_deal()
         d.set_market_name('FORTS')
         d.set_stock_name(deal.getAttribute('security_name'))
         d.set_dtm(deal.getAttribute('deal_date'))
         d.set_points(deal.getAttribute('price'))
         d.set_count(deal.getAttribute('quantity'))
         d.set_direction(deal.getAttribute('deal_sign'))
         d.set_sha1(hashlib.sha1(reduce_by_string('', [deal.getAttribute(attrname) for attrname in
                                                       ['deal_date',
                                                        'security_name',
                                                        'expiration_date',
                                                        'price',
                                                        'quantity',
                                                        'order_number',
                                                        'deal_number',
                                                        'deal_sign']])).hexdigest())
         report_deals.append(d)
     atl = report.getElementsByTagName('account_totally_line')[0]
     atl_items = atl.getElementsByTagName('item')
     broker = find_in_list(lambda a: a.getAttribute(u'total_description') == u'Вознаграждение Брокера', atl_items)
     board = find_in_list(lambda a: a.getAttribute(u'total_description') == u'Биржевой сбор', atl_items)
     brcomm = (0 if broker == None else float(atl_items[broker].getAttribute('total_value')))
     boardcomm = (0 if board == None else float(atl_items[board].getAttribute('total_value')))
     summcomm = abs(brcomm) + abs(boardcomm) # summary commission from the report
     specific_comm = summcomm / sum([d.get_volume() for d in report_deals])
     for deal in report_deals:
         deal.set_commission(specific_comm * deal.get_volume()) # set commission to the deal
     return report_deals