コード例 #1
0
ファイル: test_calculator.py プロジェクト: LeonamSilva/stoq
    def test_attach(self):
        entry = ProxyEntry()
        entry.data_type = currency
        self.assertEqual(entry.get_property('secondary-icon-pixbuf'), None)

        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)
        pixbuf_pixels = calc.render_icon(STOQ_CALC,
                                         gtk.ICON_SIZE_MENU).get_pixels()
        self.assertEqual(
            entry.get_property('secondary-icon-pixbuf').get_pixels(), pixbuf_pixels)
        entry.set_sensitive(False)
        self.assertEqual(entry.get_property('secondary-icon-pixbuf'), None)
        entry.set_sensitive(True)
        self.assertEqual(
            entry.get_property('secondary-icon-pixbuf').get_pixels(), pixbuf_pixels)

        spinbutton = ProxySpinButton()
        spinbutton.data_type = currency
        self.assertEqual(spinbutton.get_property('secondary-icon-pixbuf'), None)

        calc = CalculatorPopup(spinbutton, CalculatorPopup.MODE_SUB)
        pixbuf_pixels = calc.render_icon(STOQ_CALC,
                                         gtk.ICON_SIZE_MENU).get_pixels()
        self.assertEqual(
            spinbutton.get_property('secondary-icon-pixbuf').get_pixels(), pixbuf_pixels)
        spinbutton.set_sensitive(False)
        self.assertEqual(spinbutton.get_property('secondary-icon-pixbuf'), None)
        spinbutton.set_sensitive(True)
        self.assertEqual(
            spinbutton.get_property('secondary-icon-pixbuf').get_pixels(), pixbuf_pixels)
コード例 #2
0
ファイル: test_calculator.py プロジェクト: LeonamSilva/stoq
    def test_apply(self):
        entry = ProxyEntry()
        entry.data_type = currency
        entry.set_text('150')
        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)

        # calc.popup will not work here, so call _update_ui directly
        calc._update_ui()
        calc._entry.set_text('10%')
        event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
        event.keyval = gtk.keysyms.Return
        event.window = gtk.gdk.get_default_root_window()
        calc.emit('key-press-event', event)
        calc.emit('key-press-event', event)
        self.assertEqual(entry.read(), 135)
コード例 #3
0
ファイル: test_calculator.py プロジェクト: LeonamSilva/stoq
    def test_validate(self):
        def validate_entry(entry, value):
            if value == 100:
                return ValidationError()

        # FIXME: For some reason, entry is not emitting 'changed' event
        # on set_text, not even if we call entry.emit('changed') by hand.
        # That only happens here on the test. Figure out why
        def update_entry(entry, value):
            entry.set_text(value)
            entry.validate(force=True)

        entry = ProxyEntry()
        entry.data_type = currency
        entry.connect('validate', validate_entry)
        entry.set_text('150')

        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)
        # calc.popup will not work here, so call _update_ui directly
        calc._update_ui()
        self.assertValid(calc, ['_entry'])
        self.assertNotVisible(calc, ['_warning'])

        for value in ['abc', '+10%', '-10%', '+10', '-10']:
            update_entry(calc._entry, value)
            self.assertInvalid(calc, ['_entry'])
            self.assertNotVisible(calc, ['_warning'])

        update_entry(calc._entry, '40')
        self.assertValid(calc, ['_entry'])
        self.assertNotVisible(calc, ['_warning'])

        # 50 of discount will make the value invalid on entry
        # (see validate_entry above)
        update_entry(calc._entry, '50')
        self.assertValid(calc, ['_entry'])
        self.assertVisible(calc, ['_warning'])
コード例 #4
0
    def _setup_widgets(self):
        self._calc = CalculatorPopup(self.price,
                                     CalculatorPopup.MODE_SUB)

        self.sale.set_text(str(self.model.loan.identifier))
        self.description.set_text(self.model.sellable.get_description())
        self.original_price.update(self.model.price)
        for widget in [self.quantity, self.price]:
            widget.set_adjustment(Gtk.Adjustment(lower=0, upper=MAX_INT,
                                                 step_incr=1))
        unit = self.model.sellable.unit
        self.quantity.set_digits(
            QUANTITY_PRECISION if unit and unit.allow_fraction else 0)

        self.tabs.set_show_tabs(False)
