当前位置: 首页>>代码示例>>Python>>正文


Python Engine.play方法代码示例

本文整理汇总了Python中engine.Engine.play方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.play方法的具体用法?Python Engine.play怎么用?Python Engine.play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在engine.Engine的用法示例。


在下文中一共展示了Engine.play方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GesDemo

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import play [as 别名]
class GesDemo():
    '''User Interface class'''
    def __init__(self):
        '''Initialize the User Interface and the GES Engine'''

        self.engine = Engine()

        self.clips = {}

        # we import the gtk objects from glade and create our GtkStore and TreeView
        self.builder = Gtk.Builder()
        self.builder.add_from_file(os.path.join(os.path.curdir, \
            "py-ges-demo.glade"))
        self.builder.connect_signals(self)

        self.timeline_treeview = self.builder.get_object("timeline_treeview")
                                            #id, uri, start, duration, in point
        self.timeline_store = Gtk.ListStore(int, str, long, long, long)
        self.timeline_treeview.set_model(self.timeline_store)
        self.timeline_current_iter = None        #To keep track of the cursor

        self.start_entry = self.builder.get_object("start_entry")
        self.duration_scale = self.builder.get_object("duration_scale")
        self.in_point_scale = self.builder.get_object("in_point_scale")

        self.window = self.builder.get_object("window")
        self.window.show_all()

    def _clip_selected(self, widget):
        '''Method connected to the selection-changed signal of the TreeView'''
        model, row_iter = self.timeline_treeview.get_selection().get_selected()
        if row_iter is None:
            self.engine.prioritize(None)
        else:
            idf = self.timeline_store.get_value(row_iter, 0)
            self.engine.prioritize(self.clips[idf][5])
            print "active clip: ", self.clips[idf]

            self._update_properties_box(idf)

    def _update_properties_box(self, idf):
        '''Method to update the properties box with the information of the selected clip'''
        clip = self.clips[idf]
        self.start_entry.set_text(str(clip[1]))
        self.duration_scale.set_range(0, clip[4] - clip[3])
        self.duration_scale.set_value(clip[2])
        self.in_point_scale.set_range(0, clip[4])
        self.in_point_scale.set_value(clip[3])

    def _play_activate_cb(self, widget):
        '''Method connected to the Play button'''
        self.engine.play()

    def _stop_activate_cb(self, widget):
        '''Method connected to the Stop button'''
        self.engine.stop()

    def _add_file_activated_cb(self, widget):
        '''Method connected to the Add File button'''
        filechooser = Gtk.FileChooserDialog(action=Gtk.FileChooserAction.OPEN,
                      buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                    Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        response = filechooser.run()
        if response != Gtk.ResponseType.OK:
            filechooser.destroy()
            return

        filepath = filechooser.get_filename()
        if filepath and os.access(filepath, os.R_OK):
            filechooser.destroy()
            self.add_file(filepath)

    def add_file(self, filepath):
        '''Method that adds the file to the GtkStore and GESTimeline'''
        idf = len(self.clips)    # id field is a counter

        uri = Gst.filename_to_uri (filepath)   # conver the filepath into a valid URI
        duration, tlobj = self.engine.add_file(uri)    # add the uri to the GESTimeline

        # add to the GtkStore and internal list
        self.timeline_store.append([idf, os.path.basename(filepath), 0,
                                   duration, 0])
        # clips[id] = uri, start, duration, in_point, max_duration, timelineobj
        self.clips[idf] = [uri, 0, duration, 0, duration, tlobj]

    def _delete_activate_cb(self, widget):
        '''Method connected to the Delete button'''
        print "delete"

    def _start_changed(self, widget):
        '''Method connected to the Changed event of the start entry'''
        new_start = widget.get_text()
        print "new start entered", new_start

        # find the selected clip
        model, row_iter = self.timeline_treeview.get_selection().get_selected()
        idf = self.timeline_store.get_value(row_iter, 0)
        self.clips[idf][1] = new_start
        # set the new value to the Gtk TreeStore
        try:
#.........这里部分代码省略.........
开发者ID:luisbg,项目名称:py-ges-demo,代码行数:103,代码来源:py-ges-demo.py

示例2: Map

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import play [as 别名]
from myMap import Map
from engine import Engine

gameMap = Map("outside")
game = Engine(gameMap)
game.play()
开发者ID:jamtot,项目名称:LearnPythonTheHardWay,代码行数:8,代码来源:game.py

示例3: Wolfgang

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import play [as 别名]
class Wolfgang():

    def __init__(self):
        self.engine = Engine()
        self.lucien = Lucien()

        self.uri = None
        self.is_playing = False
        self._sliderGrabbed = False
        self.loop = False
        self.library = {}

        self.builder = Gtk.Builder()
        self.builder.add_from_file(path.join(path.curdir, "wolfgang.ui"))
        self.builder.connect_signals(self)

        # Sup dawg, I heard you like black,
        # so I put a dark UI in your car so you can drive through the night.
        gtksettings = Gtk.Settings.get_default()
        gtksettings.set_property("gtk-application-prefer-dark-theme", True)
        self.main_toolbar = self.builder.get_object("main_toolbar")
        self.main_toolbar.get_style_context().add_class("primary-toolbar")
        self.main_toolbar.set_sensitive(False)

        self.previous_button = self.builder.get_object("previous_button")
        self.play_button = self.builder.get_object("play_button")
        self.next_button = self.builder.get_object("next_button")
        self.time_slider = self.builder.get_object("time_slider")
        self.next_button.set_sensitive(False)
        self.previous_button.set_sensitive(False)

        self._prepare_treeviews()

        self.window = self.builder.get_object("window1")
        self.window.set_icon_name("rhythmbox")
        self.window.maximize()
        self.window.connect("delete-event", self.quit)
        self.window.show_all()

        self.engine.connect("about_to_finish", self._onAboutToFinish)
        self.engine.connect("error", self._onError)
        self.lucien.connect("discovered", self._new_media)

        # Slight hack to get the user's "Music" XDG directory:
        with open(path.expanduser("~/.config/user-dirs.dirs"), "r") as foo:
            lines = foo.readlines()
            for line in lines:
                if "XDG_MUSIC_DIR" in line:
                    home = path.expanduser("~")
                    music_folder = line.split('"')[1].replace("$HOME", home)
                    break
            foo.close()

        self.lucien.collect(music_folder)

        GObject.timeout_add(500, self._updateSliderPosition)

    """
    UI initialization crack
    """
    def _prepare_treeviews(self):
        self.library_treeview = self.builder.get_object("library_treeview")
        self.playlist_treeview = self.builder.get_object("playlist_treeview")
        self.queue_treeview = self.builder.get_object("queue_treeview")
        # If we enable this, we'll get in trouble in the removeFromQueue method:
        # self.queue_treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)

        self.library_store = Gtk.TreeStore(str) # Only 1 "column" to contain all
        self.playlist_store = Gtk.ListStore(str, str, int)  # title, URI, track number
        self.queue_store = Gtk.ListStore(str, str, str)  # cursor, title, URI
        self.queue_current_iter = None  # To keep track of where the cursor was

        self.library_treeview.set_model(self.library_store)
        self.playlist_treeview.set_model(self.playlist_store)
        self.queue_treeview.set_model(self.queue_store)

        # Library: only one column, with two visible levels (artist, album)
        column = Gtk.TreeViewColumn()
        column_contents = Gtk.CellRendererText()
        column.pack_start(column_contents, True)
        column.add_attribute(column_contents, "text", 0)
        self.library_treeview.append_column(column)

        # Playlist: two columns in the store (title, URI), but only one shown
        column = Gtk.TreeViewColumn("Title")
        title = Gtk.CellRendererText()
        column.pack_start(title, True)
        column.add_attribute(title, "text", 0)
        self.playlist_treeview.append_column(column)

        # Queue: 3 columns in store, 1 shown for cursor, 1 for the track title
        column = Gtk.TreeViewColumn("Cursor")
        cursor = Gtk.CellRendererText()
        column.pack_start(cursor, True)
        column.add_attribute(cursor, "text", 0)
        self.queue_treeview.append_column(column)
        column = Gtk.TreeViewColumn("Title")
        title = Gtk.CellRendererText()
        column.pack_start(title, True)
        column.add_attribute(title, "text", 1)
#.........这里部分代码省略.........
开发者ID:luisbg,项目名称:wolfgang,代码行数:103,代码来源:wolfgang.py

示例4: Map

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import play [as 别名]
from map import Map
from engine import Engine

a_map = Map('central_corridor')
a_game = Engine(a_map)
a_game.play()
开发者ID:DylanGraham,项目名称:adventure,代码行数:8,代码来源:adventure.py

示例5: TestRoom

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import play [as 别名]
from testroom import TestRoom
from engine import Engine

startroom = TestRoom('a prison cell', 'door to the west')
first = TestRoom('the guard room', 'door to the north and to the east')
second = TestRoom('an ante Room', 'door to the east and to the south')
third = TestRoom('a small chamber', 'door to the south-east and to the west')
fourth = TestRoom('a big hall', 'door to the south-west and to the north-west')
fifth = TestRoom('a cellar', 'door to the south-east and to the north-east')
sixth = TestRoom('a long corridor', 'door to the north-east and to the north-west')
seventh = TestRoom('a bedroom', 'door to the north-east and to the south-west')
eighth = TestRoom('a bathroom', 'window to the north-east and to the south-west')

startroom.add_paths({'west': first})
first.add_paths({'east': startroom, 'north': second})
second.add_paths({'south': first, 'east': third})
third.add_paths({'west': second, 'south-east': fourth})
fourth.add_paths({'north-west': third, 'south-west': fifth})
fifth.add_paths({'north-east': fourth, 'south-east': sixth})
sixth.add_paths({'north-west': fifth, 'north-east': seventh})
seventh.add_paths({'south-west': sixth, 'north-east': eighth})
eighth.add_paths({'south-west': seventh})

game_engine = Engine('TestPlayer', startroom) 
print 'Welcome to Dungeon Escape %s' % game_engine.player
game_engine.play()
开发者ID:Dasmu,项目名称:dungeon_escape,代码行数:28,代码来源:map.py

示例6: main

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import play [as 别名]
def main(input_filename=None):
    if input_filename:
        engine = Engine(input_filename)
        sections = engine.get_sections()
        print("track includes sections 1..%d" % len(sections))
    else:
        engine = None

    client = soundcloud.Client(access_token = "1-58194-65838022-e30bc60d1afac57")
    
    while True:
        cmd = raw_input("arranger > ")
        if len(cmd) == 0:
            continue

        if cmd[0].lower() == "p":
            if engine:
                engine.play([int(x) - 1 for x in cmd.split()[1:]])
            else:
                print "load a track with 'l <filename>'"
            
        elif cmd[0].lower() == "a":
            if engine:
                engine.arrange([int(x) - 1 for x in cmd.split()[1:]])
            else:
                print "load a track with 'l <filename>'"
            
        elif cmd[0].lower() == "s":
            if engine:
                name = cmd[2:]
                if len(name) < 1:
                    print "empty name"
                    continue

                engine.save(name)
                if not '.' in name:
                    name = name + '.mp3'

                yesNo = raw_input("Upload track to SoundCloud? (y/n) > ")
                if yesNo.lower().startswith("y"):
                    title = raw_input("Name your sound > ")
                    genre = raw_input("What genre is your sound? > ")
                    tags = raw_input("Add comma-separated tags > ")
                    track_dict = {'title': title, 'asset_data': open(name, 'rb'), 'genre': genre, 'tag_list': tags}
                    track_dict.update({'sharing': 'public'})
                    track = client.post('/tracks', track = track_dict)
                    while track.state != "finished":
                        time.sleep(1)
                        track = client.get("/tracks/" + str(track.id))

                    webbrowser.open(track.permalink_url)
                else:
                    continue
            else:
                print "load a track with 'l <filename>'"

        elif cmd[0].lower() == "l":
            if engine:
                engine.kill()
            new_filename = cmd[1:].strip()
            engine = Engine(new_filename)
            print("track includes sections 1..%d" % len(engine.get_sections()))

        elif cmd[0].lower() == "h":
            print HELP
            
        elif cmd[0].lower() == "k":
            if engine:
                engine.kill()

        elif cmd[0].lower() == "q":
            if engine:
                engine.kill()
            break
开发者ID:ddesroches,项目名称:arranger,代码行数:76,代码来源:arranger.py

示例7: Room

# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import play [as 别名]
from engine import Engine
from room import Room

north = Room("North Room", """This room is to the north of the center room.
You can also reach the East and West rooms from here.""", ['kid\'s water floaties'])
south = Room("South Room", """This room is to the south of the center room.
You can also reach the East and West rooms from here.""")
center = Room("Center Room", """This room is surrounded by 4 rooms. 
To the North, South, East and West.""", ['sword', 'chocolate bar', 'helmet'])
east = Room("East Room", """This room is to the east of the center room. 
You can also reach the North and South rooms from here.""")
west = Room("""West Room", "This room is to the west of the center room.
You can also reach the North and South rooms from here.""", ['walkman', 'fanny pack'])

north.add_paths({'down': center, 'center': center, 'east': east, 'west': west})
south.add_paths({'up': center, 'center': center, 'east': east, 'west': west})
center.add_paths({'north': north, 'south': south, 'east': east, 'west': west})
east.add_paths({'center': center, 'north': north, 'south': south})
west.add_paths({'center': center, 'north': north, 'south': south})

test_engine = Engine()
test_engine.play(center)
开发者ID:jamtot,项目名称:LearnPythonTheHardWay,代码行数:24,代码来源:game.py


注:本文中的engine.Engine.play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。