示例#1
0
    async def handle_input(self, widget, **kwargs):
        # Display the input as a chat entry.
        input_text = self.text_input.value
        self.chat.data.append(
            # User's avatar is from http://avatars.adorable.io
            # using [email protected]
            icon=toga.Icon('resources/user.png'),
            title='You',
            subtitle=input_text,
        )
        # Clear the current input, ready for more input.
        self.text_input.value = ''
        # Scroll so the most recent entry is visible.
        self.chat.scroll_to_bottom()

        # The partner needs to think about their response...
        await asyncio.sleep(random.random() * 3)

        # ... and they respond
        response = self.partner.respond(input_text)
        # Display the response
        self.chat.data.append(
            icon=toga.Icon('resources/brutus.png'),
            title='Brutus',
            subtitle=response,
        )

        # Scroll so the most recent entry is visible.
        self.chat.scroll_to_bottom()
示例#2
0
    def setUp(self):
        self.factory = MagicMock()
        self.factory.Icon = MagicMock(return_value=MagicMock(
            spec=toga_dummy.factory.Icon))

        self.test_path = "Example.bmp"
        self.icon = toga.Icon(self.test_path)
        self.resource_icon = toga.Icon(self.test_path, system=True)
示例#3
0
    def _setup_commands(self):
        # Custom command groups
        self.control_tests_group = toga.Group('Test')
        self.instruments_group = toga.Group('Instruments')

        self.show_coverage_command = toga.Command(self.cmd_show_coverage,
                                                  'Show coverage...',
                                                  group=self.instruments_group)
        self.show_coverage_command.enabled = False if duvet is None else True

        # Button to stop run the tests
        self.stop_command = toga.Command(self.cmd_stop,
                                         'Stop',
                                         tooltip='Stop running the tests.',
                                         icon=toga.Icon('resources/stop.png'),
                                         shortcut='s',
                                         group=self.control_tests_group)
        self.stop_command.enabled = False

        # Button to run all the tests
        self.run_all_command = toga.Command(
            self.cmd_run_all,
            'Run all',
            tooltip='Run all the tests.',
            icon=toga.Icon('resources/play.png'),
            shortcut='r',
            group=self.control_tests_group)

        # Button to run only the tests selected by the user
        self.run_selected_command = toga.Command(
            self.cmd_run_selected,
            'Run selected',
            tooltip='Run the tests selected.',
            icon=toga.Icon('resources/run_select.png'),
            shortcut='e',
            group=self.control_tests_group)
        self.run_selected_command.enabled = False

        # Re-run all the tests
        self.rerun_command = toga.Command(
            self.cmd_rerun,
            'Re-run',
            tooltip='Re-run the tests.',
            icon=toga.Icon('resources/re_run.png'),
            shortcut='a',
            group=self.control_tests_group)
        self.rerun_command.enabled = False

        # Cricket's menu items
        self.commands.add(
            # Instrument items
            self.show_coverage_command, )

        self.main_window.toolbar.add(self.stop_command, self.run_all_command,
                                     self.run_selected_command,
                                     self.rerun_command)
示例#4
0
文件: app.py 项目: xmonader/toga
    def __init__(self, path, parent):
        super().__init__()
        self._parent = parent
        self._children = []

        self.path = path
        self._mtime = self.path.stat().st_mtime
        if self.path.is_file():
            self._icon = toga.Icon('resources/file')
        else:
            self._icon = toga.Icon('resources/folder')
        self._did_start_loading = False
示例#5
0
文件: app.py 项目: leewonmoh/macrepo1
    def handle_input(self, widget, **kwargs):
        input_text = self.text_input.value
        self.chat.data.append(icon=toga.Icon('resources/user.png'),
                              title='User',
                              subtitle=input_text)
        self.text_input.value = ''
        self.chat.scroll_to_bottom()

        yield random.random() * 2
        response = self.partner.respond(input_text)
        self.chat.data.append(icon=toga.Icon('resources/brutus.png'),
                              title='Bot',
                              subtitle=response)
示例#6
0
    def setUp(self):
        # We need a test app to for icon loading to work
        self.app = toga.App(
            formal_name="Test App",
            app_id="org.beeware.test-app",
            factory=toga_dummy.factory,
        )

        self.factory = MagicMock()
        self.factory.Icon = MagicMock(return_value=MagicMock(
            spec=toga_dummy.factory.Icon))

        self.test_path = "Example.bmp"
        self.icon = toga.Icon(self.test_path)
        self.system_icon = toga.Icon(self.test_path, system=True)