コード例 #5
0
    def test_attach(self):
        entry = ProxyEntry()
        entry.data_type = currency
        self.assertEqual(entry.get_property('secondary-icon-pixbuf'), None)
        theme = Gtk.IconTheme.get_default()

        CalculatorPopup(entry, CalculatorPopup.MODE_SUB)
        pixbuf_pixels = theme.load_icon(STOQ_CALC, Gtk.IconSize.MENU,
                                        0).get_pixels()

        self.assertEqual(
            entry.get_property('secondary-icon-pixbuf').get_pixels(),
            pixbuf_pixels)
        entry.set_sensitive(False)
        self.assertEqual(entry.get_property('secondary-icon-pixbuf'), None)
        entry.set_sensitive(True)
        self.assertEqual(
            entry.get_property('secondary-icon-pixbuf').get_pixels(),
            pixbuf_pixels)

        spinbutton = ProxySpinButton()
        spinbutton.data_type = currency
        self.assertEqual(spinbutton.get_property('secondary-icon-pixbuf'),
                         None)

        CalculatorPopup(spinbutton, CalculatorPopup.MODE_SUB)
        self.assertEqual(
            spinbutton.get_property('secondary-icon-pixbuf').get_pixels(),
            pixbuf_pixels)
        spinbutton.set_sensitive(False)
        self.assertEqual(spinbutton.get_property('secondary-icon-pixbuf'),
                         None)
        spinbutton.set_sensitive(True)
        self.assertEqual(
            spinbutton.get_property('secondary-icon-pixbuf').get_pixels(),
            pixbuf_pixels)
コード例 #6
0
ファイル: test_calculator.py プロジェクト: sarkis89/stoq
    def test_popdown(self):
        entry = ProxyEntry()
        entry.data_type = currency
        entry.set_text('150')
        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)

        with contextlib.nested(
                mock.patch.object(calc, '_maybe_apply_new_value'),
                mock.patch.object(calc, 'popdown')) as (manv, popdown):
            # Those keys should try to apply the value
            for keyval in [
                    gtk.keysyms.Return, gtk.keysyms.KP_Enter, gtk.keysyms.Tab
            ]:
                event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
                event.keyval = keyval
                event.window = gtk.gdk.get_default_root_window()
                calc.emit('key-press-event', event)

                self.assertEqual(manv.call_count, 1)
                self.assertEqual(popdown.call_count, 0)

                manv.reset_mock()
                popdown.reset_mock()

            event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
            # Escape should popdown the popup
            event.keyval = gtk.keysyms.Escape
            event.window = gtk.gdk.get_default_root_window()
            calc.emit('key-press-event', event)

            self.assertEqual(popdown.call_count, 1)
            self.assertEqual(manv.call_count, 0)
            manv.reset_mock()
            popdown.reset_mock()

            event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
            # Any other should not do anything
            event.keyval = gtk.keysyms.A
            event.window = gtk.gdk.get_default_root_window()
            calc.emit('key-press-event', event)

            self.assertEqual(manv.call_count, 0)
            self.assertEqual(popdown.call_count, 0)
コード例 #7
0
    def test_apply(self):
        entry = ProxyEntry()
        entry.data_type = currency
        entry.set_text('150')
        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)

        # calc.popup will not work here, so call validate_popup directly
        calc.validate_popup()
        calc._entry.set_text('10%')
        event = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
        event.keyval = Gdk.KEY_Return
        event.window = Gdk.get_default_root_window()
        calc.emit('key-press-event', event)
        calc.emit('key-press-event', event)
        self.assertEqual(entry.read(), 135)
コード例 #8
0
ファイル: test_calculator.py プロジェクト: Guillon88/stoq
    def test_popdown(self):
        entry = ProxyEntry()
        entry.data_type = currency
        entry.set_text('150')
        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)

        with contextlib.nested(
                mock.patch.object(calc, '_maybe_apply_new_value'),
                mock.patch.object(calc, 'popdown')) as (manv, popdown):
            # Those keys should try to apply the value
            for keyval in [gtk.keysyms.Return,
                           gtk.keysyms.KP_Enter,
                           gtk.keysyms.Tab]:
                event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
                event.keyval = keyval
                event.window = gtk.gdk.get_default_root_window()
                calc.emit('key-press-event', event)

                self.assertEqual(manv.call_count, 1)
                self.assertEqual(popdown.call_count, 0)

                manv.reset_mock()
                popdown.reset_mock()

            event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
            # Escape should popdown the popup
            event.keyval = gtk.keysyms.Escape
            event.window = gtk.gdk.get_default_root_window()
            calc.emit('key-press-event', event)

            self.assertEqual(popdown.call_count, 1)
            self.assertEqual(manv.call_count, 0)
            manv.reset_mock()
            popdown.reset_mock()

            event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
            # Any other should not do anything
            event.keyval = gtk.keysyms.A
            event.window = gtk.gdk.get_default_root_window()
            calc.emit('key-press-event', event)

            self.assertEqual(manv.call_count, 0)
            self.assertEqual(popdown.call_count, 0)
