Пример #1
0
    def __init__(self):
        super(StreamSetupWidget, self).__init__()

        self.username_line = LineEdit()
        self.username_line.setPlaceholderText('Username')
        self.username_line.setReadOnly(True)

        self.stream_title_line = LineEdit()
        self.stream_title_line.setPlaceholderText('Stream title')

        self.subreddit_combo = ComboBox()
        subreddits = config['subreddits']
        self.subreddit_combo.setMaxVisibleItems(len(subreddits))
        for subreddit in subreddits:
            self.subreddit_combo.addItem(f'r/{subreddit}')

        self.start_stream_button = Button('Set up the stream')
        self.start_stream_button.clicked.connect(self.start_stream)

        self.disable_all_widgets()

        self.layout = QGridLayout()
        self.layout.setSpacing(6)
        self.layout.addWidget(self.username_line, 1, 0, 1, 2)
        self.layout.addWidget(self.stream_title_line, 2, 0, 1, 2)
        self.layout.addWidget(self.subreddit_combo, 3, 0, 1, 2)
        self.layout.addWidget(self.start_stream_button, 4, 0, 1, 2)
        self.layout.addWidget(QWidget(), 5, 0, 1, 2)
        self.setLayout(self.layout)
Пример #2
0
class UrlSelectColumnFrame(ttk.Frame):
    def __init__(self, master=None, id=None, url='', response_gt=None, max_page=None, is_using=True, **kw):
        super().__init__(master, **kw)
        self.database_id = id
        self.check_button = CheckButton(self, value=is_using, help_text='是否启用')
        self.url_text = UrlEntry(self, width=50, value=url, help_text='url!!!!')
        self.response_num_text = NumberEntry(self, width=5, value=response_gt, help_text='最小相应数')
        self.max_page_text = NumberEntry(self, width=5, value=max_page, help_text='最大搜索页数')
        self.delete_button = Button(self, text='Delete', command=self.delete, help_text='删除')

        self.check_button.grid(column=0, row=0)
        self.url_text.grid(column=1, row=0)
        self.response_num_text.grid(column=2, row=0)
        self.max_page_text.grid(column=3, row=0)
        self.delete_button.grid(column=4, row=0)

        for w in self.children.values():
            w.bind('<Enter>', self.show_help_text)

    def get_as_dict(self):
        ret = {
            'url': self.url_text.get(),
            'response_gt': self.response_num_text.get(),
            'max_page': self.max_page_text.get(),
            'is_using': self.check_button.get(),
            'id': self.database_id,
        }
        return ret

    def info_is_using(self):
        """
        :return: If Checkbutton is pressed
        """
        return True if self.check_button.get() else False

    def delete(self):
        Tasks.delete_by_id(self.database_id)
        self.destroy()

    def show_help_text(self, event):
        help_text = event.widget.help_text
        self.master.set_info(help_text)
Пример #3
0
    def __init__(self):
        super(AuthWidget, self).__init__()

        self.auth_button = Button('Authorize')
        self.auth_button.clicked.connect(self.authorize)

        self.help_button = Button('Help')
        self.help_button.clicked.connect(self.help)

        self.layout = QGridLayout()
        self.layout.addWidget(QWidget())
        self.layout.addWidget(self.auth_button, 1, 0, Qt.AlignHCenter)
        self.layout.addWidget(self.help_button, 2, 0, Qt.AlignHCenter)
        self.layout.addWidget(QWidget())
        self.layout.addWidget(QWidget())
        self.setLayout(self.layout)

        self.timer = QTimer()
        self.timer.setInterval(1000)
        self.timer.timeout.connect(self.check_for_token)
