コード例 #1
0
 def widget(self, widget, kw):
     for i in widget_options.get_options(widget, self.widget.__name__):
         if i in kw:
             name = i.capitalize()
             if not isinstance(kw[i], getattr(tkinter, name)):
                 raise TclError(
                     'expected tkinter.%s instance but got "%s"' % (name, kw[i]))
コード例 #2
0
 def not_exist(self, widget, kw):
     for i in widget_options.get_options(widget, self.not_exist.__name__):
         image_cond = ('image' in i and i in kw and
                       isinstance(kw[i], str) and kw[i] != '')
         font_cond = 'font' in kw and kw['font'] == ''
         if i in kw and (image_cond or font_cond):
             name = 'image' if i == 'activeimage' else i
             raise TclError('%s "%s" doesn\'t exist' % (name, kw[i]))
コード例 #3
0
ファイル: test_gui.py プロジェクト: ethru/bookmeister
def test_form_frame_clear(parameter, mocker):
    mocked = mocker.MagicMock()
    mock = mocker.MagicMock()
    if isinstance(parameter, bool):
        mock.set.side_effect = [TclError(), None]
    mocked.variables.values.return_value = [mock]
    gui.Form.clear(mocked)
    mocked.menu.search.box.clear.assert_called_once()
    mock.set.assert_called_with(parameter)
コード例 #4
0
 def boolean(self, widget, kw):
     for i in widget_options.get_options(widget, self.boolean.__name__):
         if i in kw:
             if kw[i] in (False, 0, 'false', 'no', 'off'):
                 kw[i] = 0
             elif kw[i] in (True, 1, 'true', 'yes', 'on'):
                 kw[i] = 1
             else:
                 raise TclError(
                     'expected boolean value but got "%s"' % kw[i])
コード例 #5
0
ファイル: test_widgetredir.py プロジェクト: Gzigithub/-
 def test_command_dispatch(self):
     # Test that .__init__ causes redirection of tk calls
     # through redir.dispatch
     self.root.call(self.text._w, 'insert', 'hello')
     self.assertEqual(self.func.args, ('hello',))
     self.assertEqual(self.text.get('1.0', 'end'), '\n')
     # Ensure that called through redir .dispatch and not through
     # self.text.insert by having mock raise TclError.
     self.func.__init__(TclError())
     self.assertEqual(self.root.call(self.text._w, 'insert', 'boo'), '')
コード例 #6
0
 def pixel(self, widget, kw):
     for i in widget_options.get_options(widget, self.pixel.__name__):
         if i in kw:
             if '.' in str(kw[i]):
                 kw[i] = round(float(kw[i]))
             if isinstance(kw[i], str):
                 if kw[i][-1] in UNITS and kw[i][:-1].isnumeric():
                     kw[i] = round(pixels_conv(kw[i]))
             if not isinstance(kw[i], (int, float)):
                 raise TclError('bad screen distance "%s"' % kw[i])
コード例 #7
0
ファイル: smashres.py プロジェクト: cnassau/yacop-sage
    def generators(self, region, extracondition=""):
        """
        This routine is used by Subset(SmashResolutionHomology) to implement the basis of Ext(M)

        #TODO: The code is copied over from minres and should be refactored
        """
        if self._resolution._viewtype == "even":
            nexp = "(ideg/2-sdeg)"
            texp = "(ideg/2)"
        else:
            nexp = "(ideg-sdeg)"
            texp = "ideg"

        from tkinter import TclError

        def cond(var, col, fac=1):
            res = ""
            mi, ma = region.min(var), region.max(var)
            if mi > -Infinity:
                res += " and %s >= %d" % (col, fac * mi)
            if ma < +Infinity:
                res += " and %s <= %d" % (col, fac * ma)
            return res

        c = ""
        c += cond("s", "sdeg")
        c += cond("t", texp)
        c += cond("n", "ndeg")
        c += cond("e", "edeg")
        c += cond("b", "(sdeg-edeg)")
        if len(c) and len(extracondition):
            c += " and "
        c += extracondition
        while c[:4] == " and":
            c = c[4:]
        if len(c) and c[:5] != "where":
            c = "where " + c
        code = """
               join [smashprod db eval {
                   select pydict('id',rowid,'s',sdeg,'t',%s,
                     'e',edeg,'n',%s,'num',basid)
                     from homology_generators %s
               }] ,
        """ % (
            texp,
            nexp,
            c,
        )
        # print code
        try:
            res = "[" + self.tcl.eval(code) + "]"
        except TclError as e:
            raise TclError("query failed: %s\n%s" % (c, e.message))
        return eval(res)
コード例 #8
0
 def enum(self, widget, kw):
     op_list = widget_options.get_options(widget, self.enum.__name__)
     for k, v in self.enum_para.items():
         if (k in op_list and k in kw
             and kw[k] not in v
             and not (k == 'compound'
                              and str(kw[k]).lower() in 'none'
                              and kw[k] != '')
             ):
             err = 'ambiguous' if kw[k] == '' else 'bad'
             name = 'justification' if k == 'justify' else k
             if 'overrelief' == k:
                 v = v[:-1]
                 name = 'relief'
             raise TclError(
                 '%s %s "%s": must be %s%s or %s' % (
                     err, name, kw[k], ', '.join(v[:-1]),
                     ',' if len(v) > 2 else '', v[-1]))
コード例 #9
0
def tcl_eval(tcl, script):
    """
    Execute a Tcl script, with error reporting.

    EXAMPLE::

        sage: from yacop.utils.tcl import tcl_interp, tcl_eval
        sage: tcl_eval(tcl_interp(),"oops")
        Traceback (most recent call last):
        ...
        TclError: invalid command name "oops"
            while executing
        "oops"

    """
    try:
        return tcl.eval(script)
    except TclError as e:
        einf = tcl.eval("set ::errorInfo")
        raise TclError(einf)
コード例 #10
0
 def test_command_dispatch(self):
     self.root.call(self.text._w, 'insert', 'hello')
     self.assertEqual(self.func.args, ('hello', ))
     self.assertEqual(self.text.get('1.0', 'end'), '\n')
     self.func.__init__(TclError())
     self.assertEqual(self.root.call(self.text._w, 'insert', 'boo'), '')
コード例 #11
0
ファイル: test_widgetredir.py プロジェクト: Gzigithub/-
 def test_dispatch_error(self):
     self.func.__init__(TclError())
     self.assertEqual(self.redir.dispatch('insert', False), '')
     self.assertEqual(self.redir.dispatch('invalid'), '')
コード例 #12
0
 def place(self, **kw):
     raise TclError("cannot use place with this widget")
コード例 #13
0
 def pack(self, **kw):
     raise TclError("cannot use pack with this widget")
コード例 #14
0
ファイル: textview.py プロジェクト: bodinroxana0/learning
 def place(self, **kwargs):
     raise TclError(f'{self.__class__.__name__} does not support "place"')
