Example #1
0
    def run(self, stdscr):
        """
        This method is called by the curses.wrapper to start the mainloop and
        screen.

        :param stdscr: curses screen passed in from curses.wrapper

        """
        # We want to do an interactive session, so start up the curses screen and
        # pass it the function that handles commands
        colors.init_colors()
        self.screen = screen.Screen(stdscr, self.do_command, self.tab_completer, self.encoding)
        self.statusbars = StatusBars()
        self.eventlog = EventLog()

        self.screen.topbar = "{!status!}Deluge " + deluge.common.get_version() + " Console"
        self.screen.bottombar = "{!status!}"
        self.screen.refresh()

        # The Screen object is designed to run as a twisted reader so that it
        # can use twisted's select poll for non-blocking user input.
        reactor.addReader(self.screen)

        # Start the twisted mainloop
        reactor.run()
Example #2
0
    def run(self, stdscr):
        """
        This method is called by the curses.wrapper to start the mainloop and
        screen.

        :param stdscr: curses screen passed in from curses.wrapper

        """
        # We want to do an interactive session, so start up the curses screen and
        # pass it the function that handles commands
        colors.init_colors()
        self.screen = screen.Screen(stdscr, self.do_command, self.tab_completer, self.encoding)
        self.statusbars = StatusBars()
        self.eventlog = EventLog()

        self.screen.topbar = "{!status!}Deluge " + deluge.common.get_version() + " Console"
        self.screen.bottombar = "{!status!}"
        self.screen.refresh()

        # The Screen object is designed to run as a twisted reader so that it
        # can use twisted's select poll for non-blocking user input.
        reactor.addReader(self.screen)

        # Start the twisted mainloop
        reactor.run()
Example #3
0
def init_layout_theme(color=init_colors()):
    return {
        "border_width": 2,
        "margin": 16,
        "border_focus": color[8],
        "border_normal": color[15]
    }