Пример #4
0
    def __init__(self):
        super(StreamReadyWidget, self).__init__()

        self.key_line = LineEdit()
        self.key_line.setPlaceholderText('Streamer key')
        self.key_line.setReadOnly(True)
        self.copy_key_button = Button('Copy stream key')
        self.copy_key_button.clicked.connect(self.copy_key)

        self.rtmp_line = LineEdit()
        self.rtmp_line.setPlaceholderText('RTMP URL')
        self.rtmp_line.setReadOnly(True)
        self.copy_rtmp_button = Button('Copy server URL')
        self.copy_rtmp_button.clicked.connect(self.copy_rtmp)

        self.copy_stream_url_button = Button('Copy stream URL')
        self.copy_stream_url_button.clicked.connect(self.copy_stream_url)
        self.open_stream_url_button = Button('Open stream URL')
        self.open_stream_url_button.clicked.connect(self.open_stream_url)

        self.chat_widget = QWidget()

        self.open_chat_button = Button('Open chat')
        self.open_chat_button.clicked.connect(self.open_chat_window)

        self.layout = QGridLayout()
        self.layout.addWidget(QWidget())
        self.layout.addWidget(self.key_line, 1, 0, 1, 5)
        self.layout.addWidget(self.rtmp_line, 2, 0, 1, 5)
        self.layout.addWidget(self.copy_key_button, 1, 5, 1, 1)
        self.layout.addWidget(self.copy_rtmp_button, 2, 5, 1, 1)
        self.layout.addWidget(self.copy_stream_url_button, 3, 5, 1, 1)
        self.layout.addWidget(self.open_stream_url_button, 3, 0, 1, 5)
        self.layout.addWidget(self.open_chat_button, 4, 0, 1, 6)
        self.layout.addWidget(QWidget())
        self.setLayout(self.layout)
Пример #5
0
    def __init__(self, master=None, id=None, url='', response_gt=None, max_page=None, is_using=True, **kw):
        super().__init__(master, **kw)
        self.database_id = id
        self.check_button = CheckButton(self, value=is_using, help_text='是否启用')
        self.url_text = UrlEntry(self, width=50, value=url, help_text='url!!!!')
        self.response_num_text = NumberEntry(self, width=5, value=response_gt, help_text='最小相应数')
        self.max_page_text = NumberEntry(self, width=5, value=max_page, help_text='最大搜索页数')
        self.delete_button = Button(self, text='Delete', command=self.delete, help_text='删除')

        self.check_button.grid(column=0, row=0)
        self.url_text.grid(column=1, row=0)
        self.response_num_text.grid(column=2, row=0)
        self.max_page_text.grid(column=3, row=0)
        self.delete_button.grid(column=4, row=0)

        for w in self.children.values():
            w.bind('<Enter>', self.show_help_text)
