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>word = chr(char + a)<EOL>for i in range(<NUM_LIT:1>, length):<EOL><INDENT>char = self._generate_nextchar(self.row_sums[char],<EOL>DIGRAPHS_FREQUENCY[char])<EOL>word += chr(char + a)<EOL><DEDENT>return word<EOL>
|
: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_words[row.strip()] = i<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for i, word in enumerate(common_words):<EOL><INDENT>self.common_words[word] = i<EOL><DEDENT><DEDENT>super().__init__(leet)<EOL>
|
: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_sub_word_length = <NUM_LIT:0><EOL>for sub_word in sub_words:<EOL><INDENT>try:<EOL><INDENT>all_valid_com.add(self.common_words[sub_word] / len(sub_word))<EOL>total_sub_word_length += len(sub_word)<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>try:<EOL><INDENT>absolute_rareness = (((sum(all_valid_com, <NUM_LIT:0>)/len(all_valid_com)) / len(self.common_words))<EOL>* (len(sub_words) / total_sub_word_length**<NUM_LIT:2>)<EOL>* (len(password) / total_sub_word_length))<EOL>return math.sqrt(absolute_rareness/absolute_rareness_cutoff)if absolute_rareness < absolute_rareness_cutoff else <NUM_LIT:1><EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>
|
: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('helloworld')
0.1644235716987842
# Good words should eval less than 0.2
>>> Complexity().rareness('verylongpassword')
0.16626577386889024
>>> Complexity().rareness('averylongpassword')
0.1622989831750065
>>> Complexity().rareness('ultrasupersuperlonglonglongpasswordlongerthanlonger')
0.23084370223197
# Half gibberish should not eval 1
>>> Complexity().rareness('ultrasuperlongpasswordsdhsdhjksdskdhskjdhakdhsadjdi')
0.40519672587970423
# Gibberish of various length should eval approx. 1
>>> Complexity().rareness('faxwyhxihs')
1
>>> Complexity().rareness('aarhzcrzncseexdeccli')
1
>>> Complexity().rareness('qdhlivjpyyobhowxixzgupdhdsmzeu')
1
>>> Complexity().rareness('jjvkzlrjtraszzxrrztyrjhytvdjvvgujelareztwlkpuwutfw')
1
|
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, used_separators<EOL>depth += <NUM_LIT:1><EOL>for current in range(previous + min_word_fragment_length, len(password) - min_word_fragment_length + <NUM_LIT:1>):<EOL><INDENT>try:<EOL><INDENT>separators[depth] = current<EOL><DEDENT>except IndexError:<EOL><INDENT>separators.append(current)<EOL><DEDENT>if depth < number_of_separators - <NUM_LIT:1>:<EOL><INDENT>recurse(current)<EOL><DEDENT>else:<EOL><INDENT>used_separators.add(tuple(separators))<EOL><DEDENT><DEDENT>depth -= <NUM_LIT:1><EOL><DEDENT>start = time()<EOL>subword_commonness = dict()<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>subword_commonness[(i_front, i_back)]= self.common_words.get(password[i_front:i_back], commonness_of_non_word)/commonness_of_non_word<EOL><DEDENT><DEDENT>print('<STR_LIT>', time()-start)<EOL>start = time()<EOL>commonness_value = <NUM_LIT:1><EOL>used_separators = set()<EOL>for number_of_separators in range(len(password)//min_word_fragment_length):<EOL><INDENT>if number_of_separators == <NUM_LIT:0>:<EOL><INDENT>get_min_commonness_value({self.common_words.get(password, commonness_of_non_word)/commonness_of_non_word})<EOL><DEDENT>else:<EOL><INDENT>separators = list()<EOL>depth = -<NUM_LIT:1><EOL>recurse(<NUM_LIT:0>)<EOL><DEDENT><DEDENT>print('<STR_LIT>', time()-start)<EOL>start = time()<EOL>for sep in used_separators:<EOL><INDENT>commonness_list = set()<EOL>commonness_list.add(subword_commonness[(<NUM_LIT:0>, sep[<NUM_LIT:0>])])<EOL>for i in range(len(sep)-<NUM_LIT:1>):<EOL><INDENT>commonness_list.add(subword_commonness[(sep[i], sep[i + <NUM_LIT:1>])])<EOL><DEDENT>commonness_list.add(subword_commonness[(sep[-<NUM_LIT:1>], len(password))])<EOL>get_min_commonness_value(commonness_list)<EOL><DEDENT>print('<STR_LIT>', time()-start)<EOL>return commonness_value<EOL>
|
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.0
>>> Complexity().rareness2('poison') # the last word in Google's list
0.19998
>>> Complexity().rareness2('asdfegu')
1
>>> Complexity().rareness2('helloworld')
0.02537
>>> Complexity().rareness2('verylongpassword')
0.006806666666666667
>>> Complexity().rareness2('averylongpassword')
0.26282000000000005
>>> Complexity().rareness2('djkhsdjkashdaslkdhas')
0.31674
|
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><DEDENT><DEDENT>try:<EOL><INDENT>return consec / (len(password) - consecutive_length)<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>
|
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
>>> Complexity.consecutiveness('PaSsWoRd')
0.0
>>> Complexity.consecutiveness('yio')
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 values for various layout options,
and can be overwritten in any display method. A value of None means
use the system default, which may be set by a configuration file or
fall back to the compile-time default. See the Rofi documentation for
full details on what the values mean.
lines: positive integer
The maximum number of lines to show before scrolling.
fixed_lines: positive integer
Keep a fixed number of lines visible.
width: real
If positive but not more than 100, this is the percentage of the
screen's width the window takes up. If greater than 100, it is the
width in pixels. If negative, it estimates the width required for
the corresponding number of characters, i.e., -30 would set the
width so ~30 characters per row would show.
fullscreen: boolean
If True, use the full height and width of the screen.
location: integer
The position of the window on the screen.
rofi_args: list
A list of other arguments to pass in to every call to rofi. These get appended
after any other arguments
|
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>count = <NUM_LIT:0><EOL>while count < <NUM_LIT:100>:<EOL><INDENT>if self._process.poll() is not None:<EOL><INDENT>break<EOL><DEDENT>time.sleep(<NUM_LIT>)<EOL><DEDENT>if self._process.poll() is None:<EOL><INDENT>self._process.send_signal(signal.SIGKILL)<EOL><DEDENT><DEDENT>self._process = None<EOL><DEDENT>
|
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 not None:<EOL><INDENT>kwargs['<STR_LIT>'] = subprocess.PIPE<EOL><DEDENT>with Popen(args, **kwargs) as proc:<EOL><INDENT>stdout, stderr = proc.communicate(input)<EOL>returncode = proc.poll()<EOL>return returncode, stdout<EOL><DEDENT>
|
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.
Returns
-------
(returncode, stdout)
The exit code (integer) and stdout value (string) from 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.
Fullscreen mode is not supported for status messages and if specified
will be ignored.
Parameters
----------
message: string
Progress message to show.
|
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>display_bindings = []<EOL>user_keys = set()<EOL>for k, v in kwargs.items():<EOL><INDENT>if not k.startswith('<STR_LIT:key>'):<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>keynum = int(k[<NUM_LIT:3>:])<EOL><DEDENT>except ValueError:<EOL><INDENT>continue<EOL><DEDENT>key, action = v<EOL>user_keys.add(keynum)<EOL>args.extend(['<STR_LIT>'.format(k[<NUM_LIT:3>:]), key])<EOL>if action:<EOL><INDENT>display_bindings.append("<STR_LIT>".format(key, action))<EOL><DEDENT><DEDENT>exit_keys = set()<EOL>next_key = <NUM_LIT:10><EOL>for key in self.exit_hotkeys:<EOL><INDENT>while next_key in user_keys:<EOL><INDENT>next_key += <NUM_LIT:1><EOL><DEDENT>exit_keys.add(next_key)<EOL>args.extend(['<STR_LIT>'.format(next_key), key])<EOL>next_key += <NUM_LIT:1><EOL><DEDENT>message = message or "<STR_LIT>"<EOL>if display_bindings:<EOL><INDENT>message += "<STR_LIT:\n>" + "<STR_LIT:U+0020>".join(display_bindings)<EOL><DEDENT>message = message.strip()<EOL>if message:<EOL><INDENT>args.extend(['<STR_LIT>', message])<EOL><DEDENT>args.extend(self._common_args(**kwargs))<EOL>args.extend(rofi_args)<EOL>returncode, stdout = self._run_blocking(args, input=optionstr)<EOL>stdout = stdout.strip()<EOL>index = int(stdout) if stdout else -<NUM_LIT:1><EOL>if returncode == <NUM_LIT:0>:<EOL><INDENT>key = <NUM_LIT:0><EOL><DEDENT>elif returncode == <NUM_LIT:1>:<EOL><INDENT>key = -<NUM_LIT:1><EOL><DEDENT>elif returncode > <NUM_LIT:9>:<EOL><INDENT>key = returncode - <NUM_LIT:9><EOL>if key in exit_keys:<EOL><INDENT>raise SystemExit()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.exit_with_error("<STR_LIT>".format(results.returncode))<EOL><DEDENT>return index, key<EOL>
|
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. Any newline characters are
replaced with spaces.
message: string, optional
Message to show between the prompt and the options. This can
contain Pango markup, and any text content should be escaped.
select: integer, optional
Set which option is initially selected.
keyN: tuple (string, string); optional
Custom key bindings where N is one or greater. The first entry in
the tuple should be a string defining the key, e.g., "Alt+x" or
"Delete". Note that letter keys should be lowercase ie.e., Alt+a
not Alt+A.
The second entry should be a short string stating the action the
key will take. This is displayed to the user at the top of the
dialog. If None or an empty string, it is not displayed (but the
binding is still set).
By default, key1 through key9 are set to ("Alt+1", None) through
("Alt+9", None) respectively.
Returns
-------
tuple (index, key)
The index of the option the user selected, or -1 if they cancelled
the dialog.
Key indicates which key was pressed, with 0 being 'OK' (generally
Enter), -1 being 'Cancel' (generally escape), and N being custom
key N.
|
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><INDENT>args.extend(['<STR_LIT>', msg])<EOL><DEDENT>args.extend(self._common_args(**kwargs))<EOL>args.extend(rofi_args)<EOL>returncode, stdout = self._run_blocking(args, input="<STR_LIT>")<EOL>if returncode == <NUM_LIT:1>:<EOL><INDENT>return None<EOL><DEDENT>text = stdout.rstrip('<STR_LIT:\n>')<EOL>if validator:<EOL><INDENT>value, error = validator(text)<EOL>if not error:<EOL><INDENT>return value<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return text<EOL><DEDENT><DEDENT>
|
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
return a tuple (value, error). The value should be the users entry
converted to the appropriate Python type, or None if the entry was
invalid. The error message should be a string telling the user what
was wrong, or None if the entry was valid. The prompt will be
re-displayed to the user (along with the error message) until they
enter a valid value. If no validator is given, the text that the
user entered is returned as-is.
message: string
Optional message to display under the entry.
Returns
-------
The value returned by the validator, or None if the dialog was
cancelled.
Examples
--------
Enforce a minimum entry length:
>>> r = Rofi()
>>> validator = lambda s: (s, None) if len(s) > 6 else (None, "Too short")
>>> r.generic_entry('Enter a 7-character or longer string: ', validator)
|
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: Boolean
Whether to strip leading and trailing whitespace from the entered
value.
Returns
-------
string, or None if the dialog was cancelled.
|
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 (value < min):<EOL><INDENT>return None, "<STR_LIT>".format(min)<EOL><DEDENT>if (max is not None) and (value > max):<EOL><INDENT>return None, "<STR_LIT>".format(max)<EOL><DEDENT>return value, None<EOL><DEDENT>return self.generic_entry(prompt, integer_validator, message, rofi_args, **kwargs)<EOL>
|
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 None, no limit is imposed.
Returns
-------
integer, or None if the dialog is cancelled.
|
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 (value < min):<EOL><INDENT>return None, "<STR_LIT>".format(min)<EOL><DEDENT>if (max is not None) and (value > max):<EOL><INDENT>return None, "<STR_LIT>".format(max)<EOL><DEDENT>return value, None<EOL><DEDENT>return self.generic_entry(prompt, float_validator, message, rofi_args, **kwargs)<EOL>
|
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 allow. If None, no limit is imposed.
Returns
-------
float, or None if the dialog is cancelled.
|
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 None) and (value < min):<EOL><INDENT>return None, "<STR_LIT>".format(min)<EOL><DEDENT>if (max is not None) and (value > max):<EOL><INDENT>return None, "<STR_LIT>".format(max)<EOL><DEDENT>return value, None<EOL><DEDENT>return self.generic_entry(prompt, decimal_validator, message, rofi_args, **kwargs)<EOL>
|
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. If None, no limit is imposed.
Returns
-------
Decimal, or None if the dialog is cancelled.
|
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><INDENT>message = message or "<STR_LIT>"<EOL>message += "<STR_LIT>" + datetime.now().strftime(formats[<NUM_LIT:0>])<EOL><DEDENT>return self.generic_entry(prompt, date_validator, message, rofi_args, **kwargs)<EOL>
|
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 dates in. These should be
format strings as accepted by the datetime.datetime.strptime()
function from the standard library. They are tried in order, and
the first that returns a date object without error is selected.
Note that the '%x' in the default list is the current locale's date
representation.
show_example: Boolean
If True, today's date in the first format given is appended to the
message.
Returns
-------
datetime.date, or None if the dialog is cancelled.
|
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><INDENT>message = message or "<STR_LIT>"<EOL>message += "<STR_LIT>" + datetime.now().strftime(formats[<NUM_LIT:0>])<EOL><DEDENT>return self.generic_entry(prompt, time_validator, message, rofi_args=None, **kwargs)<EOL>
|
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 times in. These should be
format strings as accepted by the datetime.datetime.strptime()
function from the standard library. They are tried in order, and
the first that returns a time object without error is selected.
Note that the '%X' in the default list is the current locale's time
representation.
show_example: Boolean
If True, the current time in the first format given is appended to
the message.
Returns
-------
datetime.time, or None if the dialog is cancelled.
|
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>message = message or "<STR_LIT>"<EOL>message += "<STR_LIT>" + datetime.now().strftime(formats[<NUM_LIT:0>])<EOL><DEDENT>return self.generic_entry(prompt, datetime_validator, message, rofi_args, **kwargs)<EOL>
|
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 enter the date and time in. These
should be format strings as accepted by the
datetime.datetime.strptime() function from the standard library.
They are tried in order, and the first that returns a datetime
object without error is selected. Note that the '%x %X' in the
default list is the current locale's date and time representation.
show_example: Boolean
If True, the current date and time in the first format given is appended to
the message.
Returns
-------
datetime.datetime, or None if the dialog is cancelled.
|
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 * tx + ty * ty + tz * tz) ** <NUM_LIT:0.5><EOL>result.append((tx / d, ty / d, tz / d))<EOL><DEDENT>return result<EOL>
|
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
vertex buffer. The shader attributes can be assigned a slice of the
vertex buffer.
|
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, e1)<EOL>v = dot(d, q) * inv<EOL>if v < <NUM_LIT:0> or v > <NUM_LIT:1>:<EOL><INDENT>return None<EOL><DEDENT>t = dot(e2, q) * inv<EOL>if t > eps:<EOL><INDENT>return t<EOL><DEDENT>return None<EOL>
|
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 candidates:<EOL><INDENT>continue<EOL><DEDENT>basename = os.path.basename(filename)<EOL>if basename.startswith('<STR_LIT>'+library_name):<EOL><INDENT>basename_end = basename[len('<STR_LIT>'+library_name):]<EOL><DEDENT>elif basename.startswith(library_name):<EOL><INDENT>basename_end = basename[len(library_name):]<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>for file_extension in library_file_extensions:<EOL><INDENT>if basename_end.startswith(file_extension):<EOL><INDENT>if basename_end[len(file_extension):][:<NUM_LIT:1>] in ('<STR_LIT>', '<STR_LIT:.>'):<EOL><INDENT>candidates.add(filename)<EOL><DEDENT><DEDENT>if basename_end.endswith(file_extension):<EOL><INDENT>basename_middle = basename_end[:-len(file_extension)]<EOL>if all(c in '<STR_LIT>' for c in basename_middle):<EOL><INDENT>candidates.add(filename)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return candidates<EOL>
|
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>library_versions.append((version, filename))<EOL><DEDENT><DEDENT>if not library_versions:<EOL><INDENT>return None<EOL><DEDENT>library_versions.sort()<EOL>return ctypes.CDLL(library_versions[-<NUM_LIT:1>][<NUM_LIT:1>])<EOL>
|
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.strip()<EOL>if out:<EOL><INDENT>return eval(out)<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
|
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, minor_value.value, rev_value.value<EOL>
|
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_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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_callback[<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWwindowposfun(cbfun)<EOL>_window_pos_callback_repository[window_addr] = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetWindowPosCallback(window, cbfun)<EOL>if previous_callback is not None and previous_callback[<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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:<EOL><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWwindowsizefun(cbfun)<EOL>_window_size_callback_repository[window_addr] = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetWindowSizeCallback(window, cbfun)<EOL>if previous_callback is not None and previous_callback[<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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:<EOL><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWwindowclosefun(cbfun)<EOL>_window_close_callback_repository[window_addr] = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetWindowCloseCallback(window, cbfun)<EOL>if previous_callback is not None and previous_callback[<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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 None:<EOL><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWwindowrefreshfun(cbfun)<EOL>_window_refresh_callback_repository[window_addr] = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetWindowRefreshCallback(window, cbfun)<EOL>if previous_callback is not None and previous_callback[<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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:<EOL><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWwindowfocusfun(cbfun)<EOL>_window_focus_callback_repository[window_addr] = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetWindowFocusCallback(window, cbfun)<EOL>if previous_callback is not None and previous_callback[<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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 None:<EOL><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWwindowiconifyfun(cbfun)<EOL>_window_iconify_callback_repository[window_addr] = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetWindowIconifyCallback(window, cbfun)<EOL>if previous_callback is not None and previous_callback[<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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 is None:<EOL><INDENT>cbfun = <NUM_LIT:0><EOL><DEDENT>c_cbfun = _GLFWframebuffersizefun(cbfun)<EOL>_framebuffer_size_callback_repository[window_addr] = (cbfun, c_cbfun)<EOL>cbfun = c_cbfun<EOL>_glfw.glfwSetFramebufferSizeCallback(window, cbfun)<EOL>if previous_callback is not None and previous_callback[<NUM_LIT:0>] != <NUM_LIT:0>:<EOL><INDENT>return previous_callback[<NUM_LIT:0>]<EOL><DEDENT>
|
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, int value);
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.