示例#7
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)
        self.main_window.app = self

        self.partner = Eliza()

        self.chat = toga.DetailedList(data=[{
            'icon':
            toga.Icon('resources/brutus.png'),
            'title':
            'Brutus',
            'subtitle':
            'Hello. How are you feeling today?',
        }],
                                      style=Pack(flex=1))

        # Buttons
        self.text_input = toga.TextInput(style=Pack(flex=1, padding=5))
        send_button = toga.Button('Send',
                                  on_press=self.handle_input,
                                  style=Pack(padding=5))
        input_box = toga.Box(children=[self.text_input, send_button],
                             style=Pack(direction=ROW))

        # Outermost box
        outer_box = toga.Box(children=[self.chat, input_box],
                             style=Pack(direction=COLUMN))

        # Add the content on the main window
        self.main_window.content = outer_box

        # Show the main window
        self.main_window.show()
示例#8
0
    def startup(self):

        self.chat = toga.DetailedList(data=[{
            'icon': toga.Icon(),
            'title': 'RisBot',
            'subtitle': 'Hello,Wassup?',
        }],
                                      style=Pack(flex=1))

        self.text_input = toga.TextInput(style=Pack(flex=1))
        send_button = toga.Button('Send',
                                  style=Pack(padding_left=5),
                                  on_press=self.handle_input)

        input_box = toga.Box(children=[self.text_input, send_button],
                             style=Pack(direction=ROW,
                                        alignment='CENTER',
                                        padding=5))

        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(title=self.name)

        # Create a main content box
        main_box = toga.Box()

        # Add the content on the main window
        self.main_window.content = toga.Box(children=[self.chat, input_box],
                                            style=Pack(direction=COLUMN))

        self.partner = eliza.Eliza()
        # Show the main window
        self.main_window.show()
示例#9
0
文件: app.py 项目: kgisl/podium
 def __init__(self):
     super().__init__(
         'Podium',
         app_id='org.pybee.podium',
         icon=toga.Icon(os.path.join(os.path.dirname(__file__), 'icons', 'podium.icns')),
         document_types=['podium']
     )
示例#10
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

        # Label to show responses.
        self.label = toga.Label('Ready.')

        widget = toga.DetailedList(
            data=[{
                'icon': toga.Icon('resources/brutus.png'),
                'title': translation['string'],
                'subtitle': translation['country'],
            } for translation in bee_translations],
            on_select=self.on_select_handler,
            # on_delete=self.on_delete_handler,
            on_refresh=self.on_refresh_handler,
            style=Pack(flex=1))

        # Outermost box
        outer_box = toga.Box(children=[widget, self.label],
                             style=Pack(
                                 flex=1,
                                 direction=COLUMN,
                                 padding=10,
                             ))

        # Add the content on the main window
        self.main_window.content = outer_box

        # Show the main window
        self.main_window.show()
示例#11
0
文件: app.py 项目: timb07/podium
 def __init__(self):
     resource_dir = os.path.dirname(
         os.path.dirname(os.path.dirname(__file__)))
     super().__init__('Podium',
                      app_id='org.beeware.podium',
                      icon=toga.Icon(
                          os.path.join(resource_dir, 'podium.icns')),
                      document_types={'podium': SlideDeck})
示例#12
0
文件: app.py 项目: willingc/hera
 def __init__(self):
     resource_dir = os.path.dirname(
         os.path.dirname(os.path.dirname(__file__)))
     super().__init__(
         'Hera',
         app_id='net.phildini.Hera',
         icon=toga.Icon(os.path.join(resource_dir, 'Hera.icns')),
         document_types={'ipynb': Notebook},
     )
示例#13
0
def launch_dativetop(services):
    icon = toga.Icon('resources/dativetop.icns')
    app = DativeTop(services,
                    formal_name=c.APP_FORMAL_NAME,
                    app_name=c.APP_NAME,
                    app_id=c.APP_ID,
                    on_exit=dativetop_on_exit,
                    icon=icon)
    app.main_loop()
    return app
示例#14
0
    def handle_input(self, widget, **kwargs):
        input_text = self.text_input.value

        self.chat.data.append(
            icon=toga.Icon('resources/user.png'),
            title='You',
            subtitle=input_text,
        )

        self.text_input.value = ''

        self.chat.scroll_to_bottom()
