예제 #1
0
 def run(self, ):
     """\brief show dialog window and save data into database if "save" pressed
     \retval gtk.RESPONSE_ACCEPT
     \retval gtk.RESPONSE_CANCEL
     """
     try:
         self.list.set_odd_color(self._parent.settings.get_key('interface.odd_color'))
         self.list.set_even_color(self._parent.settings.get_key('interface.even_color'))
     except od_exception_config_key_error:
         pass
     if not self._parent.connected():
         return
     self._parent.model.start_transacted_action("Edit some papers")
     self.window.show_all()
     try:
         ret = self.window.run()
         if ret == gtk.RESPONSE_ACCEPT:
             self._parent.model.commit_transacted_action()
         else:
             self._parent.model.rollback()
     except Exception as e:
         self._parent.model.rollback()
         self.window.hide()
         show_and_print_error(e, self._parent.window.builder.get_object('main_window'))
                              
     self.window.hide()
     return (ret == gtk.RESPONSE_ACCEPT and ret or gtk.RESPONSE_CANCEL)
예제 #2
0
    def __init__(self, ):
        """initialize gtk view
        """
        self.model = None
        self.settings = settings()
        self.window = main_window_controller(self)
        if self.settings.get_key('behavior.load_last_database'):
            dbpath = self.settings.get_key('database.path')
            if not (is_null_or_empty(dbpath) or dbpath == ':memory:'):
                try:
                    self.open_existing_sqlite(dbpath)
                except sqlite3.OperationalError as e:
                    show_and_print_error(e, self.window.builder.get_object('main_window'))
            else:
                self.settings.set_key('database.path', '')
        self.currency = currency_edit_control(self)
        self.account_edit = account_edit_control(self)
        self.accounts = accounts_tab_controller(self)
        self.deals_tab = deals_tab_controller(self)
        self.deal_adder = deal_adder_control(self)
        self.deal_editor = deal_editor_control(self)
        self.deals_filter = deals_filter(self)
        self.paper_adder = paper_adder(self)
        self.positions_tab = positions_tab_controller(self)
        self.positions_filter = positions_filter(self)
        self.position_adder = position_adder_control(self)
        self.points = points_control(self)
        self.report_importer = report_importer_control(self)
        self.chart_tab = chart_tab_controller(self)
        self.settings_dialog = settings_dialog_controller(self)
        self.account_in_out = account_in_out_controller(self)
        self.history_dialog = history_dialog_controller(self)

        self.call_update_callback()
 def continue_from_head(self, ):
     """\brief set history back to finite state
     """
     try:
         self._parent.model.tago_to_head()
         self.update()
     except Exception as e:
         show_and_print_error(e, self.window)
 def rollback_selected(self, ):
     """\brief rollback to selected action
     """
     sel = self.history.get_selected_row()
     if sel == None:
         return
     try:
         self._parent.model.tago_to_action(sel[0])
         self.update()
     except Exception as e:
         show_and_print_error(e, self.window)
 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()
예제 #6
0
 def create_database_in_file(self):
     if self._parent.disconnect():
         win = self.builder.get_object("main_window")
         diag = gtk.FileChooserDialog(title = u'Новая база', parent = win, action = gtk.FILE_CHOOSER_ACTION_SAVE)
         diag.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
         diag.add_button(gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT)
         if diag.run() == gtk.RESPONSE_ACCEPT:
             try:
                 self._parent.create_new_sqlite(diag.get_filename())
             except Exception as e:
                 show_and_print_error(e, self.builder.get_object("main_window"))
         diag.destroy()
         self._parent.call_update_callback()
 def head_selected(self, ):
     """\brief remove selected action and all above it
     """
     sel = self.history.get_selected_row()
     if sel == None:
         return
     try:
         stat = self._parent.model.get_action_stats(sel[0])
         dialog = gtk.MessageDialog(parent = self.window, flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_WARNING, buttons = gtk.BUTTONS_YES_NO, message_format = u'Этим дейтвием вы безвозвратно удалите {0} действий в которых содержиться {1} запросов на изменение базы данных.\n Вы желаете продолжить ?'.format(stat['actions_above'], stat['queries_above']))
         if dialog.run() == gtk.RESPONSE_YES:
             self._parent.model.taremove_action(sel[0])
             self.update()
     except Exception as e:
         show_and_print_error(e, self.window)
     dialog.destroy()
