Ejemplo n.º 1
0
 def catch_finish(self, img, fail=True, width=0, height=0):
     with patch('simplequi._url._on_finished') as finish:
         finish.side_effect = partial(self.on_finished, fail=fail)
         simplequi.create_timer(500, QApplication.instance().exit).start()
         QApplication.instance().exec_()
     finish.assert_called_with(img._Image__load_image, ANY)
     self.assertTrue(self.passed, 'failed when expected to succeed or vice versa')
     self.assertEqual(img.get_width(), width)
     self.assertEqual(img.get_height(), height)
     if not fail:
         self.assertEqual(self.error, QNetworkReply.NoError)
Ejemplo n.º 2
0
 def test_handler(self):
     timer = simplequi.create_timer(8, self.handler)
     stop_timer = simplequi.create_timer(40, timer.stop)
     exit_timer = simplequi.create_timer(50, self.app.exit)
     timer.start()
     stop_timer.start()
     exit_timer.start()
     self.app.exec_()
     self.assertFalse(timer.is_running())
     if not disable_call_counts():
         self.assertAlmostEqual(self.handler.call_count, 5, delta=1)  # Allow delta due to timer inaccuracies
     self.handler.assert_has_calls([call() for _ in range(self.handler.call_count)])
Ejemplo n.º 3
0
 def test_timer(self):
     timer = simplequi.create_timer(100, self.handler)
     self.assertFalse(timer.is_running())
     self.assertNotIn(timer, self.app.tracked)
     timer.start()
     self.assertTrue(timer.is_running())
     self.assertIn(timer, self.app.tracked)
     timer.stop()
     self.assertFalse(timer.is_running())
     self.assertNotIn(timer, self.app.tracked)
Ejemplo n.º 4
0

def callback():
    global count, volume
    count -= 1

    fraction = count / 100.
    log_volume = total_log * fraction
    drum_volume = 2**log_volume / 100.
    sound_volume = drum_volume * 0.2

    drums.set_volume(drum_volume)
    sound.set_volume(sound_volume)

    if count == 0:
        drum_timer.stop()
        sound_timer.stop()
        volume_timer.stop()
    else:
        drums.play()
        sound.play()


drum_timer = simplegui.create_timer(8000, drums.play)
sound_timer = simplegui.create_timer(4000, sound.play)
volume_timer = simplegui.create_timer(240, callback)

drum_timer.start()
sound_timer.start()
volume_timer.start()
Ejemplo n.º 5
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# simplequi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with simplequi.  If not, see <https://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
"""Count to 10"""

import simplequi as simplegui

count = 0


def callback():
    global count
    count += 1
    print(count)
    if count == 10:
        print('Fin.')
        timer.stop()


timer = simplegui.create_timer(1000, callback)
timer.start()