コード例 #1
0
import sharedlibs
sharedlibs.add_path_for('dice')
from dice import Dice

from score_category import ScoreCategory as SC


class Scorecard(object):
    def __init__(self):
        self.reset()

    ## properties

    @property
    def ones(self):
        return self._score[SC.ONES]

    @property
    def twos(self):
        return self._score[SC.TWOS]

    @property
    def threes(self):
        return self._score[SC.THREES]

    @property
    def fours(self):
        return self._score[SC.FOURS]

    @property
    def fives(self):
コード例 #2
0
import ui

import sharedlibs

sharedlibs.add_path_for('die_view')
from die_view import DieView


class YahtzeeDiceView(ui.View):
    def __init__(self, *args, **kwargs):
        super().__init__(self, *args, **kwargs)
        self.flex = 'WB'
        self._dvs = [DieView() for _ in range(5)]
        for dv in self._dvs:
            dv.onholdchange = self._handle_hold
            self.add_subview(dv)
        self._num_finished = 0
        self._enabled = True
        self.onholdchange = lambda i, v: None
        self.onrollfinished = lambda: None

    def layout(self):
        padding = 8
        x, y, w, h = self.frame
        box_size = (w - 4 * padding) / 5
        for i, dv in enumerate(self._dvs):
            new_x = i * (box_size + padding)
            dv.frame = (new_x, 0, box_size, box_size)
        self.frame = (x, y, w, box_size)

    @property
コード例 #3
0
import sharedlibs
sharedlibs.add_path_for('word_utils')
from word_tree import WordTree
from word_loader import load_wwf_words


class Dictionary(object):
    def __init__(self):
        self._word_tree = WordTree
コード例 #4
0
import ui
from number_slider import NumberSlider
from color_pallet import ColorPallet
from recent_colors import RecentColors
import sharedlibs

sharedlibs.add_path_for('brightness', 'view_swap')
from brightness import Brightness
from view_swap import ViewSwap


class ColorPicker(ui.View):

    EDGE_PADDING = 6
    COMPONENT_PADDING = 8

    def __init__(self):
        self.recent_colors = RecentColors()
        self.result = None

    def did_load(self):
        self.background_color = (0.5, 0.5, 0.5, 0.5)
        self.window = self['window']

        self.close_btn = self.window['close_btn']
        self.close_btn.action = self.close_popup

        self.select_btn = self.window['select_btn']
        self.select_btn.action = self.select_and_close

        self.demo_lbl = self.window['demo_lbl']
コード例 #5
0
import sharedlibs
sharedlibs.add_path_for('perm_utils')
from permuter import Permuter


class StringPermuter(object):
    def __init__(self, str, *args, **kwargs):
        self._permuter = Permuter(list(str), *args, **kwargs)

    def permute(self, *args, **kwargs):
        for perm in self._permuter.permute(*args, **kwargs):
            yield ''.join(perm)


if __name__ == '__main__':
    sp = StringPermuter('aaba')
    for p in sp.permute():
        print(p)
コード例 #6
0
import ui
import sharedlibs
sharedlibs.add_path_for('view_swap')
from view_swap import ViewSwap
sharedlibs.add_path_for('list_selector')
from list_selector import ListSelector


class ConfirmView(ui.View):
    def did_load(self):
        self.ls = None
        self.proceed = False
        self.yes_btn = self['yes_btn']
        self.yes_btn.action = self.yes_action
        self.no_btn = self['no_btn']
        self.no_btn.action = self.no_action
        self.zip = self['zip']
        self.zip.enabled = False
        self.sw = self['sw']

    def init(self, pathstr, file):
        vs = ViewSwap(self)
        paths = pathstr.split('|')
        self.ls = ListSelector(paths, placeholder='Select a path...')
        vs.swap('dummy_ls', self.ls)
        self.ls.value = None if len(paths) == 0 else paths[0]
        self.zip.text = file

    @staticmethod
    def load_view(pathstr, file):
        v = ui.load_view()
コード例 #7
0
from keyboard_panel import KeyboardPanel

import ui
import sharedlibs
sharedlibs.add_path_for('view_swap')
from view_swap import ViewSwap


class KeyboardView(ui.View):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        alpha_keys = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']
        alpha_alts = ['QWERTYUIOP', 'ASDFGHJKL', 'ZXCVBNM']
        special_keys = ['1234567890', '-/:;()$&@"', '.,?!\'']
        special_alts = ['[]{}#%^*+=', '_\\|~<>€£¥•', '.,?!\'']

        self.panels = [
            KeyboardPanel(alpha_keys, alpha_alts),
            KeyboardPanel(special_keys, special_alts)
        ]

        self.vs = ViewSwap(self)
        lb = ui.Label()
        lb.name = 'lb1'
        lb.text = 'Keyboard'
        lb.alignment = ui.ALIGN_CENTER
        lb.bg_color = '#c0ffb3'
        lb.flex = 'WH'
        lb.frame = self.frame
        self.add_subview(lb)
コード例 #8
0
import sys
import appex
import os
import shutil
from zipfile import ZipFile
from confirm_view import ConfirmView

import sharedlibs
sharedlibs.add_path_for('config_file')
from config_file import ConfigFile

config_path = 'app.config'


def first_run(config):
    config.set('FIRST_RUN', 'True')
    path = os.getcwd()
    tag = '/Pythonista3/Documents/'
    parts = path.split(tag)
    root = parts[0] + tag
    local = tag.join(parts[1:]) + os.sep + 'out'
    config.set('ROOT', root)
    config.set('DEST', local)
    config.save()


def main():
    if not appex.is_running_extension():
        print(
            'Running in Pythonista app. Use via sharing extension with a .zip file instead.'
        )