signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def generate_word():
return choice(INITIAL_CONSONANTS)+ choice(choice(['<STR_LIT>', list(double_vowels())]))+ choice(['<STR_LIT>', choice(FINAL_CONSONANTS)])<EOL>
:return: str >>> generate_word()
f3449:m0
def length(self, min_length, max_length):
min_length = min_length or self.min_length<EOL>max_length = max_length or self.max_length<EOL>if not min_length and not max_length:<EOL><INDENT>return<EOL><DEDENT>length = min_length + randrange(max_length - min_length)<EOL>char = self._generate_nextchar(self.total_sum, self.start_freq)<EOL>a = ord('<STR_LIT:a>')<EOL>w...
:param min_length: :param max_length: :return: >>> PronounceableWord().length(6, 10) 'centte'
f3449:c0:m1
def __init__(self, leet=None):
self.possible_syllables = sorted(set(possible_syllables()), key=len, reverse=True)<EOL>self.substitution = dict()<EOL>if leet is not None:<EOL><INDENT>for k, v in leet.items():<EOL><INDENT>for symbol in v:<EOL><INDENT>self.substitution.setdefault(symbol, []).append(k)<EOL><DEDENT><DEDENT><DEDENT>
:param dict leet: leet substitutions
f3452:c0:m0
def __init__(self, leet=None, common_words=None):
if leet is None:<EOL><INDENT>with open(database_path('<STR_LIT>')) as f:<EOL><INDENT>leet = yaml.safe_load(f)['<STR_LIT>']<EOL><DEDENT><DEDENT>self.common_words = dict()<EOL>if common_words is None:<EOL><INDENT>with open(database_path('<STR_LIT>')) as f:<EOL><INDENT>for i, row in enumerate(f):<EOL><INDENT>self.common_w...
:param dict leet: a dictionary containing leet substitutions (see leetspeak.yaml) :param list common_words: a list containing common words, sorted by commonness
f3452:c1:m0
def rareness(self, password, min_word_fragment_length=<NUM_LIT:3>, absolute_rareness_cutoff=<NUM_LIT:0.1>):
sub_words = list()<EOL>for i_front in range(<NUM_LIT:0>, len(password) - min_word_fragment_length + <NUM_LIT:1>):<EOL><INDENT>for i_back in range(i_front + min_word_fragment_length, len(password) + <NUM_LIT:1>):<EOL><INDENT>sub_words.append(password[i_front:i_back])<EOL><DEDENT><DEDENT>all_valid_com = set()<EOL>total_s...
:param password: :param int min_word_fragment_length: :param float absolute_rareness_cutoff: :return int: in range 0-1 >>> Complexity().rareness('thethethe') 0.0 >>> Complexity().rareness('poison') # the last word in Google's list 0.19649219348046737 >>> Complexity().rareness('asdfegu') 1 >>> Complexity().rareness('he...
f3452:c1:m3
def rareness2(self, password, min_word_fragment_length=<NUM_LIT:3>, commonness_of_non_word=<NUM_LIT>):
from time import time<EOL>def get_min_commonness_value(commonness_list):<EOL><INDENT>nonlocal commonness_value<EOL>value = sum(commonness_list)/len(commonness_list)<EOL>if value < commonness_value:<EOL><INDENT>commonness_value = value<EOL><DEDENT><DEDENT>def recurse(previous):<EOL><INDENT>nonlocal separators, depth, us...
A logical way to calculate rareness, but the speed is illogical for length > 40. (length 45: 60 sec per test) :param password: :param int min_word_fragment_length: :param int commonness_of_non_word: an arbitrary value to improve commonness of 'poison' :return int: in range 0-1 >>> Complexity().rareness2('thethethe') 0...
f3452:c1:m4
@staticmethod<EOL><INDENT>def consecutiveness(password, consecutive_length=<NUM_LIT:3>):<DEDENT>
consec = <NUM_LIT:0><EOL>for i in range(len(password) - consecutive_length):<EOL><INDENT>if all([char.islower() for char in password[i:i+consecutive_length]]):<EOL><INDENT>consec += <NUM_LIT:1><EOL><DEDENT>elif all([char.islower() for char in password[i:i+consecutive_length]]):<EOL><INDENT>consec += <NUM_LIT:1><EOL><DE...
Consecutiveness is the enemy of entropy, but makes it easier to remember. :param str password: :param int consecutive_length: length of the segment to be uniform to consider loss of entropy :param int base_length: usual length of the password :return int: in range 0-1 >>> Complexity.consecutiveness('password') 1.0 >>> ...
f3452:c1:m5
def complexity_initial(length=<NUM_LIT:15>):
password = gp.new_initial_password(min_length=length)[<NUM_LIT:0>]<EOL>if password is not None:<EOL><INDENT>return complexity.complexity(password[:length])<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>
:return: length=10: Best: 3.69, 3.72, 3.87; Worst: 6.36, 6.56, 6.77 length=15: Best: 3.74, 4.77, 4.82; Worst: 6.97, 7.25, 7.50
f3459:m0
def complexity_diceware_policy_conformized(number_of_words=<NUM_LIT:4>):
password = gp.new_diceware_password(number_of_words=number_of_words)[<NUM_LIT:0>]<EOL>if password is not None:<EOL><INDENT>return complexity.complexity(password)<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>
:return: number_of_words=4: Best: 5.65, 6.11, 6.13; Worst: 9.89, 9.96, 11.63
f3459:m1
def complexity_common_diceware_policy_conformized(number_of_words=<NUM_LIT:4>):
password = gp.new_common_diceware_password(number_of_words=number_of_words)[<NUM_LIT:0>]<EOL>if password is not None:<EOL><INDENT>return complexity.complexity(password)<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>
:return: number_of_words=4: Best: 4.31, 4.69, 4.97; Worst: 9.13, 9.15, 9.33 number_of_words=6: Best: 5.71, 5.78, 5.93; Worst: 10.98, 11.27, 12.09
f3459:m2
def complexity_common_diceware_all_lower(number_of_words=<NUM_LIT:4>):
password = '<STR_LIT>'.join([word_tool.get_random_common_word() for _ in range(number_of_words)])<EOL>print(password)<EOL>return complexity.complexity(password)<EOL>
:param number_of_words: :return: number_of_words=4: Best: 2.25, 2.30, 2.58; Worst: 4.49, 4.52, 4.56 number_of_words=6: Best: 3.62, 3.65, 3.71; Worst: 6.10, 6.22, 6.23
f3459:m3
def complexity_pronounceable_word_all_lower(number_of_words=<NUM_LIT:6>):
password = '<STR_LIT>'.join([generate_word() for _ in range(number_of_words)])<EOL>return complexity.complexity(password)<EOL>
:param number_of_words: :return: number_of_words=4: Best: 2.16, 2.67, 3.08; Worst: 4.31, 4.51, 4.72 number_of_words=6: Best: 3.56, 3.58, 3.69; Worst: 5.33, 5.33, 5.74
f3459:m4
def complexity_pronounceable_length_all_lower(min_length=<NUM_LIT:20>):
password = pw.length(min_length, min_length+<NUM_LIT:5>)<EOL>return complexity.complexity(password)<EOL>
:param min_length: :return: min_length=15: Best: 1.70, 2.44, 2.61; Worst: 4.51, 4.51, 4.92 min_length=20: Best: 2.33, 2.41, 2.57; Worst: 4.92, 4.92, 4.92
f3459:m5
def __init__(self, lines=None, fixed_lines=None, width=None,<EOL>fullscreen=None, location=None,<EOL>exit_hotkeys=('<STR_LIT>', '<STR_LIT>'), rofi_args=None):
<EOL>self._process = None<EOL>self.lines = lines<EOL>self.fixed_lines = fixed_lines<EOL>self.width = width<EOL>self.fullscreen = fullscreen<EOL>self.location = location<EOL>self.exit_hotkeys = exit_hotkeys<EOL>self.rofi_args = rofi_args or []<EOL>atexit.register(self.close)<EOL>
Parameters ---------- exit_hotkeys: tuple of strings Hotkeys to use to exit the application. These will be automatically set and handled in any method which takes hotkey arguments. If one of these hotkeys is pressed, a SystemExit will be raised to perform the exit. The following parameters set default ...
f3460:c0:m0
@classmethod<EOL><INDENT>def escape(self, string):<DEDENT>
<EOL>return string.translate(<EOL>{<NUM_LIT>: '<STR_LIT>'}<EOL>).translate({<EOL><NUM_LIT>: '<STR_LIT>',<EOL><NUM_LIT>: '<STR_LIT>',<EOL><NUM_LIT>: '<STR_LIT>',<EOL><NUM_LIT>: '<STR_LIT>'<EOL>})<EOL>
Escape a string for Pango markup. Parameters ---------- string: A piece of text to escape. Returns ------- The text, safe for use in with Pango markup.
f3460:c0:m1
def close(self):
if self._process:<EOL><INDENT>self._process.send_signal(signal.SIGINT)<EOL>if hasattr(subprocess, '<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>self._process.wait(timeout=<NUM_LIT:1>)<EOL><DEDENT>except subprocess.TimeoutExpired:<EOL><INDENT>self._process.send_signal(signal.SIGKILL)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>c...
Close any open window. Note that this only works with non-blocking methods.
f3460:c0:m2
def _run_blocking(self, args, input=None):
<EOL>if self._process:<EOL><INDENT>self.close()<EOL><DEDENT>kwargs = {}<EOL>kwargs['<STR_LIT>'] = subprocess.PIPE<EOL>kwargs['<STR_LIT>'] = True<EOL>if hasattr(subprocess, '<STR_LIT>'):<EOL><INDENT>result = subprocess.run(args, input=input, **kwargs)<EOL>return result.returncode, result.stdout<EOL><DEDENT>if input is n...
Internal API: run a blocking command with subprocess. This closes any open non-blocking dialog before running the command. Parameters ---------- args: Popen constructor arguments Command to run. input: string Value to feed to the stdin of the process. ...
f3460:c0:m3
def _run_nonblocking(self, args, input=None):
<EOL>if self._process:<EOL><INDENT>self.close()<EOL><DEDENT>self._process = subprocess.Popen(args, stdout=subprocess.PIPE)<EOL>
Internal API: run a non-blocking command with subprocess. This closes any open non-blocking dialog before running the command. Parameters ---------- args: Popen constructor arguments Command to run. input: string Value to feed to the stdin of the process...
f3460:c0:m4
def error(self, message, rofi_args=None, **kwargs):
rofi_args = rofi_args or []<EOL>args = ['<STR_LIT>', '<STR_LIT>', message]<EOL>args.extend(self._common_args(allow_fullscreen=False, **kwargs))<EOL>args.extend(rofi_args)<EOL>self._run_blocking(args)<EOL>
Show an error window. This method blocks until the user presses a key. Fullscreen mode is not supported for error windows, and if specified will be ignored. Parameters ---------- message: string Error message to show.
f3460:c0:m6
def status(self, message, rofi_args=None, **kwargs):
rofi_args = rofi_args or []<EOL>args = ['<STR_LIT>', '<STR_LIT>', message]<EOL>args.extend(self._common_args(allow_fullscreen=False, **kwargs))<EOL>args.extend(rofi_args)<EOL>self._run_nonblocking(args)<EOL>
Show a status message. This method is non-blocking, and intended to give a status update to the user while something is happening in the background. To close the window, either call the close() method or use any of the display methods to replace it with a different window. Ful...
f3460:c0:m7
def select(self, prompt, options, rofi_args=None, message="<STR_LIT>", select=None, **kwargs):
rofi_args = rofi_args or []<EOL>optionstr = '<STR_LIT:\n>'.join(option.replace('<STR_LIT:\n>', '<STR_LIT:U+0020>') for option in options)<EOL>args = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', prompt, '<STR_LIT>', '<STR_LIT:i>']<EOL>if select is not None:<EOL><INDENT>args.extend(['<STR_LIT>', str(select)])<EOL><DEDENT>disp...
Show a list of options and return user selection. This method blocks until the user makes their choice. Parameters ---------- prompt: string The prompt telling the user what they are selecting. options: list of strings The options they can choose from. A...
f3460:c0:m8
def generic_entry(self, prompt, validator=None, message=None, rofi_args=None, **kwargs):
error = "<STR_LIT>"<EOL>rofi_args = rofi_args or []<EOL>while True:<EOL><INDENT>args = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', prompt, '<STR_LIT>', '<STR_LIT:s>']<EOL>msg = message or "<STR_LIT>"<EOL>if error:<EOL><INDENT>msg = '<STR_LIT>'.format(error, msg)<EOL>msg = msg.rstrip('<STR_LIT:\n>')<EOL><DEDENT>if msg:<EOL>...
A generic entry box. Parameters ---------- prompt: string Text prompt for the entry. validator: function, optional A function to validate and convert the value entered by the user. It should take one parameter, the string that the user entered, and ...
f3460:c0:m9
def text_entry(self, prompt, message=None, allow_blank=False, strip=True,<EOL>rofi_args=None, **kwargs):
def text_validator(text):<EOL><INDENT>if strip:<EOL><INDENT>text = text.strip()<EOL><DEDENT>if not allow_blank:<EOL><INDENT>if not text:<EOL><INDENT>return None, "<STR_LIT>"<EOL><DEDENT><DEDENT>return text, None<EOL><DEDENT>return self.generic_entry(prompt, text_validator, message, rofi_args, **kwargs)<EOL>
Prompt the user to enter a piece of text. Parameters ---------- prompt: string Prompt to display to the user. message: string, optional Message to display under the entry line. allow_blank: Boolean Whether to allow blank entries. strip...
f3460:c0:m10
def integer_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
<EOL>if (min is not None) and (max is not None) and not (max > min):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>def integer_validator(text):<EOL><INDENT>error = None<EOL>try:<EOL><INDENT>value = int(text)<EOL><DEDENT>except ValueError:<EOL><INDENT>return None, "<STR_LIT>"<EOL><DEDENT>if (min is not None) and...
Prompt the user to enter an integer. Parameters ---------- prompt: string Prompt to display to the user. message: string, optional Message to display under the entry line. min, max: integer, optional Minimum and maximum values to allow. If Non...
f3460:c0:m11
def float_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
<EOL>if (min is not None) and (max is not None) and not (max > min):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>def float_validator(text):<EOL><INDENT>error = None<EOL>try:<EOL><INDENT>value = float(text)<EOL><DEDENT>except ValueError:<EOL><INDENT>return None, "<STR_LIT>"<EOL><DEDENT>if (min is not None) and...
Prompt the user to enter a floating point number. Parameters ---------- prompt: string Prompt to display to the user. message: string, optional Message to display under the entry line. min, max: float, optional Minimum and maximum values to al...
f3460:c0:m12
def decimal_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
<EOL>if (min is not None) and (max is not None) and not (max > min):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>def decimal_validator(text):<EOL><INDENT>error = None<EOL>try:<EOL><INDENT>value = Decimal(text)<EOL><DEDENT>except InvalidOperation:<EOL><INDENT>return None, "<STR_LIT>"<EOL><DEDENT>if (min is not...
Prompt the user to enter a decimal number. Parameters ---------- prompt: string Prompt to display to the user. message: string, optional Message to display under the entry line. min, max: Decimal, optional Minimum and maximum values to allow. ...
f3460:c0:m13
def date_entry(self, prompt, message=None, formats=['<STR_LIT>', '<STR_LIT>'],<EOL>show_example=False, rofi_args=None, **kwargs):
def date_validator(text):<EOL><INDENT>for format in formats:<EOL><INDENT>try:<EOL><INDENT>dt = datetime.strptime(text, format)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>return (dt.date(), None)<EOL><DEDENT><DEDENT>return (None, '<STR_LIT>')<EOL><DEDENT>if show_example:<EOL><INDEN...
Prompt the user to enter a date. Parameters ---------- prompt: string Prompt to display to the user. message: string, optional Message to display under the entry line. formats: list of strings, optional The formats that the user can enter date...
f3460:c0:m14
def time_entry(self, prompt, message=None, formats=['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>'], show_example=False, rofi_args=None, **kwargs):
def time_validator(text):<EOL><INDENT>for format in formats:<EOL><INDENT>try:<EOL><INDENT>dt = datetime.strptime(text, format)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>return (dt.time(), None)<EOL><DEDENT><DEDENT>return (None, '<STR_LIT>')<EOL><DEDENT>if show_example:<EOL><INDEN...
Prompt the user to enter a time. Parameters ---------- prompt: string Prompt to display to the user. message: string, optional Message to display under the entry line. formats: list of strings, optional The formats that the user can enter time...
f3460:c0:m15
def datetime_entry(self, prompt, message=None, formats=['<STR_LIT>'], show_example=False,<EOL>rofi_args=None, **kwargs):
def datetime_validator(text):<EOL><INDENT>for format in formats:<EOL><INDENT>try:<EOL><INDENT>dt = datetime.strptime(text, format)<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>return (dt, None)<EOL><DEDENT><DEDENT>return (None, '<STR_LIT>')<EOL><DEDENT>if show_example:<EOL><INDENT>m...
Prompt the user to enter a date and time. Parameters ---------- prompt: string Prompt to display to the user. message: string, optional Message to display under the entry line. formats: list of strings, optional The formats that the user can e...
f3460:c0:m16
def exit_with_error(self, error, **kwargs):
self.error(error, **kwargs)<EOL>raise SystemExit(error)<EOL>
Report an error and exit. This raises a SystemExit exception to ask the interpreter to quit. Parameters ---------- error: string The error to report before quitting.
f3460:c0:m17
def hex_color(value):
r = ((value >> (<NUM_LIT:8> * <NUM_LIT:2>)) & <NUM_LIT:255>) / <NUM_LIT><EOL>g = ((value >> (<NUM_LIT:8> * <NUM_LIT:1>)) & <NUM_LIT:255>) / <NUM_LIT><EOL>b = ((value >> (<NUM_LIT:8> * <NUM_LIT:0>)) & <NUM_LIT:255>) / <NUM_LIT><EOL>return (r, g, b)<EOL>
Accepts a hexadecimal color `value` in the format ``0xrrggbb`` and returns an (r, g, b) tuple where 0.0 <= r, g, b <= 1.0.
f3487:m0
def normalize(vector):
d = sum(x * x for x in vector) ** <NUM_LIT:0.5><EOL>return tuple(x / d for x in vector)<EOL>
Normalizes the `vector` so that its length is 1. `vector` can have any number of components.
f3487:m1
def distance(p1, p2):
return sum((a - b) ** <NUM_LIT:2> for a, b in zip(p1, p2)) ** <NUM_LIT:0.5><EOL>
Computes and returns the distance between two points, `p1` and `p2`. The points can have any number of components.
f3487:m2
def cross(v1, v2):
return (<EOL>v1[<NUM_LIT:1>] * v2[<NUM_LIT:2>] - v1[<NUM_LIT:2>] * v2[<NUM_LIT:1>],<EOL>v1[<NUM_LIT:2>] * v2[<NUM_LIT:0>] - v1[<NUM_LIT:0>] * v2[<NUM_LIT:2>],<EOL>v1[<NUM_LIT:0>] * v2[<NUM_LIT:1>] - v1[<NUM_LIT:1>] * v2[<NUM_LIT:0>],<EOL>)<EOL>
Computes the cross product of two vectors.
f3487:m3
def dot(v1, v2):
x1, y1, z1 = v1<EOL>x2, y2, z2 = v2<EOL>return x1 * x2 + y1 * y2 + z1 * z2<EOL>
Computes the dot product of two vectors.
f3487:m4
def add(v1, v2):
return tuple(a + b for a, b in zip(v1, v2))<EOL>
Adds two vectors.
f3487:m5
def sub(v1, v2):
return tuple(a - b for a, b in zip(v1, v2))<EOL>
Subtracts two vectors.
f3487:m6
def mul(v, s):
return tuple(a * s for a in v)<EOL>
Multiplies a vector and a scalar.
f3487:m7
def neg(vector):
return tuple(-x for x in vector)<EOL>
Negates a vector.
f3487:m8
def interpolate(v1, v2, t):
return add(v1, mul(sub(v2, v1), t))<EOL>
Interpolate from one vector to another.
f3487:m9
def normal_from_points(a, b, c):
x1, y1, z1 = a<EOL>x2, y2, z2 = b<EOL>x3, y3, z3 = c<EOL>ab = (x2 - x1, y2 - y1, z2 - z1)<EOL>ac = (x3 - x1, y3 - y1, z3 - z1)<EOL>x, y, z = cross(ab, ac)<EOL>d = (x * x + y * y + z * z) ** <NUM_LIT:0.5><EOL>return (x / d, y / d, z / d)<EOL>
Computes a normal vector given three points.
f3487:m10
def smooth_normals(positions, normals):
lookup = defaultdict(list)<EOL>for position, normal in zip(positions, normals):<EOL><INDENT>lookup[position].append(normal)<EOL><DEDENT>result = []<EOL>for position in positions:<EOL><INDENT>tx = ty = tz = <NUM_LIT:0><EOL>for x, y, z in lookup[position]:<EOL><INDENT>tx += x<EOL>ty += y<EOL>tz += z<EOL><DEDENT>d = (tx *...
Assigns an averaged normal to each position based on all of the normals originally used for the position.
f3487:m11
def bounding_box(positions):
(x0, y0, z0) = (x1, y1, z1) = positions[<NUM_LIT:0>]<EOL>for x, y, z in positions:<EOL><INDENT>x0 = min(x0, x)<EOL>y0 = min(y0, y)<EOL>z0 = min(z0, z)<EOL>x1 = max(x1, x)<EOL>y1 = max(y1, y)<EOL>z1 = max(z1, z)<EOL><DEDENT>return (x0, y0, z0), (x1, y1, z1)<EOL>
Computes the bounding box for a list of 3-dimensional points.
f3487:m12
def recenter(positions):
(x0, y0, z0), (x1, y1, z1) = bounding_box(positions)<EOL>dx = x1 - (x1 - x0) / <NUM_LIT><EOL>dy = y1 - (y1 - y0) / <NUM_LIT><EOL>dz = z1 - (z1 - z0) / <NUM_LIT><EOL>result = []<EOL>for x, y, z in positions:<EOL><INDENT>result.append((x - dx, y - dy, z - dz))<EOL><DEDENT>return result<EOL>
Returns a list of new positions centered around the origin.
f3487:m13
def interleave(*args):
result = []<EOL>for array in zip(*args):<EOL><INDENT>result.append(tuple(flatten(array)))<EOL><DEDENT>return result<EOL>
Interleaves the elements of the provided arrays. >>> a = [(0, 0), (1, 0), (2, 0), (3, 0)] >>> b = [(0, 0), (0, 1), (0, 2), (0, 3)] >>> interleave(a, b) [(0, 0, 0, 0), (1, 0, 0, 1), (2, 0, 0, 2), (3, 0, 0, 3)] This is useful for combining multiple vertex attributes into a single ...
f3487:m14
def flatten(array):
result = []<EOL>for value in array:<EOL><INDENT>result.extend(value)<EOL><DEDENT>return result<EOL>
Flattens the elements of the provided array, `data`. >>> a = [(0, 0), (1, 0), (2, 0), (3, 0)] >>> flatten(a) [0, 0, 1, 0, 2, 0, 3, 0] The flattening process is not recursive, it is only one level deep.
f3487:m15
def distinct(iterable, keyfunc=None):
seen = set()<EOL>for item in iterable:<EOL><INDENT>key = item if keyfunc is None else keyfunc(item)<EOL>if key not in seen:<EOL><INDENT>seen.add(key)<EOL>yield item<EOL><DEDENT><DEDENT>
Yields distinct items from `iterable` in the order that they appear.
f3487:m16
def ray_triangle_intersection(v1, v2, v3, o, d):
eps = <NUM_LIT><EOL>e1 = sub(v2, v1)<EOL>e2 = sub(v3, v1)<EOL>p = cross(d, e2)<EOL>det = dot(e1, p)<EOL>if abs(det) < eps:<EOL><INDENT>return None<EOL><DEDENT>inv = <NUM_LIT:1.0> / det<EOL>t = sub(o, v1)<EOL>u = dot(t, p) * inv<EOL>if u < <NUM_LIT:0> or u > <NUM_LIT:1>:<EOL><INDENT>return None<EOL><DEDENT>q = cross(t, ...
Computes the distance from a point to a triangle given a ray.
f3487:m17
def pack_list(fmt, data):
func = struct.Struct(fmt).pack<EOL>return create_string_buffer('<STR_LIT>'.join([func(x) for x in data]))<EOL>
Convert a Python list into a ctypes buffer. This appears to be faster than the typical method of creating a ctypes array, e.g. (c_float * len(data))(*data)
f3487:m18
def _find_library_candidates(library_names,<EOL>library_file_extensions,<EOL>library_search_paths):
candidates = set()<EOL>for library_name in library_names:<EOL><INDENT>for search_path in library_search_paths:<EOL><INDENT>glob_query = os.path.join(search_path, '<STR_LIT:*>'+library_name+'<STR_LIT:*>')<EOL>for filename in glob.iglob(glob_query):<EOL><INDENT>filename = os.path.realpath(filename)<EOL>if filename in can...
Finds and returns filenames which might be the library you are looking for.
f3493:m0
def _load_library(library_names, library_file_extensions,<EOL>library_search_paths, version_check_callback):
candidates = _find_library_candidates(library_names,<EOL>library_file_extensions,<EOL>library_search_paths)<EOL>library_versions = []<EOL>for filename in candidates:<EOL><INDENT>version = version_check_callback(filename)<EOL>if version is not None and version >= (<NUM_LIT:3>, <NUM_LIT:0>, <NUM_LIT:0>):<EOL><INDENT>libr...
Finds, loads and returns the most recent version of the library.
f3493:m1
def _glfw_get_version(filename):
version_checker_source = """<STR_LIT>"""<EOL>args = [sys.executable, '<STR_LIT:-c>', textwrap.dedent(version_checker_source)]<EOL>process = subprocess.Popen(args, universal_newlines=True,<EOL>stdin=subprocess.PIPE, stdout=subprocess.PIPE)<EOL>out = process.communicate(_to_char_p(filename))[<NUM_LIT:0>]<EOL>out = out.st...
Queries and returns the library version tuple or None by using a subprocess.
f3493:m2
def init():
cwd = _getcwd()<EOL>res = _glfw.glfwInit()<EOL>os.chdir(cwd)<EOL>return res<EOL>
Initializes the GLFW library. Wrapper for: int glfwInit(void);
f3493:m3
def terminate():
_glfw.glfwTerminate()<EOL>
Terminates the GLFW library. Wrapper for: void glfwTerminate(void);
f3493:m4
def get_version():
major_value = ctypes.c_int(<NUM_LIT:0>)<EOL>major = ctypes.pointer(major_value)<EOL>minor_value = ctypes.c_int(<NUM_LIT:0>)<EOL>minor = ctypes.pointer(minor_value)<EOL>rev_value = ctypes.c_int(<NUM_LIT:0>)<EOL>rev = ctypes.pointer(rev_value)<EOL>_glfw.glfwGetVersion(major, minor, rev)<EOL>return major_value.value, mino...
Retrieves the version of the GLFW library. Wrapper for: void glfwGetVersion(int* major, int* minor, int* rev);
f3493:m5
def get_version_string():
return _glfw.glfwGetVersionString()<EOL>
Returns a string describing the compile-time configuration. Wrapper for: const char* glfwGetVersionString(void);
f3493:m6
def set_error_callback(cbfun):
global _error_callback<EOL>previous_callback = _error_callback<EOL>if cbfun is None:<EOL><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWerrorfun(cbfun)<EOL>_error_callback = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetErrorCallback(cbfun)<EOL>if previous_callback is not None and previous_callback[<NUM...
Sets the error callback. Wrapper for: GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun);
f3493:m7
def get_monitors():
count_value = ctypes.c_int(<NUM_LIT:0>)<EOL>count = ctypes.pointer(count_value)<EOL>result = _glfw.glfwGetMonitors(count)<EOL>monitors = [result[i] for i in range(count_value.value)]<EOL>return monitors<EOL>
Returns the currently connected monitors. Wrapper for: GLFWmonitor** glfwGetMonitors(int* count);
f3493:m8
def get_primary_monitor():
return _glfw.glfwGetPrimaryMonitor()<EOL>
Returns the primary monitor. Wrapper for: GLFWmonitor* glfwGetPrimaryMonitor(void);
f3493:m9
def get_monitor_pos(monitor):
xpos_value = ctypes.c_int(<NUM_LIT:0>)<EOL>xpos = ctypes.pointer(xpos_value)<EOL>ypos_value = ctypes.c_int(<NUM_LIT:0>)<EOL>ypos = ctypes.pointer(ypos_value)<EOL>_glfw.glfwGetMonitorPos(monitor, xpos, ypos)<EOL>return xpos_value.value, ypos_value.value<EOL>
Returns the position of the monitor's viewport on the virtual screen. Wrapper for: void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos);
f3493:m10
def get_monitor_physical_size(monitor):
width_value = ctypes.c_int(<NUM_LIT:0>)<EOL>width = ctypes.pointer(width_value)<EOL>height_value = ctypes.c_int(<NUM_LIT:0>)<EOL>height = ctypes.pointer(height_value)<EOL>_glfw.glfwGetMonitorPhysicalSize(monitor, width, height)<EOL>return width_value.value, height_value.value<EOL>
Returns the physical size of the monitor. Wrapper for: void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* width, int* height);
f3493:m11
def get_monitor_name(monitor):
return _glfw.glfwGetMonitorName(monitor)<EOL>
Returns the name of the specified monitor. Wrapper for: const char* glfwGetMonitorName(GLFWmonitor* monitor);
f3493:m12
def set_monitor_callback(cbfun):
global _monitor_callback<EOL>previous_callback = _monitor_callback<EOL>if cbfun is None:<EOL><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWmonitorfun(cbfun)<EOL>_monitor_callback = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetMonitorCallback(cbfun)<EOL>if previous_callback is not None and previous_cal...
Sets the monitor configuration callback. Wrapper for: GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun);
f3493:m13
def get_video_modes(monitor):
count_value = ctypes.c_int(<NUM_LIT:0>)<EOL>count = ctypes.pointer(count_value)<EOL>result = _glfw.glfwGetVideoModes(monitor, count)<EOL>videomodes = [result[i].unwrap() for i in range(count_value.value)]<EOL>return videomodes<EOL>
Returns the available video modes for the specified monitor. Wrapper for: const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count);
f3493:m14
def get_video_mode(monitor):
videomode = _glfw.glfwGetVideoMode(monitor).contents<EOL>return videomode.unwrap()<EOL>
Returns the current mode of the specified monitor. Wrapper for: const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor);
f3493:m15
def set_gamma(monitor, gamma):
_glfw.glfwSetGamma(monitor, gamma)<EOL>
Generates a gamma ramp and sets it for the specified monitor. Wrapper for: void glfwSetGamma(GLFWmonitor* monitor, float gamma);
f3493:m16
def get_gamma_ramp(monitor):
gammaramp = _glfw.glfwGetGammaRamp(monitor).contents<EOL>return gammaramp.unwrap()<EOL>
Retrieves the current gamma ramp for the specified monitor. Wrapper for: const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor);
f3493:m17
def set_gamma_ramp(monitor, ramp):
gammaramp = _GLFWgammaramp()<EOL>gammaramp.wrap(ramp)<EOL>_glfw.glfwSetGammaRamp(monitor, ctypes.pointer(gammaramp))<EOL>
Sets the current gamma ramp for the specified monitor. Wrapper for: void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp);
f3493:m18
def default_window_hints():
_glfw.glfwDefaultWindowHints()<EOL>
Resets all window hints to their default values. Wrapper for: void glfwDefaultWindowHints(void);
f3493:m19
def window_hint(target, hint):
_glfw.glfwWindowHint(target, hint)<EOL>
Sets the specified window hint to the desired value. Wrapper for: void glfwWindowHint(int target, int hint);
f3493:m20
def create_window(width, height, title, monitor, share):
return _glfw.glfwCreateWindow(width, height, _to_char_p(title),<EOL>monitor, share)<EOL>
Creates a window and its associated context. Wrapper for: GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share);
f3493:m21
def destroy_window(window):
_glfw.glfwDestroyWindow(window)<EOL>window_addr = ctypes.cast(ctypes.pointer(window),<EOL>ctypes.POINTER(ctypes.c_ulong)).contents.value<EOL>for callback_repository in _callback_repositories:<EOL><INDENT>if window_addr in callback_repository:<EOL><INDENT>del callback_repository[window_addr]<EOL><DEDENT><DEDENT>
Destroys the specified window and its context. Wrapper for: void glfwDestroyWindow(GLFWwindow* window);
f3493:m22
def window_should_close(window):
return _glfw.glfwWindowShouldClose(window)<EOL>
Checks the close flag of the specified window. Wrapper for: int glfwWindowShouldClose(GLFWwindow* window);
f3493:m23
def set_window_should_close(window, value):
_glfw.glfwSetWindowShouldClose(window, value)<EOL>
Sets the close flag of the specified window. Wrapper for: void glfwSetWindowShouldClose(GLFWwindow* window, int value);
f3493:m24
def set_window_title(window, title):
_glfw.glfwSetWindowTitle(window, _to_char_p(title))<EOL>
Sets the title of the specified window. Wrapper for: void glfwSetWindowTitle(GLFWwindow* window, const char* title);
f3493:m25
def get_window_pos(window):
xpos_value = ctypes.c_int(<NUM_LIT:0>)<EOL>xpos = ctypes.pointer(xpos_value)<EOL>ypos_value = ctypes.c_int(<NUM_LIT:0>)<EOL>ypos = ctypes.pointer(ypos_value)<EOL>_glfw.glfwGetWindowPos(window, xpos, ypos)<EOL>return xpos_value.value, ypos_value.value<EOL>
Retrieves the position of the client area of the specified window. Wrapper for: void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos);
f3493:m26
def set_window_pos(window, xpos, ypos):
_glfw.glfwSetWindowPos(window, xpos, ypos)<EOL>
Sets the position of the client area of the specified window. Wrapper for: void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos);
f3493:m27
def get_window_size(window):
width_value = ctypes.c_int(<NUM_LIT:0>)<EOL>width = ctypes.pointer(width_value)<EOL>height_value = ctypes.c_int(<NUM_LIT:0>)<EOL>height = ctypes.pointer(height_value)<EOL>_glfw.glfwGetWindowSize(window, width, height)<EOL>return width_value.value, height_value.value<EOL>
Retrieves the size of the client area of the specified window. Wrapper for: void glfwGetWindowSize(GLFWwindow* window, int* width, int* height);
f3493:m28
def set_window_size(window, width, height):
_glfw.glfwSetWindowSize(window, width, height)<EOL>
Sets the size of the client area of the specified window. Wrapper for: void glfwSetWindowSize(GLFWwindow* window, int width, int height);
f3493:m29
def get_framebuffer_size(window):
width_value = ctypes.c_int(<NUM_LIT:0>)<EOL>width = ctypes.pointer(width_value)<EOL>height_value = ctypes.c_int(<NUM_LIT:0>)<EOL>height = ctypes.pointer(height_value)<EOL>_glfw.glfwGetFramebufferSize(window, width, height)<EOL>return width_value.value, height_value.value<EOL>
Retrieves the size of the framebuffer of the specified window. Wrapper for: void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height);
f3493:m30
def iconify_window(window):
_glfw.glfwIconifyWindow(window)<EOL>
Iconifies the specified window. Wrapper for: void glfwIconifyWindow(GLFWwindow* window);
f3493:m31
def restore_window(window):
_glfw.glfwRestoreWindow(window)<EOL>
Restores the specified window. Wrapper for: void glfwRestoreWindow(GLFWwindow* window);
f3493:m32
def show_window(window):
_glfw.glfwShowWindow(window)<EOL>
Makes the specified window visible. Wrapper for: void glfwShowWindow(GLFWwindow* window);
f3493:m33
def hide_window(window):
_glfw.glfwHideWindow(window)<EOL>
Hides the specified window. Wrapper for: void glfwHideWindow(GLFWwindow* window);
f3493:m34
def get_window_monitor(window):
return _glfw.glfwGetWindowMonitor(window)<EOL>
Returns the monitor that the window uses for full screen mode. Wrapper for: GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window);
f3493:m35
def get_window_attrib(window, attrib):
return _glfw.glfwGetWindowAttrib(window, attrib)<EOL>
Returns an attribute of the specified window. Wrapper for: int glfwGetWindowAttrib(GLFWwindow* window, int attrib);
f3493:m36
def set_window_user_pointer(window, pointer):
_glfw.glfwSetWindowUserPointer(window, pointer)<EOL>
Sets the user pointer of the specified window. Wrapper for: void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer);
f3493:m37
def get_window_user_pointer(window):
return _glfw.glfwGetWindowUserPointer(window)<EOL>
Returns the user pointer of the specified window. Wrapper for: void* glfwGetWindowUserPointer(GLFWwindow* window);
f3493:m38
def set_window_pos_callback(window, cbfun):
window_addr = ctypes.cast(ctypes.pointer(window),<EOL>ctypes.POINTER(ctypes.c_long)).contents.value<EOL>if window_addr in _window_pos_callback_repository:<EOL><INDENT>previous_callback = _window_pos_callback_repository[window_addr]<EOL><DEDENT>else:<EOL><INDENT>previous_callback = None<EOL><DEDENT>if cbfun is None:<EOL...
Sets the position callback for the specified window. Wrapper for: GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun);
f3493:m39
def set_window_size_callback(window, cbfun):
window_addr = ctypes.cast(ctypes.pointer(window),<EOL>ctypes.POINTER(ctypes.c_long)).contents.value<EOL>if window_addr in _window_size_callback_repository:<EOL><INDENT>previous_callback = _window_size_callback_repository[window_addr]<EOL><DEDENT>else:<EOL><INDENT>previous_callback = None<EOL><DEDENT>if cbfun is None:<E...
Sets the size callback for the specified window. Wrapper for: GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun);
f3493:m40
def set_window_close_callback(window, cbfun):
window_addr = ctypes.cast(ctypes.pointer(window),<EOL>ctypes.POINTER(ctypes.c_long)).contents.value<EOL>if window_addr in _window_close_callback_repository:<EOL><INDENT>previous_callback = _window_close_callback_repository[window_addr]<EOL><DEDENT>else:<EOL><INDENT>previous_callback = None<EOL><DEDENT>if cbfun is None:...
Sets the close callback for the specified window. Wrapper for: GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun cbfun);
f3493:m41
def set_window_refresh_callback(window, cbfun):
window_addr = ctypes.cast(ctypes.pointer(window),<EOL>ctypes.POINTER(ctypes.c_long)).contents.value<EOL>if window_addr in _window_refresh_callback_repository:<EOL><INDENT>previous_callback = _window_refresh_callback_repository[window_addr]<EOL><DEDENT>else:<EOL><INDENT>previous_callback = None<EOL><DEDENT>if cbfun is N...
Sets the refresh callback for the specified window. Wrapper for: GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun cbfun);
f3493:m42
def set_window_focus_callback(window, cbfun):
window_addr = ctypes.cast(ctypes.pointer(window),<EOL>ctypes.POINTER(ctypes.c_long)).contents.value<EOL>if window_addr in _window_focus_callback_repository:<EOL><INDENT>previous_callback = _window_focus_callback_repository[window_addr]<EOL><DEDENT>else:<EOL><INDENT>previous_callback = None<EOL><DEDENT>if cbfun is None:...
Sets the focus callback for the specified window. Wrapper for: GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun cbfun);
f3493:m43
def set_window_iconify_callback(window, cbfun):
window_addr = ctypes.cast(ctypes.pointer(window),<EOL>ctypes.POINTER(ctypes.c_long)).contents.value<EOL>if window_addr in _window_iconify_callback_repository:<EOL><INDENT>previous_callback = _window_iconify_callback_repository[window_addr]<EOL><DEDENT>else:<EOL><INDENT>previous_callback = None<EOL><DEDENT>if cbfun is N...
Sets the iconify callback for the specified window. Wrapper for: GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun);
f3493:m44
def set_framebuffer_size_callback(window, cbfun):
window_addr = ctypes.cast(ctypes.pointer(window),<EOL>ctypes.POINTER(ctypes.c_long)).contents.value<EOL>if window_addr in _framebuffer_size_callback_repository:<EOL><INDENT>previous_callback = _framebuffer_size_callback_repository[window_addr]<EOL><DEDENT>else:<EOL><INDENT>previous_callback = None<EOL><DEDENT>if cbfun ...
Sets the framebuffer resize callback for the specified window. Wrapper for: GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun cbfun);
f3493:m45
def poll_events():
_glfw.glfwPollEvents()<EOL>
Processes all pending events. Wrapper for: void glfwPollEvents(void);
f3493:m46
def wait_events():
_glfw.glfwWaitEvents()<EOL>
Waits until events are pending and processes them. Wrapper for: void glfwWaitEvents(void);
f3493:m47
def get_input_mode(window, mode):
return _glfw.glfwGetInputMode(window, mode)<EOL>
Returns the value of an input option for the specified window. Wrapper for: int glfwGetInputMode(GLFWwindow* window, int mode);
f3493:m48
def set_input_mode(window, mode, value):
_glfw.glfwSetInputMode(window, mode, value)<EOL>
Sets an input option for the specified window. @param[in] window The window whose input mode to set. @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or `GLFW_STICKY_MOUSE_BUTTONS`. @param[in] value The new value of the specified input mode. Wrapper for: void glfwSetInputMode(GLFWwindow* window, int mode, ...
f3493:m49
def get_key(window, key):
return _glfw.glfwGetKey(window, key)<EOL>
Returns the last reported state of a keyboard key for the specified window. Wrapper for: int glfwGetKey(GLFWwindow* window, int key);
f3493:m50