Пример #1
0
    def getTime(self,
                in_seconds: bool = True,
                js_code: str = None,
                set_var: bool = False):
        """
    Description:
    -----------
    To get the unix timestamp using JavaScript you need to use the getTime() function of the build in Date object.
    As this returns the number of milliseconds then we must divide the number by 1000 and round it in order to get the
    timestamp in seconds.

    Attributes:
    ----------
    :param bool in_seconds: In second conversion of the Javascript timestamp
    :param str js_code:
    :param bool set_var:
    """
        from epyk.core.js.primitives import JsNumber
        if js_code is not None:
            set_var = True
        if in_seconds:
            return JsNumber.JsNumber("%s.getTime()/1000" % self.varId,
                                     js_code=js_code,
                                     set_var=set_var,
                                     is_py_data=False)

        return JsNumber.JsNumber("%s.getTime()" % self.varId,
                                 js_code=js_code,
                                 set_var=set_var,
                                 is_py_data=False)
Пример #2
0
    def random(self,
               min_val: Union[int, primitives.JsDataModel] = 0,
               max_val: Union[int, primitives.JsDataModel] = 1):
        """
    Description:
    ------------
    Math.random() returns a random number between 0 (inclusive),  and 1 (exclusive):

    Usage::

      page.js.math.random()
      jsObj.math.random(10, 100)

    Related Pages:

      https://www.w3schools.com/js/js_random.asp

    Attributes:
    ----------
    :param Union[int, primitives.JsDataModel] min_val: Optional The minimum value for the random function.
    :param Union[int, primitives.JsDataModel] max_val: Optional The maximum value for the random function.

    :return: A Number, representing a number from 0 up to but not including 1.
    """
        if min_val == 0 and max_val == 1:
            return JsNumber.JsNumber("Math.random()", is_py_data=False)

        min_val = JsUtils.jsConvertData(min_val, None)
        max_val = JsUtils.jsConvertData(max_val, None)
        return JsNumber.JsNumber(
            "Math.random() * (%(max)s - %(min)s + 1) + %(min)s" % {
                "min": min_val,
                "max": max_val
            })
Пример #3
0
class DataReduce(object):
    """
  Description:
  -----------

  rVal  :
  val   :
  index :
  """
    rVal, val, index = JsObject.JsObject("r"), JsNumber.JsNumber(
        "o", isPyData=False), JsNumber.JsNumber("i", isPyData=False)
Пример #4
0
class DataReduce:
    """
  Description:
  -----------

  rVal  :
  val   :
  index :
  """
    rVal, val = JsObject.JsObject("r"), JsNumber.JsNumber("o",
                                                          is_py_data=False)
    index = JsNumber.JsNumber("i", is_py_data=False)
Пример #5
0
    def round(self, number: Union[float, primitives.JsDataModel]):
        """
    Description:
    ------------
    The round() method rounds a number to the nearest integer.

    Note: 2.49 will be rounded down (2), and 2.5 will be rounded up (3).

    Usage::

      jsObj.objects.number.new(23.6, varName="MyNumber")
      jsObj.math.round(jsObj.objects.number.get("MyNumber"))

    Related Pages:

      https//www.w3schools.com/jsref/jsref_round.asp

    Attributes:
    ----------
    :param Union[float, primitives.JsDataModel] number: The number to be rounded.

    :return: Rounds x to the nearest integer.
    """
        number = JsUtils.jsConvertData(number, None)
        return JsNumber.JsNumber("Math.round(%s)" % number, is_py_data=False)
Пример #6
0
    def min(self, *args):
        """
    Description:
    ------------
    The min() method returns the number with the lowest value.

    Usage::

      jsObj.math.min(10, 45, 100, -3, 56)

    Related Pages:

      https://www.w3schools.com/jsref/jsref_min.asp

    Attributes:
    ----------
    :param args: Optional. One or more numbers to compare.

    :return: A Number, representing the lowest number of the arguments, or Infinity
    if no arguments are given, or NaN if one or more arguments are not numbers
    """
        js_args = [JsUtils.jsConvertData(a, None) for a in args]
        return JsNumber.JsNumber("Math.min(%s)" %
                                 ",".join([str(jsa) for jsa in js_args]),
                                 is_py_data=False)
Пример #7
0
    def which(self):
        """
    The which property returns a number that indicates which mouse button was pressed when a mouse event was triggered.

    https://www.w3schools.com/jsref/event_which.asp
    """
        return JsNumber.JsNumber("event.which", isPyData=False)
Пример #8
0
    def PI(self):
        """
    The PI property returns the ratio of a circle's area to the square of its radius, approximately 3.14

    https://www.w3schools.com/jsref/jsref_pi.asp
    """
        return JsNumber.JsNumber("Math.PI", isPyData=False)
