Beispiel #1
0
    def load_config(self):
        '''(internal) This function is used for returning a ConfigParser with
        the application configuration. It's doing 3 things:

            #. Creating an instance of a ConfigParser
            #. Loading the default configuration by calling
               :meth:`build_config`, then
            #. If it exists, it loads the application configuration file,
               otherwise it creates one.

        :return:
            :class:`~kivy.config.ConfigParser` instance
        '''
        try:
            config = ConfigParser.get_configparser('app')
        except KeyError:
            config = None
        if config is None:
            config = ConfigParser(name='app')
        self.config = config
        self.build_config(config)
        # if no sections are created, that's mean the user don't have
        # configuration.
        if len(config.sections()) == 0:
            return
        # ok, the user have some sections, read the default file if exist
        # or write it !
        filename = self.get_application_config()
        if filename is None:
            return config
        Logger.debug('App: Loading configuration <{0}>'.format(filename))
        if exists(filename):
            try:
                config.read(filename)
            except:
                Logger.error('App: Corrupted config file, ignored.')
                config.name = ''
                try:
                    config = ConfigParser.get_configparser('app')
                except KeyError:
                    config = None
                if config is None:
                    config = ConfigParser(name='app')
                self.config = config
                self.build_config(config)
                pass
        else:
            Logger.debug('App: First configuration, create <{0}>'.format(
                filename))
            config.filename = filename
            config.write()
        return config
Beispiel #2
0
    def load_config(self):
        '''(internal) This function is used for returning a ConfigParser with
        the application configuration. It's doing 3 things:

            #. Creating an instance of a ConfigParser
            #. Loading the default configuration by calling
               :meth:`build_config`, then
            #. If it exists, it loads the application configuration file,
               otherwise it creates one.

        :return:
            :class:`~kivy.config.ConfigParser` instance
        '''
        try:
            config = ConfigParser.get_configparser('app')
        except KeyError:
            config = None
        if config is None:
            config = ConfigParser(name='app')
        self.config = config
        self.build_config(config)
        # if no sections are created, that's mean the user don't have
        # configuration.
        if len(config.sections()) == 0:
            return
        # ok, the user have some sections, read the default file if exist
        # or write it !
        filename = self.get_application_config()
        if filename is None:
            return config
        Logger.debug('App: Loading configuration <{0}>'.format(filename))
        if exists(filename):
            try:
                config.read(filename)
            except:
                Logger.error('App: Corrupted config file, ignored.')
                config.name = ''
                try:
                    config = ConfigParser.get_configparser('app')
                except KeyError:
                    config = None
                if config is None:
                    config = ConfigParser(name='app')
                self.config = config
                self.build_config(config)
                pass
        else:
            Logger.debug('App: First configuration, create <{0}>'.format(
                filename))
            config.filename = filename
            config.write()
        return config
Beispiel #3
0
 def __init__(self, name):
     self.name = name
     self.path = "characters/{0}/".format(self.name)
     self.display_name = None
     self.series = None
     self.extra_series = []
     self.sprites_path = None
     self.icons_path = None
     self.avatar = None
     self.loaded_sprites = False
     self.loaded_icons = False
     self.sprites = None
     self.icons = None
     self.link = None
     self.version = None
     # Hash tables for faster membership checking
     self.nsfw_sprites = {}
     self.spoiler_sprites = {}
     self.cg_sprites = {}
     try:
         self.config = ConfigParser(self.name)
     except ValueError:
         self.config = ConfigParser.get_configparser(self.name)
     try:
         self.read_config()
     except (KeyError, AttributeError):
         Logger.exception('Problematic character located in: ' + self.path)
Beispiel #4
0
    def __init__(self, *args, **kwargs):
        super(Display, self).__init__(*args, **kwargs)

        # 1 and -1 are used to denote the players, 1 is the first player and -1 is the second
        #  player. This makes checking for a win very easy since a row/column/diagonal will add
        #  up to 3 or -3 if someone has won.
        self.player = Players.player_one

        self.config_parser = ConfigParser.get_configparser("app")

        self.game_over = True

        self.two_player = None
        self.human_player = None

        self.player_icons = Bidict()
        self.player_icons[Players.player_one] = "X"
        self.player_icons[Players.player_two] = "O"
        self.player_icons[Players.unplayed] = ""

        self.player_names = Bidict()
        self.player_names[Players.player_one] = "Player One"
        self.player_names[Players.player_two] = "Player Two"

        self.board = Board()
    def load_scales(self):
        scales_file = ConfigParser.get_configparser('app').get('harmonic_definitions', 'scale_system_file')
        try:

            # ConfigParser.get_configparser('app').get('fretboard', key)
            print("das goddam scales file is {}".format(scales_file))
            scale_systems = toml.load(scales_file)

            systems = scale_systems.get('systems')
            self.scales = {**scale_systems.get('scales'), **systems}

            for s in self.scales.values():
                s.sort()


        except IOError:
            box = BoxLayout(orientation="vertical")

            label = Label(
                text='Could not load scales file {}. \nPlease select a valid scales file'.format(scales_file))
            box.add_widget(label)
            button_select = Button(text='OK', size_hint=(.3, .2))
            box.add_widget(Widget(size_hint=(None, .02)))
            box.add_widget(button_select)

            popup = Popup(title='Midi Port Not Found', content=box, size_hint=(None, None), size=(1000, 400))

            def dismiss():
                popup.dismiss()
                App.get_running_app().open_settings()

            button_select.bind(on_release=lambda *args: dismiss())
            popup.open()