Пример #6
0
    def __init__(self, parent, title="Einstellungen: Doppelpendel",
                position=None, constraints=(285, 200), pendulum=None):
        super(SettingsWindow, self).__init__(parent, title,
                                             position, constraints)

        # Referenz auf Pendel speichern
        self._pendulum = pendulum

        # Simulation gestoppt?
        self.stopped = False

        # Winkel
        self.add_widget(Label(self, text=u"Φ₁ [°]:", position=(10, 10),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.phi1slider = Slider(self, position=(85, 10),
                                 constraints=(190, 15),
                                 initial_value=90, span=(0, 360))
        self.add_widget(self.phi1slider)
        self.add_widget(Label(self, text=u"Φ₂ [°]:", position=(10, 35),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.phi2slider = Slider(self, position=(85, 35),
                                 constraints=(190, 15),
                                 initial_value=180, span=(0, 360))
        self.add_widget(self.phi2slider)

        # Längen
        self.add_widget(Label(self, text=u"l₁ [m]:", position=(10, 60),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.l1slider = Slider(self, position=(85, 60),
                               constraints=(190, 15),
                               initial_value = 4, span = (0.1, 10))
        self.add_widget(self.l1slider)
        self.add_widget(Label(self, text=u"l₂ [m]:", position=(10, 85),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.l2slider = Slider(self, position=(85, 85),
                               constraints=(190, 15),
                               initial_value=5, span=(0.1, 10))
        self.add_widget(self.l2slider)

        # Massen
        self.add_widget(Label(self, text=u"m₁ [kg]:", position=(10, 110),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.m1slider = Slider(self, position=(85, 110),
                               constraints=(190, 15),
                               initial_value=5, span=(0.1, 10))
        self.add_widget(self.m1slider)
        self.add_widget(Label(self, text=u"m₂ [kg]:", position=(10, 135),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.m2slider = Slider(self, position=(85, 135),
                               constraints=(190, 15),
                               initial_value=10, span=(0.1, 10))
        self.add_widget(self.m2slider)

        # Aktualisierungs-Aktion für die Slider
        self.phi1slider.set_value_handler(self.slider_update)
        self.phi2slider.set_value_handler(self.slider_update)
        self.l1slider.set_value_handler(self.slider_update)
        self.l2slider.set_value_handler(self.slider_update)
        self.m1slider.set_value_handler(self.slider_update)
        self.m2slider.set_value_handler(self.slider_update)

        # Buttons
        self.startbutton = Button(self, position=(10, 160),
                                  constraints=(50, 15))
        self.update_start_button()
        self.startbutton.set_handler(self.start_action)
        self.add_widget(self.startbutton)
        self.resetbutton = Button(self, text="Reset", position=(70, 160),
                                  constraints=(50, 15))
        self.resetbutton.set_handler(self.reset)
        self.add_widget(self.resetbutton)
Пример #7
0
class SettingsWindow(gui.window.Window):
    """Fenster zur Änderung der Versuchsparameter."""

    def __init__(self, parent, title="Einstellungen: Doppelpendel",
                position=None, constraints=(285, 200), pendulum=None):
        super(SettingsWindow, self).__init__(parent, title,
                                             position, constraints)

        # Referenz auf Pendel speichern
        self._pendulum = pendulum

        # Simulation gestoppt?
        self.stopped = False

        # Winkel
        self.add_widget(Label(self, text=u"Φ₁ [°]:", position=(10, 10),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.phi1slider = Slider(self, position=(85, 10),
                                 constraints=(190, 15),
                                 initial_value=90, span=(0, 360))
        self.add_widget(self.phi1slider)
        self.add_widget(Label(self, text=u"Φ₂ [°]:", position=(10, 35),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.phi2slider = Slider(self, position=(85, 35),
                                 constraints=(190, 15),
                                 initial_value=180, span=(0, 360))
        self.add_widget(self.phi2slider)

        # Längen
        self.add_widget(Label(self, text=u"l₁ [m]:", position=(10, 60),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.l1slider = Slider(self, position=(85, 60),
                               constraints=(190, 15),
                               initial_value = 4, span = (0.1, 10))
        self.add_widget(self.l1slider)
        self.add_widget(Label(self, text=u"l₂ [m]:", position=(10, 85),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.l2slider = Slider(self, position=(85, 85),
                               constraints=(190, 15),
                               initial_value=5, span=(0.1, 10))
        self.add_widget(self.l2slider)

        # Massen
        self.add_widget(Label(self, text=u"m₁ [kg]:", position=(10, 110),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.m1slider = Slider(self, position=(85, 110),
                               constraints=(190, 15),
                               initial_value=5, span=(0.1, 10))
        self.add_widget(self.m1slider)
        self.add_widget(Label(self, text=u"m₂ [kg]:", position=(10, 135),
                              constraints=(70, 15), align=font.Text.RIGHT))
        self.m2slider = Slider(self, position=(85, 135),
                               constraints=(190, 15),
                               initial_value=10, span=(0.1, 10))
        self.add_widget(self.m2slider)

        # Aktualisierungs-Aktion für die Slider
        self.phi1slider.set_value_handler(self.slider_update)
        self.phi2slider.set_value_handler(self.slider_update)
        self.l1slider.set_value_handler(self.slider_update)
        self.l2slider.set_value_handler(self.slider_update)
        self.m1slider.set_value_handler(self.slider_update)
        self.m2slider.set_value_handler(self.slider_update)

        # Buttons
        self.startbutton = Button(self, position=(10, 160),
                                  constraints=(50, 15))
        self.update_start_button()
        self.startbutton.set_handler(self.start_action)
        self.add_widget(self.startbutton)
        self.resetbutton = Button(self, text="Reset", position=(70, 160),
                                  constraints=(50, 15))
        self.resetbutton.set_handler(self.reset)
        self.add_widget(self.resetbutton)

    def update_start_button(self):
        if self.stopped:
            self.startbutton.text = "Start"
        else:
            self.startbutton.text = "Stop"

    def start_action(self):
        self.stopped = not self.stopped
        self.update_start_button()

    def reset(self):
        phi1 = self.phi1slider.value / 180.0 * pi
        phi2 = self.phi2slider.value / 180.0 * pi
        length1 = self.l1slider.value
        length2 = self.l2slider.value
        mass1 = self.m1slider.value
        mass2 = self.m2slider.value
        self._pendulum.reset(phi1, phi2, length1, length2, mass1, mass2)

    def slider_update(self):
        if self.stopped:
            self.reset()
Пример #8
0
class StreamSetupWidget(QWidget):

    stream_started = pyqtSignal()

    def __init__(self):
        super(StreamSetupWidget, self).__init__()

        self.username_line = LineEdit()
        self.username_line.setPlaceholderText('Username')
        self.username_line.setReadOnly(True)

        self.stream_title_line = LineEdit()
        self.stream_title_line.setPlaceholderText('Stream title')

        self.subreddit_combo = ComboBox()
        subreddits = config['subreddits']
        self.subreddit_combo.setMaxVisibleItems(len(subreddits))
        for subreddit in subreddits:
            self.subreddit_combo.addItem(f'r/{subreddit}')

        self.start_stream_button = Button('Set up the stream')
        self.start_stream_button.clicked.connect(self.start_stream)

        self.disable_all_widgets()

        self.layout = QGridLayout()
        self.layout.setSpacing(6)
        self.layout.addWidget(self.username_line, 1, 0, 1, 2)
        self.layout.addWidget(self.stream_title_line, 2, 0, 1, 2)
        self.layout.addWidget(self.subreddit_combo, 3, 0, 1, 2)
        self.layout.addWidget(self.start_stream_button, 4, 0, 1, 2)
        self.layout.addWidget(QWidget(), 5, 0, 1, 2)
        self.setLayout(self.layout)

    def initialize(self):
        self.username_line.setText(f'u/{reddit.get_username()}')
        self.enable_all_widgets()

    def start_stream(self):
        self.disable_all_widgets()

        title = self.stream_title_line.text()
        if len(title) == 0:
            QMessageBox().information(self, 'Insufficient title length',
                                      'Your title must be longer.')
            self.enable_all_widgets()
            return

        _, subreddit = self.subreddit_combo.currentText().split('/')

        response = reddit.post_broadcast(title, subreddit)
        status_code = response.status_code
        if status_code != 200:
            if status_code == 503:
                error_str = f"{subreddit} is not available right now.\n" \
                            f"Please, try a different subreddit."
            else:
                error_str = f"Couldn't start a stream, status code: {status_code}"
            QMessageBox().information(self, 'Stream setup unsuccessful',
                                      error_str)
            self.enable_all_widgets()
            return

        self.stream_started.emit()

    def disable_all_widgets(self):
        self.username_line.setDisabled(True)
        self.stream_title_line.setDisabled(True)
        self.subreddit_combo.setDisabled(True)
        self.start_stream_button.setDisabled(True)

    def enable_all_widgets(self):
        self.username_line.setEnabled(True)
        self.stream_title_line.setEnabled(True)
        self.subreddit_combo.setEnabled(True)
        self.start_stream_button.setEnabled(True)
Пример #9
0

from gui.gui import GUI
from gui.widgets import Button


gui = GUI()
test_button = Button(gui, (100, 100))
test_button.on_left_click = gui.quit