示例#15
0
class TestCase(TestNode):
    """A data representation of a test case, wrapping multiple test methods.
    """
    TEST_CASE_ICON = toga.Icon('resources/test_case.png')

    def __repr__(self):
        return '<TestCase %s>' % self.path

    @property
    def label(self):
        "The display label for the node"
        return (self.TEST_CASE_ICON, self.name)

    def set_active(self, is_active, cascade=True):
        """Explicitly set the active state of the test case.

        Forces all methods on this test case to set to the same
        active status.

        If cascade is True, the parent test module will be prompted
        to check it's current active status.
        """
        if self._active:
            if not is_active:
                self._active = False
                # self.emit('inactive')
                if cascade:
                    self.parent._update_active()
                for testMethod in self.values():
                    testMethod.set_active(False, cascade=False)
        else:
            if is_active:
                self._active = True
                # self.emit('active')
                if cascade:
                    self.parent._update_active()
                for testMethod in self.values():
                    testMethod.set_active(True, cascade=False)

    def toggle_active(self):
        "Toggle the current active status of this test case"
        self.set_active(not self.active)

    def _update_active(self):
        "Check the active status of all child nodes, and update the status of this node accordingly"
        for testMethod_name, testMethod in self.items():
            if testMethod.active:
                # As soon as we find an active child, this node
                # must be marked active, and no other checks are
                # required.
                self.set_active(True)
                return
        self.set_active(False)
示例#16
0
class TestModule(TestNode):
    """A data representation of a module. It may contain test cases, or other modules.
    """
    TEST_MODULE_ICON = toga.Icon('resources/test_module.png')

    def __repr__(self):
        return '<TestModule %s>' % self.path

    @property
    def label(self):
        "The display label for the node"
        return (self.TEST_MODULE_ICON, self.name)

    def set_active(self, is_active, cascade=True):
        """Explicitly set the active state of the test case.

        Forces all test cases and test modules held by this test module
        to be set to the same active status

        If cascade is True, the parent test module will be prompted
        to check it's current active status.
        """
        if self._active:
            if not is_active:
                self._active = False
                # self.emit('inactive')
                if cascade:
                    self.parent._update_active()
                for testModule in self.values():
                    testModule.set_active(False, cascade=False)
        else:
            if is_active:
                self._active = True
                # self.emit('active')
                if cascade:
                    self.parent._update_active()
                for testModule in self.values():
                    testModule.set_active(True, cascade=False)

    def toggle_active(self):
        "Toggle the current active status of this test case"
        self.set_active(not self.active)

    def _purge(self, timestamp):
        """Search all submodules and test cases looking for stale test methods.

        Purge any test module without any test cases, and any test Case with no
        test methods.
        """
        for testModule_name, testModule in self.items():
            testModule._purge(timestamp)
            if len(testModule) == 0:
                self.pop(testModule_name)
示例#17
0
def main(Model):
    """Run the main loop of the app.

    Take the test_suite Model as the argument. This model will be
    instantiated as part of the main loop.
    """
    parser = ArgumentParser()

    parser.add_argument("--version",
                        help="Display version number and exit",
                        action="store_true")

    Model.add_arguments(parser)
    options = parser.parse_args()

    # Check the shortcut options
    if options.version:
        import cricket
        print(cricket.__version__)
        return

    # Construct a Toga application
    app = Cricket('Cricket',
                  'org.pybee.cricket',
                  icon=toga.Icon('icons/cricket'))

    # Try to load the test_suite. If any error occurs during
    # test suite load, show an error dialog
    test_suite = None
    while test_suite is None:
        try:
            # Create the test_suite objects
            test_suite = Model(options)
            test_suite.refresh()
        except ModelLoadError as e:
            # Load failed; destroy the test_suite and show an error dialog.
            #   If the user selects cancel, quit.
            app.test_load_error = e.trace
        else:
            app.test_load_error = None

    if test_suite.errors:
        app.ignorable_test_load_error = '\n'.join(test_suite.errors)
    else:
        app.ignorable_test_load_error = None

    # Set the test_suite for the main window.
    # This populates the tree, and sets listeners for
    # future tree modifications.
    app.test_suite = test_suite

    return app
示例#18
0
    def handle_input(self, widget, **kwargs):
        input_text = self.text_input.value

        self.chat.scroll_to_bottom()

        yield random.random() * 3

        response = self.partner.respond(input_text)
        self.chat.data.append(
            icon=toga.Icon(),
            title='You',
            subtitle=input_text,
        )

        self.text_input.value = ''
