在python中构建一个带有轨道和时间轴的前端

时间:2021-06-25 06:51:25

I'm looking for a solution to create a front-end in python for an app. I've some experience with Tk (but it's not fundamental i would like to use wxpython) and standard widget, but now i'm in a project too complicated for me. The app is like a multimedia presentation builder or scheduler, where the elements i can use are pictures, videos, sounds, and other as command to execute something and where i decide when to start to view each element. I've not found any standard widget to use, so i've made a mockup of the interface that is similar to the multitrack audio or video editor,

我正在寻找一个解决方案,在一个应用程序的python中创建一个前端。我有一些使用Tk的经验(但这不是我想使用wxpython的基础)和标准小部件,但现在我的项目对我来说太复杂了。该应用程序就像一个多媒体演示构建器或调度程序,我可以使用的元素是图片,视频,声音,以及其他作为命令执行的东西,我决定何时开始查看每个元素。我没有找到任何标准小部件可供使用,所以我制作了类似于多轨音频或视频编辑器的接口模型,

the mock-up image is http://tinypic.com/r/4gqnap/5

模拟图像是http://tinypic.com/r/4gqnap/5

you can see in the picture my idea: there are some channels where i can put different objects like picture, videos, serial command, and foreach i can set the moment to start and the duration. When i press play the timeline cursor goes and when it reach a begin point of object in channel, the object "start " to view or execution video or something else. i can control the timeline scroll when i'm not in play, the channel scroll to add how many channels i need. The pictures and the videos will bew viewed on other dedicated frames: each channel a frame. Exist a similar front-ent from which i could get ideas? or instructions on how to build something like it?

你可以在图片中看到我的想法:有一些频道我可以放置不同的对象,如图片,视频,串行命令和foreach,我可以设置开始的时刻和持续时间。当我按下播放时,时间轴光标移动,当它到达通道中对象的开始点时,对象“开始”查看或执行视频或其他内容。当我不在游戏中时,我可以控制时间轴滚动,频道滚动以添加我需要的频道数量。将在其他专用帧上查看图片和视频:每个通道一帧。存在类似的前端,我可以从中得到想法?或说明如何建立类似的东西?

thank's to all.

谢谢大家。

Giorgio

1 个解决方案

#1


0  

This is a extreeemely vague question.. But here we go.. I'd skip most of the traditional modules (such as Tk or wxPython but they could work for you).

这是一个非常模糊的问题..但是我们走了......我会跳过大多数传统模块(例如Tk或wxPython,但它们可以为你工作)。

I usually present the Pyglet option to anyone interesting in GUI development or anything graphic wise..

我经常向任何有趣的GUI开发或任何图形明智的人展示Pyglet选项。

Here's a short drag-n-drop example:

这是一个简短的拖放示例:

#!/usr/bin/python
import pyglet
from time import time, sleep

class Window(pyglet.window.Window):
    def __init__(self, refreshrate):
        super(Window, self).__init__(vsync = False)
        self.frames = 0
        self.framerate = pyglet.text.Label(text='Unknown', font_name='Verdana', font_size=8, x=10, y=10, color=(255,255,255,255))
        self.last = time()
        self.alive = 1
        self.refreshrate = refreshrate
        self.click = None
        self.drag = False

    def on_draw(self):
        self.render()

    def on_mouse_press(self, x, y, button, modifiers):
        self.click = x,y

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if self.click:
            self.drag = True
            print 'Drag offset:',(dx,dy)

    def on_mouse_release(self, x, y, button, modifiers):
        if not self.drag and self.click:
            print 'You clicked here', self.click, 'Relese point:',(x,y)
        else:
            print 'You draged from', self.click, 'to:',(x,y)
        self.click = None
        self.drag = False

    def render(self):
        self.clear()
        if time() - self.last >= 1:
            self.framerate.text = str(self.frames)
            self.frames = 0
            self.last = time()
        else:
            self.frames += 1
        self.framerate.draw()
        self.flip()

    def on_close(self):
        self.alive = 0

    def run(self):
        while self.alive:
            self.render()
            # ----> Note: <----
            #  Without self.dispatc_events() the screen will freeze
            #  due to the fact that i don't call pyglet.app.run(),
            #  because i like to have the control when and what locks
            #  the application, since pyglet.app.run() is a locking call.
            event = self.dispatch_events()
            sleep(1.0/self.refreshrate)

win = Window(23) # set the fps
win.run()

Here you will have to create your own objects (textboxes, sliders.. etc) but you'll have full control over them.

在这里你必须创建自己的对象(文本框,滑块等),但你可以完全控制它们。

I've built a few (8-13) large-scale GUI applications and this is the cleanest way to go if you don't want to use brick looking buttons and generic colorschemes.

我已经构建了一些(8-13)大型GUI应用程序,如果你不想使用砖块按钮和通用颜色方案,这是最干净的方法。

Also, see this thread and many more on GUI discussions, what the best modules are etc:

另外,请参阅此线程以及更多关于GUI讨论,最佳模块等等:

And for Pyglet:

而对于Pyglet:

#1


0  

This is a extreeemely vague question.. But here we go.. I'd skip most of the traditional modules (such as Tk or wxPython but they could work for you).

这是一个非常模糊的问题..但是我们走了......我会跳过大多数传统模块(例如Tk或wxPython,但它们可以为你工作)。

I usually present the Pyglet option to anyone interesting in GUI development or anything graphic wise..

我经常向任何有趣的GUI开发或任何图形明智的人展示Pyglet选项。

Here's a short drag-n-drop example:

这是一个简短的拖放示例:

#!/usr/bin/python
import pyglet
from time import time, sleep

class Window(pyglet.window.Window):
    def __init__(self, refreshrate):
        super(Window, self).__init__(vsync = False)
        self.frames = 0
        self.framerate = pyglet.text.Label(text='Unknown', font_name='Verdana', font_size=8, x=10, y=10, color=(255,255,255,255))
        self.last = time()
        self.alive = 1
        self.refreshrate = refreshrate
        self.click = None
        self.drag = False

    def on_draw(self):
        self.render()

    def on_mouse_press(self, x, y, button, modifiers):
        self.click = x,y

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if self.click:
            self.drag = True
            print 'Drag offset:',(dx,dy)

    def on_mouse_release(self, x, y, button, modifiers):
        if not self.drag and self.click:
            print 'You clicked here', self.click, 'Relese point:',(x,y)
        else:
            print 'You draged from', self.click, 'to:',(x,y)
        self.click = None
        self.drag = False

    def render(self):
        self.clear()
        if time() - self.last >= 1:
            self.framerate.text = str(self.frames)
            self.frames = 0
            self.last = time()
        else:
            self.frames += 1
        self.framerate.draw()
        self.flip()

    def on_close(self):
        self.alive = 0

    def run(self):
        while self.alive:
            self.render()
            # ----> Note: <----
            #  Without self.dispatc_events() the screen will freeze
            #  due to the fact that i don't call pyglet.app.run(),
            #  because i like to have the control when and what locks
            #  the application, since pyglet.app.run() is a locking call.
            event = self.dispatch_events()
            sleep(1.0/self.refreshrate)

win = Window(23) # set the fps
win.run()

Here you will have to create your own objects (textboxes, sliders.. etc) but you'll have full control over them.

在这里你必须创建自己的对象(文本框,滑块等),但你可以完全控制它们。

I've built a few (8-13) large-scale GUI applications and this is the cleanest way to go if you don't want to use brick looking buttons and generic colorschemes.

我已经构建了一些(8-13)大型GUI应用程序,如果你不想使用砖块按钮和通用颜色方案,这是最干净的方法。

Also, see this thread and many more on GUI discussions, what the best modules are etc:

另外,请参阅此线程以及更多关于GUI讨论,最佳模块等等:

And for Pyglet:

而对于Pyglet: