示例#1
0
    def build(self):
        tp = TabbedPanel()

        wid = Widget(size_hint=(0.9, 1))
        slider = Slider(min=0,
                        max=32,
                        value=0,
                        value_track=True,
                        orientation='vertical',
                        step=1.0,
                        value_track_color=[1, 0, 0, 1],
                        size_hint=(0.1, 1))
        self.label_pattern = "Axis {} : {}"
        self.edit_label_pattern = "Edit Color {}. Keep Axis {} : Layer Index {}. Slide : {}"
        self.color_preview_data = None
        self.fileroot = Root()
        self.axis = 0
        self.edit_axis = 1
        self.slider_value = 0
        self.layer_index = 0
        self.load_file = 0
        self.plot3d = Draw3DSurface()
        upper_layout = BoxLayout()
        upper_layout.add_widget(wid)
        upper_layout.add_widget(slider)

        self.label = Label(
            text=self.label_pattern.format(AxisList[self.axis], 0))

        btn_load_lut1 = Button(text='Load LUT 1',
                               on_press=partial(self.load_lut, wid, 1))

        btn_load_lut2 = Button(text='Load LUT 2',
                               on_press=partial(self.load_lut, wid, 2))

        btn_showlayer = Button(text='Show LUT Layer',
                               on_press=partial(self.show_lut_layer, wid))

        btn_showplot = Button(text='Show 3D Plot',
                              on_press=partial(self.show_3D_plot, wid))

        btn_double = Button(text='Change Axis',
                            on_press=partial(self.change_axis, wid))

        btn_save_lut = Button(text='Save LUT',
                              on_press=partial(self.save_lut, wid))

        layout = BoxLayout(size_hint=(1, None), height=50)
        layout.add_widget(btn_load_lut1)
        layout.add_widget(btn_load_lut2)
        layout.add_widget(btn_showlayer)
        layout.add_widget(btn_showplot)
        layout.add_widget(btn_double)
        layout.add_widget(btn_save_lut)
        layout.add_widget(self.label)

        root = BoxLayout(orientation='vertical')
        root.add_widget(upper_layout)
        root.add_widget(layout)
        slider.bind(value=partial(self.onlutlayerchange, wid))
        tp.default_tab_text = "Analysis"
        tp.background_color = (0, 0, 0, 1)
        tp.default_tab_content = root

        #Edit tab define
        th_text_head = TabbedPanelHeader(text='Edit')

        slider_layout = BoxLayout(size_hint=(1, 0.9))
        color_wid = Widget(size_hint=(1, 0.1))
        self.slider_list = []
        for i in range(33):
            self.slider_list.append(
                Slider(min=0,
                       max=1,
                       value=0,
                       value_track=False,
                       orientation='vertical',
                       cursor_size=(18, 18),
                       step=0.000001,
                       background_width=0))
        for slider_item in self.slider_list:
            slider_layout.add_widget(slider_item)
            slider_item.bind(value=partial(self.oneditcolorvalue, color_wid))

        edit_preview = BoxLayout(orientation='vertical', size_hint=(0.9, 1))
        edit_preview.add_widget(slider_layout)
        edit_preview.add_widget(color_wid)

        edit_layout_upper = BoxLayout()
        c_slider = Slider(min=0,
                          max=32,
                          value=0,
                          value_track=True,
                          orientation='vertical',
                          step=1.0,
                          value_track_color=[1, 0, 0, 1],
                          size_hint=(0.1, 1))
        c_slider.bind(value=partial(self.onslidervaluechange, color_wid))
        edit_layout_upper.add_widget(edit_preview)
        edit_layout_upper.add_widget(c_slider)

        edit_layout_lower = BoxLayout(size_hint=(1, None), height=50)
        btn_swap_axis = Button(text='Swap Axis',
                               size_hint=(0.15, 1),
                               on_press=partial(self.swap_axis, color_wid))

        btn_apply_change = Button(text='Apply Change',
                                  size_hint=(0.15, 1),
                                  on_press=partial(self.apply_change))
        self.edit_label = Label(text=self.edit_label_pattern.format(
            AxisList[self.edit_axis], AxisList[self.axis], 0, 0),
                                size_hint=(0.5, 1))
        edit_layout_lower.add_widget(btn_swap_axis)
        edit_layout_lower.add_widget(btn_apply_change)
        edit_layout_lower.add_widget(self.edit_label)
        edit_layout = BoxLayout(orientation='vertical')
        edit_layout.add_widget(edit_layout_upper)
        edit_layout.add_widget(edit_layout_lower)

        th_text_head.content = edit_layout

        tp.add_widget(th_text_head)
        th_text_head.bind(
            on_press=partial(self.edit_press_callback, color_wid))

        return tp