コード例 #9
0
ファイル: saleeditor.py プロジェクト: 5l1v3r1/stoq-1
    def _setup_widgets(self):
        self._calc = CalculatorPopup(self.price, CalculatorPopup.MODE_SUB)

        self.sale.set_text(str(self.model.sale.identifier))
        self.description.set_text(self.model.sellable.get_description())
        self.original_price.update(self.model.base_price)

        self.price.set_adjustment(
            Gtk.Adjustment(lower=0,
                           upper=MAX_INT,
                           step_increment=1,
                           page_increment=10))
        unit = self.model.sellable.unit
        digits = QUANTITY_PRECISION if unit and unit.allow_fraction else 0
        for widget in [self.quantity, self.reserved]:
            widget.set_digits(digits)
            widget.set_adjustment(
                Gtk.Adjustment(lower=0,
                               upper=MAX_INT,
                               step_increment=1,
                               page_increment=10))

        manager = get_plugin_manager()
        self.nfe_is_active = manager.is_any_active(['nfe', 'nfce'])

        if not self.nfe_is_active:
            self.cfop_label.hide()
            self.cfop.hide()

        if not self._can_reserve():
            self.reserved.hide()
            self.reserved_lbl.hide()

        # We populate this even if it's hidden because we need a default value
        # selected to add to the sale item
        cfop_items = CfopData.get_for_sale(self.store)
        self.cfop.prefill(api.for_combo(cfop_items))

        self._update_total()
        self.reserved.get_adjustment().set_upper(self.quantity_model.quantity)
コード例 #10
0
ファイル: test_calculator.py プロジェクト: sarkis89/stoq
    def test_attach(self):
        entry = ProxyEntry()
        entry.data_type = currency
        self.assertEqual(entry.get_property('secondary-icon-pixbuf'), None)

        calc = CalculatorPopup(entry, CalculatorPopup.MODE_SUB)
        pixbuf_pixels = calc.render_icon(STOQ_CALC,
                                         gtk.ICON_SIZE_MENU).get_pixels()
        self.assertEqual(
            entry.get_property('secondary-icon-pixbuf').get_pixels(),
            pixbuf_pixels)
        entry.set_sensitive(False)
        self.assertEqual(entry.get_property('secondary-icon-pixbuf'), None)
        entry.set_sensitive(True)
        self.assertEqual(
            entry.get_property('secondary-icon-pixbuf').get_pixels(),
            pixbuf_pixels)

        spinbutton = ProxySpinButton()
        spinbutton.data_type = currency
        self.assertEqual(spinbutton.get_property('secondary-icon-pixbuf'),
                         None)

        calc = CalculatorPopup(spinbutton, CalculatorPopup.MODE_SUB)
        pixbuf_pixels = calc.render_icon(STOQ_CALC,
                                         gtk.ICON_SIZE_MENU).get_pixels()
        self.assertEqual(
            spinbutton.get_property('secondary-icon-pixbuf').get_pixels(),
            pixbuf_pixels)
        spinbutton.set_sensitive(False)
        self.assertEqual(spinbutton.get_property('secondary-icon-pixbuf'),
                         None)
        spinbutton.set_sensitive(True)
        self.assertEqual(
            spinbutton.get_property('secondary-icon-pixbuf').get_pixels(),
            pixbuf_pixels)
コード例 #11
0
ファイル: abstractwizard.py プロジェクト: victornovy/stoq
 def setup_proxies(self):
     if self.calculator_mode is not None:
         self.calculator_popup = CalculatorPopup(self.cost,
                                                 self.calculator_mode)
     self.proxy = self.add_proxy(None, self.proxy_widgets)
コード例 #12
0
    def test_show(self):
        spinbutton = ProxySpinButton()
        spinbutton.data_type = currency
        calc = CalculatorPopup(spinbutton, CalculatorPopup.MODE_SUB)

        self.check_widget(calc, 'calculator-popup-show')