Example #4
0
def main(stdscr):
    # locale.setlocale(locale.LC_ALL, '')
    curses.nonl()

    # constants related to rooms
    room_max_size = 15
    room_min_size = 5
    max_rooms = 15

    # constants related to padding size
    # either height/width has to be larger than their counterparts of map
    # becuase writing on the bottom right corner of the padding causes an error
    height = 151
    width = 150
    # constants related to map size
    map_height = 150
    map_width = 150
    # get size of the screen for positioning
    # FIXME: as of now, we are going to assume that stdscr size doesn't change
    # stdscr is automatically init by wrapper()
    base_height, base_width = stdscr.getmaxyx()
    # constants related to view size
    # TODO: change view size in relation to screen size
    view_width = 100
    view_height = 24

    # default setups
    init_colors()
    curses.curs_set(0)  # hide cursor
    # win has to be a pad, so that scrolling is easily supported
    win = curses.newpad(height, width)
    win.keypad(True)
    win.bkgd(' ')
    # msgwin
    msg_win = curses.newpad(10, 100)
    msgbox = MsgBox(msg_win, view_width, view_height, base_width, base_height)

    # bars
    bar_width = 33
    bar_height = 1
    bar_win = curses.newwin(bar_height, bar_width, 1, 1)
    # bar_win.border()

    combat_module = Combat(hp=30, defense=2, power=5)
    inventory = Inventory(26)
    player = Player(combat_module, inventory)
    entities = [player]
    game_map = maps.GameMap(map_width, map_height)
    maps.generate_map(game_map, max_rooms, room_min_size, room_max_size,
                      player, entities)

    game_state = GameStates.PLAYERS_TURN
    previous_game_state = game_state
    # initial compute of fov
    game_map.compute_fov(player)
    inventory_menu = Menu(win, "INVENTORY", 30, base_width, base_height)
    while True:
        rendering.render_all(win, entities, game_map, view_width, view_height,
                             player, base_width, base_height, msgbox, bar_win,
                             inventory_menu, game_state)
        action = input_handler.handle_input(win, game_state)

        mv = action.get('move')
        pickup = action.get('pickup')
        show_inventory = action.get('show_inventory')
        hide_inventory = action.get('hide_inventory')
        item_at_cursor = action.get('item_at_cursor')
        inventory_index = action.get('inventory_index')
        move_cursor = action.get('move_cursor')
        move_page = action.get('move_page')
        exit = action.get('exit')

        inventory_shown = False

        player_turn_results = []

        if mv:
            dx, dy = mv
            dest_x = player.x + dx
            dest_y = player.y + dy

            if game_map.walkable[dest_x, dest_y]:
                target = blocking_entity_at_position(entities, dest_x, dest_y)
                if target:
                    atk_results = player.combat.attack(target)
                    player_turn_results.extend(atk_results)
                else:
                    move_results = {'move': mv}
                    player_turn_results.append(move_results)
        elif pickup:
            for e in entities:
                if e.item and e.x == player.x and e.y == player.y:
                    pickup_results = player.inventory.add_item(e)
                    player_turn_results.extend(pickup_results)
                    # only acquire one item at one turn
                    break
            else:
                msgbox.add("no_item")
        # Toggle Inventory screen
        elif show_inventory:
            msgbox.add("open inven")
            previous_game_state = game_state
            game_state = GameStates.SHOW_INVENTORY
            # FIXME: cursor, page should have a value limit
            # and it probably should be handled by menus, not here
        elif exit:
            # quit game
            # break
            pass
        if GameStates.SHOW_INVENTORY:
            if move_cursor:
                inventory_menu.next_item(move_cursor)
            elif move_page:
                inventory_menu.next_page(move_page)
            elif hide_inventory:
                game_state = previous_game_state
            elif item_at_cursor:
                item = inventory_menu.item_at_cursor()
                if item:  # TEMP FIX: check validity of choice at menu?
                    use_results = player.inventory.use_item(item)
                    player_turn_results.extend(use_results)
            elif inventory_index is not None:
                # unlike other inputs, inventory_index can be 0,
                # so compare it with "None"
                # check will cause input 0 to be ignored
                item = inventory_menu.item_at(inventory_index)
                if item:
                    use_results = player.inventory.use_item(item)
                    player_turn_results.extend(use_results)

        # evaluate results of player turn
        for result in player_turn_results:
            movement = result.get('move')
            dead_entity = result.get('dead')
            item_added = result.get('item_added')
            msg = result.get('msg')
            item_used = result.get('item_used')
            if movement:
                dx, dy = movement
                player.move(dx, dy)
                game_map.compute_fov(player)
            if item_added:
                entities.remove(item_added)
            if msg:
                msgbox.add(msg)
            if dead_entity == player:
                game_state = GameStates.PLAYER_DEAD
            if item_used:
                inventory_shown = True

            # toggle state only when something is done in PLAYERS_TURN
            game_state = GameStates.ENEMY_TURN

        if game_state == GameStates.ENEMY_TURN:
            # move those with ai modules
            enemies = (e for e in entities if e.ai)
            for e in enemies:

                e_turn_results = e.ai.take_turn(player, game_map, entities)

                # still a bit WET!
                for result in e_turn_results:
                    msg = result.get('msg')
                    dead_entity = result.get('dead')
                    if msg:
                        msgbox.add(msg)
                    if dead_entity == player:
                        game_state = GameStates.PLAYER_DEAD

        # check whether to return to beginning of loop
        if game_state == GameStates.PLAYER_DEAD:
            break
        elif game_state == GameStates.SHOW_INVENTORY:
            pass
        #if item was used at screen, keep the inventory opened
        elif inventory_shown:
            game_state = GameStates.SHOW_INVENTORY
        else:
            game_state = GameStates.PLAYERS_TURN