示例#19
0
    def setUp(self):
        icon = toga.Icon(
            os.path.join(os.path.dirname(__file__),
                         '../../../../demo/toga_demo/resources/brutus-32.png'))
        self.dl = toga.DetailedList([
            dict(icon=icon,
                 title='Item %i' % i,
                 subtitle='this is the subtitle for item %i' % i)
            for i in range(10)
        ])

        # make a shortcut for easy use
        self.gtk_dl = self.dl._impl

        self.window = Gtk.Window()
        self.window.add(self.dl._impl.native)
示例#20
0
文件: app.py 项目: leewonmoh/macrepo1
    def startup(self):
        #alternative icon embedding
        #path=os.path.dirname(os.path.abspath(__file__))
        #brutus_icon=os.path.join(path,"icons","brutus.icns")
        #Eliza module
        self.partner=Eliza()

        self.chat=toga.DetailedList(
            data=[
                {
                    'icon':toga.Icon('icons/ubs-logo.png'),

                    'title': 'Bot',
                    'subtitle': 'Hello. How are you feeling today?'
                }
            ]
            ,style=Pack(flex=1))

        self.text_input=toga.TextInput(style=Pack(flex=1))
        
        send_button=toga.Button('Send',style=Pack(padding_left=5),on_press=self.handle_input)

        input_box=toga.Box(
            children=[self.text_input, send_button],
            style=Pack(direction=ROW, alignment=CENTER, padding=5)
        )
#alignment='CENTER',
        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(title=self.name)

        # Create a main content box
        #main_box = toga.Box()

        # Add the content on the main window
        self.main_window.content = toga.Box(
            children=[self.chat,input_box],
            style=Pack(direction=COLUMN)
        )

        # Show the main window
        self.main_window.show()
示例#21
0
    def startup(self):

        self.button_add = toga.Button(
            label='Add image',
            style=Pack(padding=10, width=120),
            on_press=self.add_image,
        )

        self.button_remove = toga.Button(
            label='Remove image',
            style=Pack(padding=10, width=120),
            on_press=self.remove_image,
            enabled=False,
        )

        self.button_insert = toga.Button(
            label='Insert image',
            style=Pack(padding=10, width=120),
            on_press=self.insert_image,
        )

        self.button_reparent = toga.Button(
            label='Reparent image',
            style=Pack(padding=10, width=120),
            on_press=self.reparent_image,
            enabled=False,
        )

        self.button_add_to_scroll = toga.Button(
            label='Add new label',
            style=Pack(padding=10, width=120),
            on_press=self.add_label,
        )

        self.scroll_box = toga.Box(children=[],
                                   style=Pack(direction=COLUMN,
                                              padding=10,
                                              flex=1))
        self.scroll_view = toga.ScrollContainer(content=self.scroll_box,
                                                style=Pack(width=120))

        icon = toga.Icon('')
        self.image_view = toga.ImageView(icon,
                                         style=Pack(padding=10,
                                                    width=60,
                                                    height=60))

        # this tests addind children during init, before we have an implementaiton
        self.button_box = toga.Box(
            children=[
                self.button_add,
                self.button_insert,
                self.button_reparent,
                self.button_remove,
                self.button_add_to_scroll,
            ],
            style=Pack(direction=COLUMN),
        )

        self.box = toga.Box(children=[self.button_box, self.scroll_view],
                            style=Pack(direction=ROW,
                                       padding=10,
                                       alignment=CENTER,
                                       flex=1))

        # add a couple of labels to get us started
        # this tests adding children when we already have an impl but no window or app
        for i in range(3):
            self.add_label()

        self.main_window = toga.MainWindow()
        self.main_window.content = self.box
        self.main_window.show()