예제 #8
0
 def disconnect(self, ):
     """
     \retval True if disconnected successfully
     \retval False if did not disconnected
     """
     if self.connected():
         try:
             self.model.disconnect()
             self.model = None
         except Exception as e:
             show_and_print_error(e, self.window.builder.get_object("main_window"))
             return False
         else:
             return True
     else:
         return True
 def run(self, ):
     """\brief run dialog window
     """
     if self._parent.connected():
         self._parent.model.start_transacted_action('modify some account entry withdrawall money')
         ret = None
         try:
             ret = self.window.run()
             if ret == gtk.RESPONSE_ACCEPT:
                 self._parent.model.commit_transacted_action()
             else:
                 self._parent.model.rollback()
         except Exception as e:
             self._parent.model.rollback()
             show_and_print_error(e, self.window)
         self.window.hide()
         return ret
예제 #10
0
 def load_data(self, ):
     """\brief load data into selected account
     """
     account = self.account_control.get_value()
     if account == None:
         show_error(u'You need to select account to load data into', self.window)
         return False
     loader = open_ru_loader()
     try:
         loader.load(self._parent._parent.get_model(),
                     open_ru_source(self.window.get_filename(),
                                    self.account_control.get_value(), # account id
                                    self.repo.get_active(), # load repo deals
                                    self.accounts.get_active())) # load account IO
         return True
     except Exception as e:
         show_and_print_error(e, self.window)
         return False
예제 #11
0
 def open_database(self):
     if self._parent.disconnect():
         win = self.builder.get_object("main_window")
         diag = gtk.FileChooserDialog(title = u'Открыть базу', parent = win, action = gtk.FILE_CHOOSER_ACTION_OPEN)
         diag.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
         diag.add_button(gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT)
         fl = gtk.FileFilter()
         fl.add_mime_type('application/x-sqlite3')
         if os.name == 'posix':
             diag.set_filter(fl)
         if diag.run() == gtk.RESPONSE_ACCEPT:
             try:
                 self._parent.open_existing_sqlite(diag.get_filename())
             except Exception as e:
                 show_and_print_error(e, self.builder.get_object('main_window'))
         diag.destroy()
         fl.destroy()
         self._parent.call_update_callback()
예제 #12
0
 def import_from_old_database(self):
     if self._parent.model.connection == None:
         return
     win = self.builder.get_object("main_window")
     ch = self._parent.model.get_changes()
     if ch > 0:
         show_error(u'Перед импортом нужно завершить транзакцию выполните Rollback или Commit', win)
         return
     diag = gtk.FileChooserDialog(title = u'Открыть базу', parent = win, action = gtk.FILE_CHOOSER_ACTION_OPEN)
     diag.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
     diag.add_button(gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT)
     fl = gtk.FileFilter()
     fl.add_mime_type('application/x-sqlite3')
     diag.set_filter(fl)
     if diag.run() == gtk.RESPONSE_ACCEPT:
         try:
             self._parent.model.load_from_old_version(diag.get_filename())
         except Exception as e:
             show_and_print_error(e, win)
     diag.destroy()
     fl.destroy()
예제 #13
0
 def save_as(self):
     if not self._parent.connected():
         return
     win = self.builder.get_object("main_window")
     # ch = self._parent.model.get_changes()
     # if ch > 0:
     #     show_error(u'Перед сохранением нужно завершить транзакцию выполните Rollback или Commit', win)
     #     return
     filename = self._parent.model.get_connection_string()
     if filename == ":memory:":
         return
     dial = gtk.FileChooserDialog(title = u'Сохранить как', parent = win, action = gtk.FILE_CHOOSER_ACTION_SAVE, buttons = (gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
     if dial.run() == gtk.RESPONSE_ACCEPT:
         dial.hide()
         dstfile = dial.get_filename()
         if self._parent.disconnect():
             try:
                 shutil.copyfile(filename, dstfile)
                 self._parent.model.open_existing(dstfile)
                 self._parent.call_update_callback()
             except Exception as e:
                 show_and_print_error(e, win)
     dial.destroy()