Ejemplo n.º 1
0
 def insert(self, table, fields):
     """inserts data in fields into table
     \param table 
     \param fields  must be hash like that {"field_name" : data_to_insert} or list of that hashes
     \return id of last inserted row
     """
     assert(isinstance(fields, dict) or hasattr(fields, "__iter__"))
     names = set()
     for kk in (isinstance(fields, dict) and [fields] or fields):
         for k in kk.keys():
             assert(isinstance(k, basestring))
             names.add(k)
     names = sorted(names)
                 
     if isinstance(fields, dict):
         data = map(lambda a: fields[a], names)
     else:
         data = map(lambda a: map(lambda x: gethash(a, x), names), fields)
     qqs = reduce_by_string(", ", map(lambda a: "?", names))
     nns = reduce_by_string(", ", names)
     query = "insert into {0}({1}) values ({2})".format(table, nns, qqs)
     if isinstance(fields, dict):
         return self.execute(query, data).lastrowid
     else:
         return self.executemany(query, data).lastrowid
Ejemplo n.º 2
0
 def modify_account(self):
     """runs account dialog and modifies selected account"""
     if self._parent.connected():
         row = self.accounts_list.get_selected_row()
         if row != None:
             acc = self._parent.model.get_account(row[0])
             self._parent.account_edit.reset_widget()
             self._parent.account_edit.set_name(acc['name'])
             self._parent.account_edit.set_comment(gethash(acc, "comments"))
             self._parent.account_edit.set_currency(self._parent.model.get_money(acc["money_id"])["name"])
             self._parent.account_edit.set_first_money(acc["money_count"])
             ret = self._parent.account_edit.run()
             if ret == gtk.RESPONSE_ACCEPT:
                 dd = self._parent.account_edit.get_data()
                 self._parent.model.tachange_account(acc["id"],
                                                     dd["name"],
                                                     dd["money_name"],
                                                     dd["money_count"],
                                                     ('' if gethash(dd, 'comment') == None else dd['comment']))
             self._parent.call_update_callback()
Ejemplo n.º 3
0
 def __init__(self, ):
     """\brief constructor
     """
     self._config_data = None
     self._default_cinfig_data = {'database' : {'path' : ''},
                                  'behavior' : {'load_last_database' : True},
                                  'interface' : {'odd_color' : '#FFFFFF',
                                                 'even_color' : '#FFFFFF'},
                                  'chart' : {'legend': {'position' : 'bottom',
                                                        'font' : 'Sans 14',
                                                        'color' : '#FFFFFF'},
                                             'mesh' : {'line_width' : 1.5,
                                                       'color' : '#FFFFFF',
                                                       'font' : {'name' : 'Sans 14'}},
                                             'background' : {'color' : '#FFFFFF'},
                                             'top_indent' : 5,
                                             'bottom_indent' : 5}}
     
     if os.name in ['posix', 'nt']: # there is HOME environment under windoze in 2.7 python at least
         if os.name == 'nt':
             os.environ['HOME'] = os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH'])
         config_dir = None
         if not is_null_or_empty(gethash(os.environ, 'TD_CONFIG_DIR')):
             config_dir = os.environ['TD_CONFIG_DIR']
         else:
             if not is_null_or_empty(gethash(os.environ, 'HOME')):
                 config_dir = os.path.join(os.environ['HOME'], '.track-deals') # this is default config directory
             else:
                 raise EnvironmentError('There is not HOME environment specified')
     else:
         raise NotImplementedError('There is no code for windoze yet')
     self.config_file = os.path.join(config_dir, 'gtk-view.cfg')
     if not os.path.exists(config_dir):
         os.makedirs(config_dir)
     if not os.path.exists(self.config_file):
         self.make_default_config()
     else:
         self.read_config()
Ejemplo n.º 4
0
 def load_from_deal(self, data):
     """\brief load data from deal into widget
     \param data - int, deal id
     """
     if not self._parent.connected():
         return
     d = self._parent.model.get_deal(data)
     if d == None:
         return
     for (setter, key) in [
         (self.datetime.set_datetime, "datetime"),
         (self.direction.set_value, "direction"),
         (self.account.set_value, "account_id"),
         (self.instrument.set_value, "paper_id"),
         (self.price.set_value, "points"),
         (self.count.set_value, "count"),
         (self.commission.set_value, "commission"),
     ]:
         m = gethash(d, key)
         if m != None:
             setter(m)
     self.attributes.set_attributes((d["user_attributes"] if d.has_key("user_attributes") else None))
Ejemplo n.º 5
0
 def add_account(self):
     """runs account adder dialog and adds account to the database"""
     if self._parent.connected():
         self._parent.account_edit.reset_widget()
         ret = self._parent.account_edit.run()
         if ret == gtk.RESPONSE_ACCEPT:
             try:
                 data = self._parent.account_edit.get_data()
                 self._parent.model.tacreate_account(data["name"], data["money_name"], data["money_count"], gethash(data, "comment"))
             except Exception as e:
                 show_and_print_error(e, self._parent.window.builder.get_object("main_window"))
         self._parent.call_update_callback()