示例#2
0
    def __init__(self, df, security_name, **kwargs):
        super(Application, self).__init__(**kwargs)
        self.orientation = 'vertical'
        tab_panel = TabbedPanel()
        tab_panel.do_default_tab = False
        tab_panel.background_color = (7 / 255, 0, 13 / 255, 1)
        tab_menu = TabbedPanelItem(text="Menu")
        tab_menu.background_color = (62 / 255, 142 / 255, 222 / 255, 1)
        tab_chart = TabbedPanelItem(text='Chart')
        tab_chart.background_color = (62 / 255, 142 / 255, 222 / 255, 1)
        tab_training = TabbedPanelItem(text='Training')
        tab_training.background_color = (62 / 255, 142 / 255, 222 / 255, 1)
        tab_validate = TabbedPanelItem(text='Validate')
        tab_validate.background_color = (62 / 255, 142 / 255, 222 / 255, 1)
        tab_future = TabbedPanelItem(text='Prediction')
        tab_future.background_color = (62 / 255, 142 / 255, 222 / 255, 1)

        tab_panel.add_widget(tab_menu)
        tab_panel.add_widget(tab_chart)
        tab_panel.add_widget(tab_training)
        tab_panel.add_widget(tab_validate)
        tab_panel.add_widget(tab_future)

        tab_menu.bind(on_press=lambda x: change_screen('menu'))

        chart_layout = FloatLayout()
        fig = plot_data(df, security_name.upper(), 30, 200)
        canvas = fig.canvas
        chart_layout.add_widget(canvas)
        tab_chart.add_widget(chart_layout)

        predict_frame = FloatLayout(opacity=1)
        predict_btn = Button(text='Run Prediction',
                             background_color=(62 / 255, 142 / 255, 222 / 255,
                                               1),
                             font_size=20,
                             pos_hint={
                                 "center_x": 0.5,
                                 "bottom": 0
                             },
                             size_hint=(0.3, 0.075))

        predict_btn.bind(on_press=lambda x: start_predict(df, security_name))
        predict_frame.add_widget(predict_btn)
        chart_layout.add_widget(predict_frame)

        def start_predict(df, security_name):
            que = queue.Queue()
            par_modeling = partial(modeling, security_name=security_name)
            process = threading.Thread(
                target=lambda q, arg1: q.put(par_modeling(arg1)),
                args=(que, df),
                daemon=True)
            process.start()

            Clock.schedule_once(
                lambda *args: tab_panel.switch_to(tab_training))

            train_fig = plt.figure(facecolor='#07000d')
            train_canvas = train_fig.canvas
            train_layout = FloatLayout()
            train_layout.add_widget(train_canvas)
            tab_training.add_widget(train_layout)

            if os.path.exists('training.csv'):
                os.remove('training.csv')

            def update_plot(fig):
                train_canvas = fig.canvas
                train_layout.clear_widgets()
                train_layout.add_widget(train_canvas)
                plt.close(fig)
                # for child in train_layout.children[:1]:
                #     train_layout.remove_widget(child)
                # Clock.schedule_once(lambda *args: tab_panel.switch_to(tab_training))

            def read_training(self):
                if os.path.exists('training.csv'):
                    loss_df = None
                    try:
                        loss_df = pd.read_csv('training.csv')
                    except Exception as e:
                        print(e)
                        pass
                    if loss_df is not None:
                        train_fig = plot_loss(loss_df)
                        update_plot(train_fig)
                if not process.is_alive():
                    Clock.unschedule(read_training)
                    val_fig, future_fig = que.get()
                    val_canvas = val_fig.canvas
                    val_layout = FloatLayout()
                    val_layout.add_widget(val_canvas)
                    tab_validate.add_widget(val_layout)

                    future_canvas = future_fig.canvas
                    future_layout = FloatLayout()
                    future_layout.add_widget(future_canvas)
                    tab_future.add_widget(future_layout)

                    Clock.schedule_once(
                        lambda *args: tab_panel.switch_to(tab_validate))

            Clock.schedule_interval(read_training, 0.1)

        Clock.schedule_once(lambda *args: tab_panel.switch_to(tab_chart))

        self.add_widget(tab_panel)