Пример #9
0
    def width(self):
        """
    Description:
    -----------

    """
        return JsNumber.JsNumber("%s.width" % self.varId)
Пример #10
0
    def width(self):
        """
    Description:
    ------------

    """
        return JsNumber.JsNumber("%s.width" % self.varId, is_py_data=False)
Пример #11
0
    def reduce(self,
               js_funcs: Union[list, str],
               profile: Union[dict, bool] = False):
        """
    Description:
    -----------
    The reduce() method reduces the array to a single value.

    Usage::

      jsObj.console.log(jsObj.objects.array.get("MyArray").reduce([
      jsObj.data.reduce.val + jsObj.data.reduce.rVal,
      jsObj.return_(jsObj.data.reduce.val)]))

    Related Pages:

      https://www.w3schools.com/jsref/jsref_reduce.asp

    Attributes:
    ----------
    :param Union[list, str] js_funcs: function(currentValue, index, arr)	Required. A function to be run for each
    element in the array.
    :param Union[dict, bool] profile: Optional. A flag to set the component performance storage.

    :return: A Python / Javascript Number
    """
        from epyk.core.js.primitives import JsNumber

        js_funcs = JsUtils.jsConvertFncs(js_funcs, toStr=True, profile=profile)
        return JsNumber.JsNumber("%s.reduce(function (r, o, i){%s})" %
                                 (self.varId, js_funcs))
Пример #12
0
    def push(self, *args):
        """
    Description:
    -----------
    The push() method adds new items to the end of an array, and returns the new length.

    Usage::

      jsObj.objects.array.new([2, 5, 12, -3], "MyArray")
      jsObj.objects.array.get("MyArray").push(55, -17)

    Related Pages:

      https://www.w3schools.com/js/js_array_methods.asp

    Attributes:
    ----------
    :param args: A list of object to be added to the JsArray object

    :return: A Number, representing the new length of the array
    """
        from epyk.core.js.primitives import JsNumber

        return JsNumber.JsNumber("%s.push(%s)" % (self.varId, ", ".join(
            [str(JsUtils.jsConvertData(a, None)) for a in args])),
                                 is_py_data=False)
Пример #13
0
    def reduce(self, jsFnc):
        """
    Description:
    -----------
    The reduce() method reduces the array to a single value.

    Usage::

      jsObj.console.log(jsObj.objects.array.get("MyArray").reduce([
      jsObj.data.reduce.val + jsObj.data.reduce.rVal,
      jsObj.return_(jsObj.data.reduce.val)]))

    Related Pages:

      https://www.w3schools.com/jsref/jsref_reduce.asp

    Attributes:
    ----------
    :param jsFnc: The Javascript function used by the reduce method

    :return: A Python / Javascript Number
    """
        from epyk.core.js.primitives import JsNumber

        jsFnc = JsUtils.jsConvertFncs(jsFnc)
        return JsNumber.JsNumber("%s.reduce(function (r, o, i){%s})" %
                                 (self.varId, ";".join(jsFnc)))
Пример #14
0
    def pow(number: Union[primitives.JsDataModel, float],
            power: Union[primitives.JsDataModel, int]):
        """
    Description:
    ------------
    The pow() method returns the value of x to the power of y (xy).

    Usage::

      jsObj.objects.number.new(23.6, varName="MyNumber")
      jsObj.math.pow(jsObj.objects.number.get("MyNumber"), 2)

    Related Pages:

      https//www.w3schools.com/jsref/jsref_pow.asp

    Attributes:
    ----------
    :param Union[float, primitives.JsDataModel] number: The base.
    :param Union[int, primitives.JsDataModel] power: The exponent.

    :return: Returns the value of x to the power of y.
    """
        number = JsUtils.jsConvertData(number, None)
        power = JsUtils.jsConvertData(power, None)
        return JsNumber.JsNumber("Math.pow(%s, %s)" % (number, power),
                                 is_py_data=False)
Пример #15
0
    def max(self, *args):
        """
    Description:
    ------------
    The max() method returns the number with the highest value.

    Usage::

      jsObj.math.max(10, 45, 100, -3, 56)

    Related Pages:

      https://www.w3schools.com/jsref/jsref_max.asp
      https://www.jstips.co/en/javascript/calculate-the-max-min-value-from-an-array/

    Attributes:
    ----------
    :param args: Optional. One or more numbers to compare.

    :return: A Number, representing the highest number of the arguments, or -Infinity if no arguments are given, or NaN
    if one or more arguments are not numbers
    """
        js_args = [JsUtils.jsConvertData(a, None) for a in args]
        if len(js_args) == 1 and getattr(js_args[0], '_jsClass',
                                         None) == "Array":
            # ES2015 use of the new spread operator
            js_args[0] = "...%s" % js_args[0]
        return JsNumber.JsNumber("Math.max(%s)" %
                                 ",".join([str(jsa) for jsa in js_args]),
                                 is_py_data=False)