示例#22
0
    def startup(self):
        # Window class
        #   Main window of the application with title and size
        self.main_window = toga.MainWindow(self.name, size=(640, 480))
        self.main_window.app = self

        list_data = []
        for i in range(0, 100):
            list_data.append(('root%s' % i, 'value%s' % i))

        left_container = toga.Table(['Hello', 'World'],
                                    data=list_data,
                                    on_select=tableSelected)

        right_content = toga.Box(
            style=CSS(flex_direction='column', padding_top=50))

        for b in range(0, 10):
            right_content.add(
                toga.Button('Hello world %s' % b,
                            on_press=button_handler,
                            style=CSS(width=200, margin=20)))

        right_container = toga.ScrollContainer(horizontal=False)

        right_container.content = right_content

        split = toga.SplitContainer()

        split.content = [left_container, right_container]

        things = toga.Group('Things')

        cmd0 = toga.Command(action1,
                            label='Action 0',
                            tooltip='Perform action 0',
                            icon=toga.Icon('icons/brutus.icns'),
                            group=things)
        cmd1 = toga.Command(action1,
                            label='Action 1',
                            tooltip='Perform action 1',
                            icon=toga.Icon('icons/brutus.icns'),
                            group=things)
        cmd2 = toga.Command(action2,
                            label='Action 2',
                            tooltip='Perform action 2',
                            icon=toga.Icon.TIBERIUS_ICON,
                            group=things)
        cmd3 = toga.Command(action3,
                            label='Action 3',
                            tooltip='Perform action 3',
                            shortcut='k',
                            icon=toga.Icon('icons/cricket-72.png'))

        def action4(widget):
            print("CALLING Action 4")
            cmd3.enabled = not cmd3.enabled

        cmd4 = toga.Command(
            action4,
            label='Action 4',
            tooltip='Perform action 4',
            icon=toga.Icon('icons/brutus.icns'),
        )

        self.commands.add(cmd1, cmd3, cmd4, cmd0)
        self.main_window.toolbar.add(cmd1, cmd2, cmd3, cmd4)

        # Add the content on the main window
        self.main_window.content = split

        # Show the main window
        self.main_window.show()
示例#23
0
    def setUp(self):
        self.factory = MagicMock()
        self.factory.Icon = MagicMock(return_value=MagicMock(
            spec=toga_dummy.factory.Icon))

        self.icon = toga.Icon(self.text, factory=self.factory)
示例#24
0
class TestMethod:
    """A data representation of an individual test method.
    """
    STATUS_UNKNOWN = None
    STATUS_PASS = 100
    STATUS_SKIP = 200
    STATUS_EXPECTED_FAIL = 300
    STATUS_UNEXPECTED_SUCCESS = 400
    STATUS_FAIL = 500
    STATUS_ERROR = 600

    FAILING_STATES = (STATUS_FAIL, STATUS_UNEXPECTED_SUCCESS, STATUS_ERROR)

    STATUS_ICONS = {
        STATUS_UNKNOWN:
        toga.Icon('resources/status/unknown.png'),
        STATUS_PASS:
        toga.Icon('resources/status/pass.png'),
        STATUS_SKIP:
        toga.Icon('resources/status/skip.png'),
        STATUS_EXPECTED_FAIL:
        toga.Icon('resources/status/expected_fail.png'),
        STATUS_UNEXPECTED_SUCCESS:
        toga.Icon('resources/status/unexpected_success.png'),
        STATUS_FAIL:
        toga.Icon('resources/status/fail.png'),
        STATUS_ERROR:
        toga.Icon('resources/status/error.png'),
    }

    def __init__(self, source, path, name):
        self._source = source

        self._path = path
        self._name = name
        self._active = True

        # Test status
        self._description = ''
        self._status = self.STATUS_UNKNOWN
        self._output = None
        self._error = None
        self._duration = None

    def __repr__(self):
        return '<TestMethod %s>' % self.path

    ######################################################################
    # Methods required by the TreeSource interface
    ######################################################################

    def can_have_children(self):
        return False

    ######################################################################
    # Methods used by Cricket
    ######################################################################

    @property
    def path(self):
        return self._path

    @property
    def name(self):
        return self._name

    @property
    def label(self):
        "The display label for the node"
        return (self.STATUS_ICONS[self.status], self.name)

    @property
    def description(self):
        return self._description

    @property
    def status(self):
        return self._status

    @property
    def output(self):
        return self._output

    @property
    def error(self):
        return self._error

    @property
    def duration(self):
        return self._duration

    @property
    def active(self):
        "Is this test method currently active?"
        return self._active

    def set_result(self, description, status, output, error, duration):
        self._description = description
        self._status = status
        self._output = output
        self._error = error
        self._duration = duration

        self._source._notify('change', item=self)

    def set_active(self, is_active, cascade=True):
        """Explicitly set the active state of the test method

        If cascade is True, the parent testCase will be prompted
        to check it's current active status.
        """
        if self._active:
            if not is_active:
                self._active = False
                if cascade:
                    self.parent._update_active()
        else:
            if is_active:
                self._active = True
                if cascade:
                    self.parent._update_active()

    def toggle_active(self):
        "Toggle the current active status of this test method"
        self.set_active(not self.active)

    def find_tests(self, active=True, status=None, labels=None):
        if labels:
            if self.path in labels:
                return 1, None
            else:
                return 0, []
        else:
            return 1, None