Example #5
0
def init_bar(color=init_colors()):
    return bar.Bar(
        [
            widget.TextBox(text="",
                           font="fontello",
                           foreground=color[14],
                           fontsize=23,
                           padding=5,
                           mouse_callbacks={'Button1': jgmenu_qtile}),
            widget.GroupBox(active=color[12],
                            inactive=color[14],
                            this_current_screen_border=color[10],
                            highlight_method="line",
                            font="fontello",
                            highlight_color=[color[15]],
                            center_aligned=True,
                            disable_drag=True,
                            fontsize=14),
            widget.Spacer(580),
            widget.TextBox(
                text='',
                font="icomoon",
            ),
            widget.Clock(
                format='%Y-%m-%d',
                foreground=color[14],
                fontsize=11,
                font='Cantarell Bold',
            ),
            widget.TextBox(
                text=' ',
                font="icomoon",
            ),
            widget.Clock(
                format='%H:%M',
                foreground=color[14],
                fontsize=11,
                font='Cantarell Bold',
            ),
            widget.Spacer(bar.STRETCH),
            widget.TextBox(
                text="",
                font="icomoon",
            ),
            widget.CheckUpdates(display_format='{updates}',
                                font='Cantarell Bold',
                                execute='pamac-manager',
                                distro='Arch',
                                update_interval=1),
            widget.TextBox(text="|", ),
            widget.CheckUpdates(
                display_format='{updates}',
                font='Cantarell Bold',
                distro='Arch',
                custom_command='yay -Qum 2>/dev/null',
                update_interval=1,
                execute='pamac-manager',
            ),
            widget.Spacer(10),
            widget.Net(),
            widget.Spacer(10),
            widget.TextBox(
                #text=' ',
                text='MEM:', ),
            widget.MemoryGraph(),
            widget.Spacer(10),
            widget.TextBox(
                #text=" ",
                text='CPU:', ),
            widget.CPUGraph(),
            widget.Spacer(10),
            widget.CurrentLayoutIcon(scale=0.5, ),
        ],
        26,
        background=color[15],
        font='Cantarell Bold',
        fontsize=11)
Example #6
0
import colors

def get_param(prompt_string):
	screen.clear()
	screen.border(0)
	screen.addstr(2, 2, prompt_string)
	screen.refresh()
	input = screen.getstr(10, 10, 60)
	return input

#Here we store variables for remembering things! Yay! 
x = 0
global trackpadOff
trackpadOff =0
hibernate = 0
colors.init_colors()
screen = curses.initscr()
while x != ord('q'):
	screen = curses.initscr()
	screen.clear()
	screen.border(0)
	screen.addstr(2, 2, "Welcome to syscurse... Press q to Exit", curses.color_pair(5))
	screen.addstr(4, 4, ", - to decrease Volume", curses.color_pair(2))
	screen.addstr(5, 4, ". - to increase Volume", curses.color_pair(3))
	screen.addstr(6, 4, "    Current volume level: NaN")
	screen.addstr(7, 4, "d - Show disk space")
	if(trackpadOff):
		screen.addstr(8, 4, "t - Toggle trackpad. Current state: " + keyfunc.str_trackpad(trackpadOff), curses.color_pair(3))
	else:
		screen.addstr(8, 4, "t - Toggle trackpad. Current state: " + keyfunc.str_trackpad(trackpadOff), curses.color_pair(2))
	screen.addstr(4, 40, "f - Open Firefox", curses.color_pair(1))
Example #7
0
def init_floating_layout(color=init_colors()):
    return layout.Floating(border_focus=color[8])
Example #8
0
# import from libs
import subprocess
from libqtile import widget
from Xlib import display as xdisplay

# import from files
from colors import init_colors

# variables
colors = init_colors()
scriptfolder: str = "/home/flo/.config/qtile/barscripts/"

# define themes
widget_theme = {
    "font": "Sans",
    "fontsize": 10,
    "foreground": colors[1],
    "background": colors[0],
    "padding": 4,
}

sep_theme = {"background": colors[1], "foreground": colors[1], "padding": 0}


def get_num_monitors():
    num_monitors = 0
    try:
        display = xdisplay.Display()
        screen = display.screen()
        resources = screen.root.xrandr_get_screen_resources()
Example #9
0
 def initCurses(self):
     self.stdscr = curses.initscr()
     curses.noecho()
     curses.cbreak()
     self.stdscr.keypad(1)
     colors.init_colors()