コード例 #15
0
ファイル: psimap.py プロジェクト: cnassau/yacop-sage
    def generators(self, region, extracondition=""):
        """
        Search for generators in the given region.
        Meaningful region attributes are `s`, `t`, `n=t-s`, `b=s-e`

        TESTS::

            sage: from yacop.resolutions.minres import GFR
            sage: from yacop.utils.region import region
            sage: def count(C,**args): return len(C.generators(region(args)))
            sage: C=GFR(SteenrodAlgebra(3),memory=True)
            sage: C.extend(s=10,n=20)
            sage: count(C,n=11),count(C,t=13),count(C,s=2),count(C,s=2,e=1)
            (3, 2, 5, 2)
            sage: C=GFR(SteenrodAlgebra(2,generic=True),memory=True)
            sage: C.extend(s=10,n=20)
            sage: count(C,n=11),count(C,t=13),count(C,s=2),count(C,s=2,e=1)
            (6, 1, 10, 3)
            sage: C=GFR(SteenrodAlgebra(2),memory=True)
            sage: C.extend(s=10,n=20)
            sage: count(C,n=11),count(C,t=13),count(C,s=2),count(C,s=2,e=1)
            (3, 1, 10, 0)
            sage: count(C)
            66
        """
        from tkinter import TclError

        def cond(var, col, fac=1):
            res = ""
            mi, ma = region.min(var), region.max(var)
            if mi > -Infinity:
                res += " and %s >= %d" % (col, fac * mi)
            if ma < +Infinity:
                res += " and %s <= %d" % (col, fac * ma)
            return res

        c = ""
        c += cond("s", "sdeg")
        c += cond("t", "ideg")
        c += cond("n", "ndeg")
        c += cond("e", "edeg")
        c += cond("b", "(sdeg-edeg)")
        if len(c) and len(extracondition):
            c += " and "
        c += extracondition
        while c[:4] == " and":
            c = c[4:]
        if len(c) and c[:5] != "where":
            c = "where " + c
        try:
            res = (
                "["
                + self.tcl.eval(
                    """
               join [resolution db eval {
                   select pydict('id',rowid,'s',sdeg,'t',ideg,'e',edeg,'n',ndeg,'num',basid) from chart_generators %s
               }] ,
            """
                    % c
                )
                + "]"
            )
        except TclError as e:
            raise TclError("query failed: %s\n%s" % (c, e.message))
        return eval(res)
コード例 #16
0
ファイル: smashres.py プロジェクト: cnassau/yacop-sage
    def _tclmodule(self, action, *args, **kwd):
        """
        This function is a wrapper that is invoked from the Tcl code.
        Its purpose is to provide access to the module.
        """
        def donothing(*args):
            pass

        dbgfunc = donothing
        #dbgfunc = print
        dbgfunc("tcl call to python module:", action, args)

        if action == "actR":
            try:
                algebra = self._resolution._algebra
                el = self._module.load_element(args[0])
                op = tclsteenrodop(algebra, args[1])
                res = op % el
                ans = ""
                if not res.is_zero():
                    reg = region(s=res.s, t=res.t, e=res.e)
                    gb = self._module.graded_basis(reg)
                    cfs = self._module.graded_basis_coefficients(res, reg)
                    for (bel, cf) in zip(gb, cfs):
                        ans += " %d {%s}" % (cf,
                                             self._module.dump_element(bel))
                # print "actR",args,"=",res,"=",ans,"aus",op,"%",el
                return ans
            except Exception as e:
                dbgfunc(e)
                raise e
        elif action == "generators":
            algebra = self._resolution._algebra
            fac = self._tfactor
            # 1 if algebra.is_generic() else 2
            x = args[0].split(" ")
            dbgfunc("x=", x)
            reg = region(dict(list(zip(x[::2], (int(u) for u in x[1::2])))))
            # r2 = region(smax=reg.smax,
            #            tmax=(reg.smax+reg.nmax+(fac-1))/fac,
            #            emax=reg.emax)
            r2 = reg
            r2.tmin = fac * r2.tmin
            r2.tmax = fac * r2.tmax
            dbgfunc(reg, r2, args)
            res = ""
            B = self._module.graded_basis(r2)
            dbgfunc(r2, list(B))
            dbgfunc("basis of %s in %s = %s" % (self._module, r2, B))
            if not B.is_finite():
                # print "b not finite",r2
                raise ValueError("module not finite in region %s" % r2)
            for g in B:
                res += " {name {%s} sdeg %d ideg %d edeg %d}" % (
                    self._module.dump_element(g),
                    g.s,
                    fac * g.t,
                    g.e,
                )
            dbgfunc("answer=", res)
            return res
        elif action == "diff":
            # FIXME
            return ""
        if action == "init":
            return
        # print action
        raise TclError("action %s not implemented" % action)
コード例 #17
0
 def integer(self, widget, kw):
     for i in widget_options.get_options(widget, self.integer.__name__):
         if i in kw:
             if kw[i] == '' or '.' in str(kw[i]) or not str(kw[i]).lstrip("-").isnumeric():
                 raise TclError('expected integer but got "%s"' % kw[i])