Beispiel #6
0
    def do_search(self):
        def on_success(req, result):
            print ('search success.')
            for p in result['result']:
                p_id = str(p['id'])
                if p['code'] is None or p['code'] == '':
                    subtext = p['name']
                else:
                    subtext = p['code']
                image_source = self.get_local_image(p)
                btn = Factory.CustomButton(image_source=image_source, id=p_id,
                                           size_hint_y=None, width=300, height=100, subtext=subtext)
                btn.bind(on_press=self.do_add_item)
                self.products_search_list.append(btn)
                self.my_tabbed_panel_wid.grid_layout_search_wid.add_widget(btn)
                self.my_tabbed_panel_wid.switch_to(self.my_tabbed_panel_wid.tab_search_wid)
            self.my_tabbed_panel_wid.grid_layout_search_wid.height = (len(result['result'])/4+4)*110
            self.text_input_wid.text = ''

        def on_failure(req, result):
            on_error(req, result)

        def on_error(req, result):
            print ('POSScrean.search().on_error() ')

        print ('POSScreen.do_search():')
        if len(self.products_search_list) > 0:
            for n in self.products_search_list:
                self.my_tabbed_panel_wid.grid_layout_search_wid.remove_widget(n)
        self.products_search_list = []
        config = ConfigParser.get_configparser(name='app')
        producturl = config.get('serverconnection', 'server.url') + "pos/product/" + self.text_input_wid.text
        UrlRequest(producturl, on_success=on_success, on_failure=on_failure, on_error=on_error)
    def on_pre_enter(self):
        def on_success(req, result):
            with open('customers.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            self.products_json = result
            print('customers loaded.')
            for i in result['result']:
                btn = Button(id=str(i['id']),
                             text=i['name'],
                             size_hint_y=None,
                             width=200,
                             height=48)
                btn.bind(on_press=self.do_action)
                print('add customer ' + str(i['id']))
                self.customer_list_wid.add_widget(btn)
            self.customer_list_wid.height = (len(result['result']) + 4) * 50

        try:
            print("Select Customer")
            self.label_wid.text = self.manager.get_screen(
                'posscreen').customer_id
            # clear customer
            config = ConfigParser.get_configparser(name='app')
            print(config.get('serverconnection', 'server.url'))
            customerurl = config.get('serverconnection',
                                     'server.url') + "pos/customers/"
            UrlRequest(customerurl, on_success)
        except:
            print "Error: Could not load products"
Beispiel #8
0
 def load_all_images(self):
     config = ConfigParser.get_configparser(name='app')
     for p in self.products_json['result']:
         image_name = p['code']
         if p['code'] is None:
             image_name = str(p['id'])
         image_file = image_name + "-small.png"
         self.download_photo(config.get('serverconnection', 'server.url') + "static/products/" + image_file,
                             "./products/" + image_file)
    def pay(self):
        unique_id = uuid.uuid4()

        def on_success(req, result):
            os.remove('offline/' + str(unique_id) + '.json')
            self.manager.get_screen('posscreen').icon_wid.source = 'icon.png'
            with open('sale.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            self.sale_json = result
            print ('on_success: sale returned.')
            self.manager.get_screen('posscreen').do_clear_item_list()
            self.parent.current = "posscreen"

        def on_failure(req, result):
            on_error(req, result)

        def on_error(req, result):
            print ('on_error: Could not send payment. Save to file instead.')
            self.manager.get_screen('posscreen').icon_wid.source = 'icon_offline.png'
            self.manager.get_screen('posscreen').do_clear_item_list()
            self.parent.current = "posscreen"

        try:
            print("Pay and clear list")
            payslip_json = dict([])
            payslip_positions = self.manager.get_screen('posscreen').my_data_view
            customer = dict([])
            customer['customerid'] = self.manager.get_screen('posscreen').customer_id
            payslip_json['customer'] = customer
            payslip_items = []
            for i in payslip_positions:
                print("selling: " + str(i))
                next_element = self.getProduct(i.product_code)
                if next_element is not None:
                    payslip_items.append(next_element)
            payslip_json['items'] = payslip_items
            with open('offline/' + str(unique_id) + '.json', 'w') as fp:
                json.dump(payslip_json, fp)
                fp.close()
            # clear list
            config = ConfigParser.get_configparser(name='app')
            print(config.get('serverconnection', 'server.url'))
            saleurl = config.get('serverconnection', 'server.url') + "pos/sale/"
            data_json = json.dumps(payslip_json)
            headers = {'Content-type': 'application/jsonrequest', 'Accept': 'application/jsonrequest'}
            if len(self.manager.get_screen('posscreen').my_data_view) > 0:
                UrlRequest(url=saleurl, on_success=on_success, on_failure=on_failure, on_error=on_error, req_headers=headers, req_body=data_json)
            else:
                self.manager.get_screen('posscreen').do_clear_item_list()
                self.parent.current = "posscreen"
        except Exception:
            print(traceback.format_exc())
            print "PaymentScreen.pay() Error: Could not send payslip"
    def on_pre_enter(self, *args):
        def on_success(req, result):
            self.icon_wid.source = 'icon.png'
            with open('products.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            self.products_json = result
            print ('products loaded.')

            if len(result['result']) > 0:
                self.grid_layout_home_wid.clear_widgets()
            for i in result['result']:
                code = i['code']
                if code == '':
                    code = '200001'
                btn = Factory.CustomButton(image_source='./products/'+code+'-small.png', id=code,
                                           size_hint_y=None, width=300, height=100, subtext=code)
                btn.bind(on_press=self.do_add_item)
                self.products_list.append(btn)
                print ('add online product ' + code)
                self.grid_layout_home_wid.add_widget(btn)
            self.grid_layout_home_wid.height = (len(result['result'])/4)*110
        try:
            config = ConfigParser.get_configparser(name='app')
            print(config.get('serverconnection', 'server.url'))
            producturl = config.get('serverconnection', 'server.url') + "pos/products/"
            if len(self.products_list) == 0:
                UrlRequest(producturl, on_success)
            else:
                return
        except:
            print "POSScreen Error: Could not load products"
        print "Initialize products selection"
        for key, val in self.ids.items():
            print("key={0}, val={1}".format(key, val))
        if len(self.products_list) > 0:
            for n in self.products_list:
                self.grid_layout_home_wid.remove_widget(n)
        if len(self.products_list) == 0:
            with open('products.json') as data_file:
                result = json.load(data_file)
                self.products_json = result
            for i in result['result']:
                code = i['code']
                if code == '':
                    code = '200001'
                btn = Factory.CustomButton(image_source='./products/'+code+'-small.png', id=code,
                                           size_hint_y=None, width=300, height=100, subtext=code)
                btn.bind(on_press=self.do_add_item)
                self.products_list.append(btn)
                print ('add local product ' + code)
                self.grid_layout_home_wid.add_widget(btn)
            self.grid_layout_home_wid.height = (len(result['result'])/4)*110
Beispiel #11
0
 def load_config(self):
     try:
         config = ConfigParser.get_configparser('app')
     except KeyError:
         config = None
     if config is None:
         config = ConfigParser(name='app')
     self.config = config
     self.build_config(config)
     # if no sections are created, that's mean the user don't have
     # configuration.
     if len(config.sections()) == 0:
         return
     # ok, the user have some sections, read the default file if exist
     # or write it !
     filename = self.get_application_config()
     if filename is None:
         return config
     Logger.debug('FlexApp: Loading configuration <{0}>'.format(filename))
     if exists(filename):
         try:
             config.read(filename)
         except:
             Logger.error('FlexApp: Corrupted config file, ignored.')
             config.name = ''
             try:
                 config = ConfigParser.get_configparser('app')
             except KeyError:
                 config = None
             if config is None:
                 config = ConfigParser(name='app')
             self.config = config
             self.build_config(config)
             pass
     else:
         Logger.debug('FlexApp: First configuration, create <{0}>'.format(
             filename))
         config.filename = filename
         config.write()
     return config
Beispiel #12
0
def get_pw_path():
    app = App.get_running_app()
    print("look pw")
    pwpath = app.config.get('configuration', 'pwd_filename')
    if not os.path.isfile(pwpath):
        print("nofo pw")
        Config = ConfigParser.get_configparser("kivy")
        folder = os.path.dirname(Config.filename)
        rand_name = get_random_chars(10)
        pwpath = os.path.join(folder, rand_name)
        password_file().get(pwpath)
        print pwpath
        app.config.set('configuration', 'pwd_filename', pwpath)
    return pwpath
    def load_chords(self):
        chords_file = ConfigParser.get_configparser('app').get('harmonic_definitions', 'chords_file')
        # ConfigParser.get_configparser('app').get('fretboard', key)
        chords = toml.load(chords_file)

        chords = chords.get('chords')

        for s in chords.values():
            s.sort()

        self.chords = dict()

        for name, chord in chords.items():
            self.chords[name] = build_chord_labels(chord)
Beispiel #14
0
 def on_release(self):
     print ('POSScreen.ImageButton.on_press: upload payslips')
     upload_count = len(glob.glob('offline/*.json'))
     if upload_count > 0:
         self.popup.open()
         self.pb.value = 0
         file_count = len(glob.glob('offline/*.json'))
         increment = 100.0/file_count + 1
         for fn in glob.glob('offline/*.json'):
             if os.path.isfile(fn):
                 Clock.schedule_once(partial(self.upload_payslips, fn, increment), 0)
     config = ConfigParser.get_configparser(name='app')
     if config.get('section1', 'download_images_after_sync') == 'True':
         self.parent.parent.parent.load_all_images()
 def build(self):
     config = ConfigParser.get_configparser(name='app')
     producturl = config.get('serverconnection', 'server.url') + "pos/product/" + '200018'
     data = json.load(urllib2.urlopen(producturl))
     product = data['result'][0]
     layout = BoxLayout(orientation='vertical')
     # use a (r, g, b, a) tuple
     blue = (0, 0, 1.5, 2.5)
     red = (2.5, 0, 0, 1.5)
     btn = Button(text='Touch me!'+product['name'], background_color=blue, font_size=40)
     btn.bind(on_press=self.callback)
     self.label = Label(text="------------", font_size='50sp')
     layout.add_widget(btn)
     layout.add_widget(self.label)
     return layout
Beispiel #16
0
 def post_init(self, *args):
     config = ConfigParser.get_configparser(name='app')
     self.customer_id = config.get('section1', 'default_customer_id')
     self.order_id = int(config.get('section1', 'default_order_id'))
     with open('customers.json') as data_file:
         result = json.load(data_file)
         self.customers_json = result
     for c in result['result']:
         self.customers_list.append(c)
     customer = self.get_customer(self.customer_id)
     if customer:
         self.customer_name = customer["name"]
     else:
         self.customer_name = '???'
     self.btn_customer_wid.text = 'Client: ' + self.customer_name
     print ('post_init...')
Beispiel #17
0
 def load_plot_configuration(self):
     config = ConfigParser.get_configparser('app')
     self.plot_time_unit = config.getdefault('plot units', 'time', 'hours')
     self.plot_temp_unit = config.getdefault('plot units', 'temp', 'bar')
     self.plot_pres_unit = config.getdefault('plot units', 'pres', 'Fahrenheit')
     if self.profile:
         self.__calculate_x_ticks_major()
     if self.profile_has_been_selected:
         if self.current_plot == "temp":
             self.__makePresGraph()
             self.__makeTempGraph()
             self.showTempGraph()
         else:
             self.__makeTempGraph()
             self.__makePresGraph()
             self.showPresGraph()
Beispiel #18
0
    def check_for_update(self):
        config = ConfigParser.get_configparser('app')
        # 0 = checking, 1 not checking
        perform_update = config.getdefaultint('update', 'update', 0)
        if perform_update == 1:
            cwd = os.getcwd()
            abs_path = os.path.join(cwd, __file__)
            # cut off filename and directory
            parent_dir = os.path.split(os.path.split(abs_path)[0])[0]
            script_dir = os.path.join(parent_dir, 'script')
            src_dir = os.path.join(parent_dir, "src")

            # quit program, execute shell script, which updates the programm
            # and restarts it afterwards
            update_script = script_dir + "/update.sh"
            main_py = src_dir + "/main.py"
            subprocess.call(["bash", update_script, str(os.getpid()), main_py])
Beispiel #19
0
    def upload_payslips(self, fn, pb_inc, *args):
        def on_success(req, result):
            self.pb.value += pb_inc
            print("Progressbar is on {0}%".format(self.pb.value))
            try:
                os.remove(fn)
            except OSError:
                print(traceback.format_exc())
                print "POSScreen.upload_payslips() on_success: no such file or directory"
            if self.pb.value >= 99.9:
                self.popup.dismiss()
                self.parent.parent.parent.update_icon(True)

        def on_failure(req, result):
            on_error(req, result)

        def on_error(req, result):
            self.pb.value += pb_inc
            print("Progressbar is on {0}%".format(self.pb.value))
            if self.pb.value >= 99.9:
                self.popup.dismiss()
                self.parent.parent.parent.update_icon(False)

        try:
            print ("POSScreen.upload_payslips()" + fn + ' ' + str(pb_inc))
            config = ConfigParser.get_configparser(name='app')
            print(config.get('serverconnection', 'server.url'))
            saleurl = config.get('serverconnection', 'server.url') + "pos/sale/"
            with open(fn) as data_file:
                result = json.load(data_file)
                file_param = dict([])
                file_param['filename'] = fn
                result['filename'] = file_param
                data_json = json.dumps(result)
                headers = {'Content-type': 'application/jsonrequest', 'Accept': 'application/jsonrequest'}
                UrlRequest(url=saleurl, on_success=on_success, on_failure=on_failure, on_error=on_error,
                           req_headers=headers, req_body=data_json)
        except Exception:
            print(traceback.format_exc())
            print "POSScreen.upload_payslips() Error: Could not upload payslip"
    def do_search(self):
        def on_success(req, result):
            print ('search success.')
            for i in result['result']:
                code = str(i['code'])
                if code == '':
                    code = '200001'
                btn = ImageButton(source='./products/'+code+'-small.png', id=code, text=str(i['id']),
                                  size_hint_y=None, width=300, height=100)
                btn.bind(on_press=self.do_add_item)
                self.products_search_list.append(btn)
                self.grid_layout_search_wid.add_widget(btn)
                self.tabbed_panel_wid.switch_to(self.tab_search_wid)
            self.grid_layout_search_wid.height = (len(result['result'])/4+4)*110

        if len(self.products_search_list) > 0:
            for n in self.products_search_list:
                self.grid_layout_search_wid.remove_widget(n)
        self.products_search_list = []
        config = ConfigParser.get_configparser(name='app')
        producturl = config.get('serverconnection', 'server.url') + "pos/product/" + self.text_input_wid.text
        UrlRequest(producturl, on_success)
 def on_pre_enter(self):
     def on_success(req, result):
         with open('customers.json', 'w') as fp:
             json.dump(result, fp)
             fp.close()
         self.products_json = result
         print ('customers loaded.')
         for i in result['result']:
             btn = Button(id=str(i['id']), text=i['name'], size_hint_y=None, width=200, height=48)
             btn.bind(on_press=self.do_action)
             print ('add customer ' + str(i['id']))
             self.customer_list_wid.add_widget(btn)
         self.customer_list_wid.height = (len(result['result'])+4)*50
     try:
         print("Select Customer")
         self.label_wid.text = self.manager.get_screen('posscreen').customer_id
         # clear customer
         config = ConfigParser.get_configparser(name='app')
         print(config.get('serverconnection', 'server.url'))
         customerurl = config.get('serverconnection', 'server.url') + "pos/customers/"
         UrlRequest(customerurl, on_success)
     except:
         print "Error: Could not load products"
Beispiel #22
0
    def pay(self):
        unique_id = uuid.uuid4()
        order_id = int(self.manager.get_screen('posscreen').order_id)

        def on_success(req, result):
            os.remove('offline/' + str(unique_id) + '.json')
            self.manager.get_screen('posscreen').update_icon(True)
            with open('sale.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            print ('on_success: sale returned.')
            if self.parent is not None:
                self.parent.current = "posscreen"

        def on_failure(req, result):
            on_error(req, result)

        def on_error(req, result):
            print ('on_error: Could not send payment. Saved to file instead.')
            self.manager.get_screen('posscreen').update_icon(False)
            if self.parent is not None:
                self.parent.current = "posscreen"

        try:
            print("Pay and clear list")
            payslip_json = dict([])
            payslip_positions = self.manager.get_screen('posscreen').my_data_view
            payslip_info = dict([])
            payslip_info['payslip_uuid'] = str(unique_id)
            payslip_info['order_id'] = str(order_id)
            payslip_info['order_date'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            payslip_info['username'] = self.manager.get_screen('posscreen').username
            payslip_info['currency'] = self.active_currency
            customer = dict([])
            customer['customerid'] = self.manager.get_screen('posscreen').customer_id
            payslip_json['customer'] = customer
            payslip_json['payslip_info'] = payslip_info
            payslip_items = []
            for i in payslip_positions:
                print("selling: " + str(i))
                next_element = self.getProduct(i.product_id)
                next_element["item_qty"] = str(i.qty)
                if next_element is not None:
                    payslip_items.append(next_element)
            payslip_json['items'] = payslip_items
            with open('offline/' + str(unique_id) + '.json', 'w') as fp:
                json.dump(payslip_json, fp)
                fp.close()
            # print payslip
            config = ConfigParser.get_configparser(name='app')
            print_enabled = config.get('section1', 'pos_printing_enabled')
            if print_enabled == 'True':
                EscPrint.print_payslip(payslip_items, payslip_info)
            bluetooth_print_enabled = config.get('section1', 'bluetooth_printing_enabled')
            if bluetooth_print_enabled == 'True':
                print("Start printing over Bluetooth")
                # IMPORTANT: ANDROID: UNCOMMENT THIS
                # blutoothprint = BluetoothPrint()
                # blutoothprint.print_payslip(payslip_items, payslip_info)
            saleurl = config.get('serverconnection', 'server.url') + "pos/sale/"
            print(config.get('serverconnection', 'server.url'))
            data_json = json.dumps(payslip_json)
            headers = {'Content-type': 'application/jsonrequest', 'Accept': 'application/jsonrequest'}
            if len(self.manager.get_screen('posscreen').my_data_view) > 0:
                UrlRequest(url=saleurl, on_success=on_success, on_failure=on_failure, on_error=on_error, req_headers=headers, req_body=data_json)
            else:
                self.parent.current = "posscreen"
            self.manager.get_screen('posscreen').do_clear_item_list()
            self.manager.get_screen('posscreen').order_id = str(order_id + 1)
            self.parent.current = "posscreen"
        except Exception:
            print(traceback.format_exc())
            print "PaymentScreen.pay() Error: Could not send payslip"
    def load_patterns(self):
        patterns_file = ConfigParser.get_configparser('app').get('harmonic_definitions', 'patterns_file')
        p = toml.load(patterns_file)

        self.patterns = p.get('patterns')
Beispiel #24
0
    def on_pre_enter(self, *args):
        def on_success(req, result):
            self.update_icon(True)
            with open('products.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            self.products_json = result
            print ('products loaded.')

            if len(result['result']) > 0:
                self.my_tabbed_panel_wid.grid_layout_home_wid.clear_widgets()
            for p in result['result']:
                p_id = str(p['id'])
                if p['code'] is None or p['code'] == '':
                    subtext = p['name']
                else:
                    subtext = p['code']
                image_source = self.get_local_image(p)
                btn = Factory.CustomButton(image_source=image_source, id=p_id,
                                           size_hint_y=None, width=300, height=100, subtext=subtext)
                btn.bind(on_press=self.do_add_item)
                self.products_list.append(btn)
                print ('add online product ' + str(p['id']))
                self.my_tabbed_panel_wid.grid_layout_home_wid.add_widget(btn)
            self.my_tabbed_panel_wid.grid_layout_home_wid.height = (len(result['result'])/4)*dp(110)

        def on_failure(req, result):
            on_error(req, result)

        def on_error(req, result):
            self.update_icon(False)
            for key, val in self.ids.items():
                print("key={0}, val={1}".format(key, val))
            if len(self.products_list) > 0:
                for n in self.products_list:
                    self.my_tabbed_panel_wid.grid_layout_home_wid.remove_widget(n)
            if len(self.products_list) == 0:
                with open('products.json') as data_file:
                    result = json.load(data_file)
                    self.products_json = result
                for p in result['result']:
                    p_id = str(p['id'])
                    if p['code'] is None or p['code'] == '':
                        subtext = p['name']
                    else:
                        subtext = p['code']
                    image_source = self.get_local_image(p)
                    btn = Factory.CustomButton(image_source=image_source, id=p_id,
                                               size_hint_y=None, width=300, height=100, subtext=subtext)
                    btn.bind(on_press=self.do_add_item)
                    self.products_list.append(btn)
                    print ('add local product ' + str(p['id']))
                    self.my_tabbed_panel_wid.grid_layout_home_wid.add_widget(btn)
                self.my_tabbed_panel_wid.grid_layout_home_wid.height = (len(result['result'])/4)*110

        def getTabHeader(tablist=None, name=''):
            for t in tablist:
                if t.text == name:
                    return True
            return False

        def on_success_categories(req, result):
            with open('categories.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            self.categories_json = result
            print ('categories loaded.')
            for i in result['result']:
                name = i['name']
                self.categories_list.append(i)
                if not getTabHeader(self.my_tabbed_panel_wid.tab_list, name):
                    th = TabbedPanelHeader(text=name)
                    self.my_tabbed_panel_wid.add_widget(th)
                    layout = GridLayout(cols=4, spacing=2, size_hint_y=None)
                    layout.bind(minimum_height=layout.setter('height'))
                    root = ScrollView()
                    root.add_widget(layout)
                    th.content = root
                print ('add online category ' + name)

        def on_failure_categories(req, result):
            on_error_categories(req, result)

        def on_error_categories(req, result):
            self.update_icon(False)
            print 'could not load categories'
            try:
                with open('categories.json') as data_file:
                    result = json.load(data_file)
                    self.categories_json = result
                for i in result['result']:
                    name = i['name']
                    self.categories_list.append(i)
                    if not getTabHeader(self.my_tabbed_panel_wid.tab_list, name):
                        th = TabbedPanelHeader(text=name)
                        self.my_tabbed_panel_wid.add_widget(th)
                        layout = GridLayout(cols=4, spacing=2, size_hint_y=None)
                        layout.bind(minimum_height=layout.setter('height'))
                        root = ScrollView()
                        root.add_widget(layout)
                        th.content = root
                        print ('add local category ' + name)
            except:
                traceback.print_exc(file=sys.stdout)

        def on_success_currencies(req, result):
            with open('currencies.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            self.currencies_json = result
            print ('currencies loaded.')
            for i in result['result']:
                rate = Decimal(i['rate'])
                if rate == Decimal(1.000):
                    self.default_currency = i['code']
                    print ('set default currency ' + i['code'])
                if rate > Decimal(0.00000):
                    self.currencies_list.append(i)
                    print ('add currency ' + i['code'])

        def on_failure_currencies(req, result):
            on_error_currencies(req, result)

        def on_error_currencies(req, result):
            self.update_icon(False)
            print 'could not load currencies'
            try:
                with open('currencies.json') as data_file:
                    result = json.load(data_file)
                    self.currencies_json = result
                for i in result['result']:
                    rate = Decimal(i['rate'])
                    if rate == Decimal(1.000):
                        self.default_currency = i['code']
                        print ('set default currency ' + i['code'])
                    if i['rate'] > Decimal(0.00000):
                        self.currencies_list.append(i)
            except:
                traceback.print_exc(file=sys.stdout)
        try:
            self.btn_order_id_wid.text = str(self.order_id)
            self.username = self.manager.get_screen('main').textinput_user_wid.text
            config = ConfigParser.get_configparser(name='app')
            print(config.get('serverconnection', 'server.url'))
            hideoutofstockitems = config.get('section1', 'hide_out_of_stock_items')
            producturl = config.get('serverconnection', 'server.url') + "pos/products/" + hideoutofstockitems
            if len(self.products_list) == 0:
                UrlRequest(url=producturl, on_success=on_success, on_failure=on_failure, on_error=on_error)
            categoryurl = config.get('serverconnection', 'server.url') + "pos/categories/"
            if len(self.categories_list) == 0:
                UrlRequest(url=categoryurl, on_success=on_success_categories, on_failure=on_failure_categories,
                           on_error=on_error_categories)
            currencyurl = config.get('serverconnection', 'server.url') + "pos/currency/"
            if len(self.currencies_list) == 0:
                UrlRequest(url=currencyurl, on_success=on_success_currencies, on_failure=on_failure_currencies,
                       on_error=on_error_currencies)

        except:
            traceback.print_exc(file=sys.stdout)
        print "Initialize products selection"
Beispiel #25
0
    def __init__(self, midi_player, **kwargs):
        super(AppWindow, self).__init__(**kwargs)
        self.midi_player = midi_player
        self.orientation = 'vertical'
        self.tuning = P4Tuning(
            int(
                ConfigParser.get_configparser('app').get(
                    'fretboard', 'num_frets')))
        self.note_filter = DefaultNoteFilter(self.tuning)
        if self.midi_port:
            self.midi_config = Midi(self.midi_player, self.note_filter,
                                    self.midi_port, self.midi_message_received,
                                    self.midi_output_port)

        self.scale_config = Scales()
        self.chords_config = Chords()
        self.patterns_config = Patterns()

        with self.canvas:
            Window.size = (self.initial_width,
                           self.initial_width * self.height_ratio)
            Window.left = self.initial_screen_loc_x
            Window.top = self.initial_screen_loc_y
            Window.clearcolor = (1, 1, 1, 1)
            if self.maximized:
                Window.maximize()

            self.rect = Rectangle(pos=self.pos, size=self.size, group='fb')

        pattern_mapper = P4TuningPatternMatcher(self.tuning,
                                                self.chords_config,
                                                self.scale_config,
                                                self.patterns_config)
        self.fretboard = Fretboard(tuning=self.tuning,
                                   pattern_mapper=pattern_mapper,
                                   pos_hint={
                                       'x': 0,
                                       'y': 0
                                   },
                                   size_hint=(1, 0.3))

        self.player_panel = PlayerPanel(fretboard=self.fretboard,
                                        midi_config=self.midi_config,
                                        size_hint=(1, 1))
        self.note_trainer_panel = NoteTrainerPanel(
            fretboard=self.fretboard,
            midi_config=self.midi_config,
            tuning=self.tuning,
            size_hint=(1, 1))
        self.menu_panel = MenuPanel(fretboard=self.fretboard,
                                    player_panel=self.player_panel,
                                    note_trainer_panel=self.note_trainer_panel,
                                    size_hint=(1, 0.7))
        self.add_widget(self.menu_panel)
        self.add_widget(self.fretboard)

        with self.canvas.before:
            pass

        with self.canvas.after:
            pass

        self.bind(size=self.size_changed)
        Window.bind(on_maximize=lambda x: App.get_running_app().config.set(
            'window', 'maximized', 1))
        Window.bind(on_restore=lambda x: App.get_running_app().config.set(
            'window', 'maximized', 0))
 def post_init(self, *args):
     config = ConfigParser.get_configparser(name='app')
     self.customer_id = config.get('section1', 'default_customer_id')
     self.btn_customer_wid.text = 'Customer: ' + str(self.customer_id)
     print ('post_init...')
Beispiel #27
0
 def load_process_configuration(self):
     config = ConfigParser.get_configparser('app')
     self.log_interval = int(config.getdefault('process', "logInterval", "10"))
     self.sub_size_unit = config.getdefault("process", "subsize", "mm")
Beispiel #28
0
    def pay(self):
        unique_id = uuid.uuid4()

        def on_success(req, result):
            os.remove('offline/' + str(unique_id) + '.json')
            self.manager.get_screen('posscreen').icon_wid.source = 'icon.png'
            with open('sale.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            self.sale_json = result
            print('on_success: sale returned.')
            self.manager.get_screen('posscreen').do_clear_item_list()
            self.parent.current = "posscreen"

        def on_failure(req, result):
            on_error(req, result)

        def on_error(req, result):
            print('on_error: Could not send payment. Save to file instead.')
            self.manager.get_screen(
                'posscreen').icon_wid.source = 'icon_offline.png'
            self.manager.get_screen('posscreen').do_clear_item_list()
            self.parent.current = "posscreen"

        try:
            print("Pay and clear list")
            payslip_json = dict([])
            payslip_positions = self.manager.get_screen(
                'posscreen').my_data_view
            customer = dict([])
            customer['customerid'] = self.manager.get_screen(
                'posscreen').customer_id
            payslip_json['customer'] = customer
            payslip_items = []
            for i in payslip_positions:
                print("selling: " + str(i))
                next_element = self.getProduct(i.product_code)
                if next_element is not None:
                    payslip_items.append(next_element)
            payslip_json['items'] = payslip_items
            with open('offline/' + str(unique_id) + '.json', 'w') as fp:
                json.dump(payslip_json, fp)
                fp.close()
            # clear list
            config = ConfigParser.get_configparser(name='app')
            print(config.get('serverconnection', 'server.url'))
            saleurl = config.get('serverconnection',
                                 'server.url') + "pos/sale/"
            data_json = json.dumps(payslip_json)
            headers = {
                'Content-type': 'application/jsonrequest',
                'Accept': 'application/jsonrequest'
            }
            if len(self.manager.get_screen('posscreen').my_data_view) > 0:
                UrlRequest(url=saleurl,
                           on_success=on_success,
                           on_failure=on_failure,
                           on_error=on_error,
                           req_headers=headers,
                           req_body=data_json)
            else:
                self.manager.get_screen('posscreen').do_clear_item_list()
                self.parent.current = "posscreen"
        except Exception:
            print(traceback.format_exc())
            print "PaymentScreen.pay() Error: Could not send payslip"
Beispiel #29
0
    def pay(self):
        unique_id = uuid.uuid4()
        order_id = int(self.manager.get_screen('posscreen').order_id)

        def on_success(req, result):
            os.remove('offline/' + str(unique_id) + '.json')
            self.manager.get_screen('posscreen').update_icon(True)
            with open('sale.json', 'w') as fp:
                json.dump(result, fp)
                fp.close()
            print('on_success: sale returned.')
            if self.parent is not None:
                self.parent.current = "posscreen"

        def on_failure(req, result):
            on_error(req, result)

        def on_error(req, result):
            print('on_error: Could not send payment. Saved to file instead.')
            self.manager.get_screen('posscreen').update_icon(False)
            if self.parent is not None:
                self.parent.current = "posscreen"

        try:
            print("Pay and clear list")
            payslip_json = dict([])
            payslip_positions = self.manager.get_screen(
                'posscreen').my_data_view
            payslip_info = dict([])
            payslip_info['payslip_uuid'] = str(unique_id)
            payslip_info['order_id'] = str(order_id)
            payslip_info['order_date'] = datetime.now().strftime(
                "%Y-%m-%d %H:%M:%S")
            payslip_info['username'] = self.manager.get_screen(
                'posscreen').username
            payslip_info['currency'] = self.active_currency
            customer = dict([])
            customer['customerid'] = self.manager.get_screen(
                'posscreen').customer_id
            payslip_json['customer'] = customer
            payslip_json['payslip_info'] = payslip_info
            payslip_items = []
            for i in payslip_positions:
                print("selling: " + str(i))
                next_element = self.getProduct(i.product_id)
                next_element["item_qty"] = str(i.qty)
                if next_element is not None:
                    payslip_items.append(next_element)
            payslip_json['items'] = payslip_items
            with open('offline/' + str(unique_id) + '.json', 'w') as fp:
                json.dump(payslip_json, fp)
                fp.close()
            # print payslip
            config = ConfigParser.get_configparser(name='app')
            print_enabled = config.get('section1', 'pos_printing_enabled')
            if print_enabled == 'True':
                EscPrint.print_payslip(payslip_items, payslip_info)
            bluetooth_print_enabled = config.get('section1',
                                                 'bluetooth_printing_enabled')
            if bluetooth_print_enabled == 'True':
                print("Start printing over Bluetooth")
                # IMPORTANT: ANDROID: UNCOMMENT THIS
                # blutoothprint = BluetoothPrint()
                # blutoothprint.print_payslip(payslip_items, payslip_info)
            saleurl = config.get('serverconnection',
                                 'server.url') + "pos/sale/"
            print(config.get('serverconnection', 'server.url'))
            data_json = json.dumps(payslip_json)
            headers = {
                'Content-type': 'application/jsonrequest',
                'Accept': 'application/jsonrequest'
            }
            if len(self.manager.get_screen('posscreen').my_data_view) > 0:
                UrlRequest(url=saleurl,
                           on_success=on_success,
                           on_failure=on_failure,
                           on_error=on_error,
                           req_headers=headers,
                           req_body=data_json)
            else:
                self.parent.current = "posscreen"
            self.manager.get_screen('posscreen').do_clear_item_list()
            self.manager.get_screen('posscreen').order_id = str(order_id + 1)
            self.parent.current = "posscreen"
        except Exception:
            print(traceback.format_exc())
            print "PaymentScreen.pay() Error: Could not send payslip"