Пример #16
0
  def getTime(self, in_seconds=True):
    """
    Description:
    -----------
    To get the unix timestamp using JavaScript you need to use the getTime() function of the build in Date object.
    As this returns the number of milliseconds then we must divide the number by 1000 and round it in order to get the timestamp in seconds.

    Attributes:
    ----------
    :param in_seconds: Boolean. In second conversion of the Javascript timestamp
    """
    from epyk.core.js.primitives import JsNumber

    if in_seconds:
      return JsNumber.JsNumber("%s.getTime()/1000" % self.varId, isPyData=False)

    return JsNumber.JsNumber("%s.getTime()" % self.varId, isPyData=False)
Пример #17
0
    def buttons(self):
        """
    The buttons property returns a number that indicates which mouse button or mouse buttons were pressed when a mouse event was triggered.

    Related Pages:

      https://www.w3schools.com/jsref/event_buttons.asp
    """
        return JsNumber.JsNumber("event.buttons", isPyData=False)
Пример #18
0
    def currentYear(self):
        """
    Description:
    ------------
    The current year. E.x. 2099

    :return:
    """
        return JsNumber.JsNumber("%s.currentYear" % self._src.js.varName,
                                 report=self._report)
Пример #19
0
    def currentMonth(self):
        """
    Description:
    ------------
    A 0-index number representing the current month. For example, 0 represents January.

    :return:
    """
        return JsNumber.JsNumber("%s.currentMonth" % self._src.js.varName,
                                 report=self._report)
Пример #20
0
    def detail(self):
        """
    Description:
    ------------
    The detail property returns a number with details about the event.

    Related Pages:

      https://www.w3schools.com/jsref/event_detail.asp
    """
        return JsNumber.JsNumber("event.detail", isPyData=False)
Пример #21
0
class DataAll:
    """
  Description:
  -----------
  Data Class for the Jquery each loop

  index : index
  data  : elt
  """
    index, element = JsNumber.JsNumber(
        "index", is_py_data=False), JsNodeDom.JsDoms.get(js_code="elt")
Пример #22
0
    def time(self):
        """
    Description:
    ------------
    The IntersectionObserverEntry interface's read-only time property is a DOMHighResTimeStamp that indicates the time at which the intersection change occurred relative to the time at which the document was created.

    Related Pages:

      https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry/time
    """
        return JsNumber.JsNumber("%s.time")
Пример #23
0
class DataEach:
    """
  Description:
  -----------
  Data Class for the Jquery each loop

  index : index
  data  : element
  """
    index, data = JsNumber.JsNumber(
        "index", is_py_data=False), JsObject.JsObject("data", is_py_data=False)
Пример #24
0
    def y(self):
        """
    Description:
    -----------
    The y read-only property of the DOMRectReadOnly interface represents the y coordinate of the DOMRect's origin.

    Related Pages:

      https://developer.mozilla.org/en-US/docs/Web/API/DOMRectReadOnly/y
    """
        return JsNumber.JsNumber("%s.y" % self.varId)
Пример #25
0
    def readyState(self):
        """
    Description:
    ------------
    The XMLHttpRequest.readyState property returns the state an XMLHttpRequest client is in.

    Related Pages:

      https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
    """
        return JsNumber.JsNumber("%s.readyState" % self.varId)
Пример #26
0
class DataAll(object):
    """
  Description:
  -----------
  Data Class for the Jquery each loop

  index : index
  data  : elt
  """
    index, element = JsNumber.JsNumber(
        "index", isPyData=False), JsNodeDom.JsDoms.get(varName="elt")
Пример #27
0
    def height(self):
        """
    Description:
    -----------
    The height read-only property of the DOMRectReadOnly interface represents the height of the DOMRect.

    Related Pages:

      https://developer.mozilla.org/en-US/docs/Web/API/DOMRectReadOnly/height
    """
        return JsNumber.JsNumber("%s.height" % self.varId)
Пример #28
0
  def parseInt(self):
    """
    Description:
    ------------
    Convert the object to integer on the JavaScript side.

    :return: A Python Javascript Integer
    """
    from epyk.core.js.primitives import JsNumber

    return JsNumber.JsNumber("parseInt(%s)" % self.varId, is_py_data=False)
Пример #29
0
    def location(self):
        """
    Description:
    ------------
    The location property returns a number that indicates the location of a key on the keyboard or device.

    Related Pages:

      https://www.w3schools.com/jsref/event_key_location.asp
    """
        return JsNumber.JsNumber("event.location", isPyData=False)
Пример #30
0
    def which(self):
        """
    Description:
    ------------
    The which property returns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event.

    Related Pages:

      https://www.w3schools.com/jsref/event_key_which.asp
    """
        return JsNumber.JsNumber("event.which", isPyData=False)