示例#3
0
文件: main.py 项目: dbgrigsby/Postr
    def build(cls) -> TabbedPanel:
        performance_layout = FloatLayout()
        posts_layout = FloatLayout()
        events_layout = FloatLayout()
        update_layout = FloatLayout()
        profile_layout = FloatLayout()

        def spinner() -> Spinner:
            spin = Spinner(
                # default value
                text='Choose a site:',
                # available values
                values=(
                    'Discord', 'Facebook', 'Instagram', 'Reddit',
                    'Slack', 'Tumblr', 'Twitter', 'YouTube',
                ),

                size_hint=(.15, .1),
                pos=(15, 985),
                background_color=(0.094, 0.803, 0.803),
            )

            def show_selected_value(spnr: Spinner, text: str) -> None:
                print('The spinner', spnr, 'have text', text)

            spin.bind(text=show_selected_value)
            return spin

        performance_spinner = spinner()
        # performance_button = Button(
        #     text='Show Stats',
        #     font_size=14,
        #     color=(0.094, 0.803, 0.803),
        # )
        # performance_button.bind(on_press=callback)
        performance_layout.add_widget(performance_spinner)
        performance_layout.add_widget(
            Label(
                text='Follower Count: ', font_size='20sp',
                pos=(300, 850), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        performance_layout.add_widget(
            Label(
                text='Total Likes: ', font_size='20sp',
                pos=(300, 800), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        performance_stats = cls.performance(performance_spinner.values)
        performance_layout.add_widget(
            Label(
                text=str(performance_stats[0]), font_size='20sp',
                pos=(500, 850), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        performance_layout.add_widget(
            Label(
                text=str(performance_stats[1]), font_size='20sp',
                pos=(500, 800), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )

        post_spinner = spinner()
        # post_button = Button(
        #     text='Submit',
        #     font_size=14,
        #     color=(0.094, 0.803, 0.803),
        # )
        # # post_button.bind(on_press=callback)
        posts_layout.add_widget(post_spinner)
        posts_layout.add_widget(
            Label(
                text='Scheduled Posts: ', font_size='20sp',
                pos=(375, 675), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        post_types = Spinner(
            text='Post type',
            italic=True,
            values=(
                'Text', 'Image', 'Video', 'Link', 'Announcement',
            ),
            size_hint=(.15, .1),
            pos=(315, 985),
        )
        post_timing = Spinner(
            text='Choose a time:',
            italic=True,
            values=(
                'Immediately', 'Schedule for',
            ),

            size_hint=(.15, .1),
            pos=(615, 985),
        )
        posts_layout.add_widget(post_types)
        posts_layout.add_widget(post_timing)
        month = Spinner(
            text='Month',
            italic=True,
            values=(
                'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
                'November', 'December',
            ),
            size_hint=(.15, .1),
            pos=(915, 985),
        )
        day = Spinner(
            text='Day',
            italic=True,
            values=(
                '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
                '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31',
            ),
            size_hint=(.15, .1),
            pos=(1215, 985),
        )
        year = Spinner(
            text='Year',
            italic=True,
            values=(
                '2018', '2019', '2020',
            ),
            size_hint=(.15, .1),
            pos=(315, 850),
        )
        hour = Spinner(
            text='Hour',
            italic=True,
            values=(
                '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
                '20', '21', '22', '23',
            ),
            size_hint=(.15, .1),
            pos=(615, 850),
        )
        minute = Spinner(
            text='Minute',
            italic=True,
            values=(
                '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16',
                '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33',
                '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50',
                '51', '52', '53', '54', '55', '56', '57', '58', '59',
            ),
            size_hint=(.15, .1),
            pos=(915, 850),
        )
        posts_layout.add_widget(month)
        posts_layout.add_widget(day)
        posts_layout.add_widget(year)
        posts_layout.add_widget(hour)
        posts_layout.add_widget(minute)

        events_spinner = spinner()
        # events_button = Button(
        #     text='Submit',
        #     font_size=14,
        #     color=(0.094, 0.803, 0.803),
        # )
        # events_button.bind(on_press=callback)
        events_layout.add_widget(events_spinner)
        events_layout.add_widget(
            Label(
                text='React to: ', font_size='20sp',
                pos=(275, 900), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        events_layout.add_widget(
            Label(
                text='Hastag(s)', font_size='12sp',
                pos=(275, 850), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        hashtag_checkbox = CheckBox(pos=(450, 850), size_hint=(.15, .2), )
        events_layout.add_widget(hashtag_checkbox)
        events_layout.add_widget(
            Label(
                text='Key word', font_size='12sp',
                pos=(275, 800), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        keyword_checkbox = CheckBox(
            pos=(450, 800), size_hint=(.15, .2),
        )
        events_layout.add_widget(
            keyword_checkbox,
        )
        events_layout.add_widget(
            Label(
                text='Mention/Tag', font_size='12sp',
                pos=(275, 750), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        mention_tag_checkbox = CheckBox(
            pos=(450, 750), size_hint=(.15, .2),
        )
        events_layout.add_widget(
            mention_tag_checkbox,
        )
        events_layout.add_widget(
            Label(
                text='Like', font_size='12sp',
                pos=(275, 700), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        like_checkbox = CheckBox(
            pos=(450, 700), size_hint=(.15, .2),
        )
        events_layout.add_widget(
            like_checkbox,
        )
        events_layout.add_widget(
            Label(
                text='Comment', font_size='12sp',
                pos=(275, 650), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        comment_checkbox = CheckBox(
            pos=(450, 650), size_hint=(.15, .2),
        )
        events_layout.add_widget(
            comment_checkbox,
        )
        events_layout.add_widget(
            Label(
                text='Retweet/Repost/Share', font_size='12sp',
                pos=(275, 600), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        retweet_repost_share_checkbox = CheckBox(
            pos=(450, 600), size_hint=(.15, .2),
        )
        events_layout.add_widget(
            retweet_repost_share_checkbox,
        )

        update_spinner = spinner()
        # update_button = Button(
        #     text='Update',
        #     font_size=14,
        #     color=(0.094, 0.803, 0.803),
        # )
        # update_button.bind(on_press=callback)
        update_layout.add_widget(update_spinner)
        update_layout.add_widget(
            Label(
                text='Search for: ', font_size='20sp',
                pos=(275, 950), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        search_input = TextInput(
            multiline=False,
            pos=(300, 970), size_hint=(.15, .04),
        )
        update_layout.add_widget(
            search_input,
        )
        update_layout.add_widget(
            Label(
                text='Replace with: ', font_size='20sp',
                pos=(575, 950), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        replace_input = TextInput(
            multiline=False,
            pos=(575, 970), size_hint=(.15, .04),
        )
        update_layout.add_widget(
            replace_input,
        )

        profile_layout.add_widget(
            Label(
                text='Username: '******'20sp',
                pos=(45, 970), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        profile_layout.add_widget(
            Label(
                text='TEMP USERNAME', font_size='15sp',
                pos=(275, 967), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        profile_layout.add_widget(
            Label(
                text='Change Password: '******'20sp',
                pos=(55, 900), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        profile_layout.add_widget(
            Label(
                text='Old Password: '******'12sp',
                pos=(50, 850), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        old_password_input = TextInput(
            multiline=False,
            pos=(300, 935), size_hint=(.1, .04),
        )
        profile_layout.add_widget(
            old_password_input,
        )
        profile_layout.add_widget(
            Label(
                text='New Password: '******'12sp',
                pos=(50, 795), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        new_password_input = TextInput(
            multiline=False,
            pos=(300, 885), size_hint=(.1, .04),
        )
        profile_layout.add_widget(
            new_password_input,
        )
        profile_layout.add_widget(
            Label(
                text='Confirm New Password: '******'12sp',
                pos=(50, 745), size_hint=(.15, .2),
                color=(0, 0, 0, 1),
            ),
        )
        confirm_new_password_input = TextInput(
            multiline=False,
            pos=(300, 835), size_hint=(.1, .04),
        )
        profile_layout.add_widget(
            confirm_new_password_input,
        )

        tb_panel = TabbedPanel()
        tb_panel.do_default_tab = False
        tb_panel.background_color = (1, 1, 1, 1)
        tb_panel.border = [0, 0, 0, 0]
        tb_panel.background_image = 'path/to/background/image'

        # Create Performance tab
        performance_tab = TabbedPanelHeader(text='Performance')
        performance_tab.content = performance_layout
        tb_panel.add_widget(performance_tab)

        # Create Posts tab
        posts_tab = TabbedPanelHeader(text='Posts')
        posts_tab.content = posts_layout
        tb_panel.add_widget(posts_tab)

        # Create Events tab
        events_tab = TabbedPanelHeader(text='Events')
        events_tab.content = events_layout
        tb_panel.add_widget(events_tab)

        # Create Update tab
        update_tab = TabbedPanelHeader(text='Update')
        update_tab.content = update_layout
        tb_panel.add_widget(update_tab)

        # Create Profile tab
        profile_tab = TabbedPanelHeader(text='Profile')
        profile_tab.content = profile_layout
        tb_panel.add_widget(profile_tab)

        return tb_panel