Ejemplo n.º 1
0
 def drop(self, index):
     """
     Drop value from stack
     """
     try:
         self._stack.pop(index)
     except IndexError:
         raise StackUnderflowError(_(u'Stack is empty'))
Ejemplo n.º 2
0
    def create_menu(self):
        menu = hildon.AppMenu()
        switch(menu, [2, 8, 10, 16, -1].index(self._conv.base), self.hit_switch_base, *self.__bases_ordered)

        menu.append(picker(_(u'View mode'), (self._conv.mode,), self.hit_change_view, *self.__view_modes))

        # First number is minimal integer part length to pad to with
        # zeroes (-1 means no leading zero for numbers less than 1),
        # second number is number of digits left after decimal
        # point (0 means always work with integers, -1 - no rounding
        # is applied).
        nums = liststore(*range(-1, 65))
        menu.append(picker(_(u'Precision'), map(lambda x: x + 1, self._conv.precision), self.hit_change_precision, selector(nums, nums)))

        menu.append(picker(_(u'Orientation'), (self.orientation_mode,), self.hit_change_orientation, *self.__orientations))
        menu.append(button(_(u'About'), self.show_about_info))
        return menu
Ejemplo n.º 3
0
    def init_controls(self):
        keypad = self.create_keypad()
        stack = hildon.TextView()
        input = hildon.Entry(gtk.HILDON_SIZE_AUTO)

        input.set_placeholder(_(u'Empty value'))
        input.set_properties(
                hildon_input_mode=gtk.HILDON_GTK_INPUT_MODE_ALPHA
                | gtk.HILDON_GTK_INPUT_MODE_NUMERIC
                | gtk.HILDON_GTK_INPUT_MODE_SPECIAL)
        stack.set_placeholder(_(u'Stack is empty'))
        stack.set_properties(editable=False)

        self.w_stack = stack
        self.w_buffer = stack.get_buffer()
        self.w_input = input
        self.w_keypad = keypad
Ejemplo n.º 4
0
 def pop(self, index=0):
     """
     Pop value from stack (like get()+drop())
     """
     try:
         text = self._stack.pop(index)
     except IndexError:
         raise StackUnderflowError(_(u'Stack is empty'))
     return text
Ejemplo n.º 5
0
        def wrapper(stack):
            try:
                args = list()
                for t in rtypes:
                    args.insert(0, t(stack.pop_op()))
            except ValueError:
                raise OperationError(_(u"Arguments type mismatch for %s(%s)") % (name, ", ".join(map(lambda t: t.__name__, types))))

            op_invoke(func, stack, args)
Ejemplo n.º 6
0
    def show_about_info(self, b):
        self.note(_(u"""Programmer's calculator, v%(version)s

RPN calculator with bit-wise operations
and infix operators emulation.

Distributed AS IS under GPLv3 or greater
without any warranty.

Author: Konstantin Stepanov, (c) 2010""") % dict(version=__version__))
Ejemplo n.º 7
0
        def wrapper(stack):
            try:
                args = list()
                while stack:
                    item = stack.pop_op()
                    if item is nan:
                        break
                    args.insert(0, type_(item))
            except ValueError:
                raise OperationError(_(u"Argument type mismatch for %s(%s, ...)") % (name, type_.__name__))

            op_invoke(func, stack, args)
Ejemplo n.º 8
0
    def pop_op(self):
        while self._opstack:
            self._stack.insert(0, self._opstack.pop(0))

        try:
            data = self._stack.pop(0)
            while isinstance(data, function):
                data(self)
                data = self._stack.pop(0)

        except IndexError:
            raise StackUnderflowError(_(u'Stack is empty'))

        return data
Ejemplo n.º 9
0
    def __init__(self, e):
        if isinstance(e, Exception):
            message = e.__doc__ or ''
            if message.endswith('.'):
                message = message[:-1] + ': '
            message += e.message

        else:
            message = str(e)

        if not message:
            message = _(u'Unexpected operation error.')

        if not message.endswith('.'):
            message += '.'

        super(OperationError, self).__init__(message.capitalize())
Ejemplo n.º 10
0
    def hit_digit(self, b):
        if self.opmode:
            self.opmode = False
            self.stack_push_op()

        if self.is_mode:
            bases = {'2': '0b', '8': '0o', '0': '', 'A': '0x'}
            base = bases.get(b.get_label(), None)
            if base is not None:
                text = self.input
                minus = text.startswith('-')
                text = base + text.lstrip('-0bxo')
                if minus:
                    text = '-' + text
                self.input = text
                self.is_mode = False
            else:
                self.message(_(u'Press 2, 8, 0 or A to select base'), 4000)
        else:
            self.add_input(b.get_label())
Ejemplo n.º 11
0
 def norm(self, value):
     if value is None or value == '':
         raise StackError(_(u'No empty values allowed on the stack'))
     return self._ops.get(value, None) or self._guard(value)
Ejemplo n.º 12
0
 def get_op(self, opname):
     try:
         return self._ops[opname]
     except KeyError:
         raise StackError(_(u'Unknown operation %s') % opname)