Skip to content

Commit

Permalink
Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
imayhaveborkedit committed Aug 6, 2017
1 parent ce00c05 commit c32a149
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
v2
## UnReal World Stat Roller

A rewrite of my original stat roller [here](https://gist.github.com/imayhaveborkedit/d50eb0e1bdc47039d7db) (it's very old and bad and python 2).
3 changes: 1 addition & 2 deletions memhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def _open_proc(pid):
ctypes.windll.kernel32.CloseHandle(handle)



class Hook:
def __init__(self, load=True):
self.pid = None
Expand Down Expand Up @@ -258,7 +257,7 @@ def focus_game(self):
def focus_this(self):
win32gui.SetForegroundWindow(self._own_hwnd)

# TODO: proper context manager for this
# TODO: Test extensively
@contextmanager
def focus(self, thing):
orig_window = self.hwnd if thing == self.THIS else self._own_hwnd
Expand Down
28 changes: 15 additions & 13 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.document import Document
from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.filters import Condition, Always
from prompt_toolkit.filters import Condition
from prompt_toolkit.interface import CommandLineInterface
from prompt_toolkit.key_binding.registry import Registry
from prompt_toolkit.key_binding.bindings.named_commands import get_by_name
from prompt_toolkit.keys import Keys
from prompt_toolkit.layout.containers import VSplit, HSplit, Window
from prompt_toolkit.layout.controls import BufferControl, FillControl, TokenListControl
from prompt_toolkit.layout.controls import BufferControl, FillControl
from prompt_toolkit.layout.dimension import LayoutDimension as D
from prompt_toolkit.layout.margins import ScrollbarMargin, ConditionalMargin
from prompt_toolkit.shortcuts import create_eventloop
Expand All @@ -35,7 +35,7 @@
stat_args = {
'dont_extend_width': True,
'dont_extend_height': True,
'always_hide_cursor': False,
'always_hide_cursor': True,
'wrap_lines': True,
'height': D.exact(1),
'width': D.exact(38),
Expand Down Expand Up @@ -177,7 +177,6 @@ def _increment_repeated_msg(self, first=False):
return lambda line: line.rstrip(' ') + ' (2x)'
else:
incr = lambda match: f" ({str(int(match.group('num')) + 1)}x)"
# return lambda line: re.sub(r'[ ]\((?P<num>\d+)x\)$', incr, line)
return lambda line: self.repeated_message_pattern.sub(incr, line)

def _print(self, *args, sep=' ', pre='\n', **kwargs):
Expand All @@ -204,7 +203,7 @@ def print(self, *args, **kwargs):


def prompt(self, message, end='>'):
pass
...


def _update_info_text(self, buff=None):
Expand Down Expand Up @@ -275,6 +274,11 @@ def _gen_buffers(self):
}


# TODO: Lexers
# from pygments.lexers import HtmlLexer
# from prompt_toolkit.layout.lexers import PygmentsLexer
# BufferControl(lexer=PygmentsLexer(HtmlLexer))

def _gen_layout(self):
stat_windows = []

Expand Down Expand Up @@ -416,7 +420,8 @@ def _f(cli):

@registry.add_binding(Keys.Enter, filter=_f)
def _(event):
...
buf = event.cli.current_buffer
self.set_info_text(f"Enter on buffer {buf} at {buf.cursor_position}")

return registry

Expand Down Expand Up @@ -522,10 +527,7 @@ def append_info_text(self, text, sep='\n'):
if __name__ == '__main__':
Ui().run()


# a) Probably you want to add syntax highlighting to one of these buffers. This
# is possible by passing a lexer to the BufferControl. E.g.:

# from pygments.lexers import HtmlLexer
# from prompt_toolkit.layout.lexers import PygmentsLexer
# BufferControl(lexer=PygmentsLexer(HtmlLexer))
# TODO:
# Undo button (stat history)
# Cheat mode
# Race info and stat bounds helpers/warnings

0 comments on commit c32a149

Please sign in to comment.