def build(self):
          tb_panel= TabbedPanel()
          tb_panel.background_image ="fundal2.jpg"
          tb_panel.default_tab_text =  "tab-ul default"
          tb_panel.default_tab_content = Image(source='infoacademy3.gif',pos=(200, 100), size=(200, 200))

          th_text_head = TabbedPanelHeader(text='Text tab')
          th_text_head.content= Label(text='Infoacademy', font_size = 40)
 
          th_img_head= TabbedPanelHeader(text='Image tab')
          th_img_head.content= Image(source='infoacademy4.gif',pos=(400, 100), size=(400, 400))
 
          th_btn_head = TabbedPanelHeader(text='Button tab')
          layout= GridLayout(cols=1)
          eticheta=Label(text='tab-ul cu buton', font_size = 40)
          buton=Button(text='Acesta este un buton',font_size=20)
          layout.add_widget(eticheta)
          layout.add_widget(buton)
          th_btn_head.content= layout
          th_btn_head.content.padding = 200
          
 
          tb_panel.add_widget(th_text_head)
          tb_panel.add_widget(th_img_head)
          tb_panel.add_widget(th_btn_head)         
 
          return tb_panel
Beispiel #2
0
    def __init__(self, **kwargs):
        super(DataScreen, self).__init__(**kwargs)
        tab = TabbedPanel()

        self.th_chart_head = TabbedPanelHeader(text='Chart')
        tab.default_tab_text = 'Table'

        self.list_adapter = ListAdapter(data=[],
                                        args_converter=self.argsc,
                                        cls=TableItemView,
                                        selection_mode='single',
                                        allow_empty_selection=True)
        self.list_adapter.bind(on_selection_change=self.selection_changed)
        
        list_view = ListView(adapter=self.list_adapter)

        self.th_chart_head.content = GraphView()
        tab.default_tab_content = TableView(list_view)

        tab.add_widget(self.th_chart_head)

        button = Button(text='Add',size_hint_y=None,height=dp(50))
        button.bind(on_release=self.addItem)
        
        layout = BoxLayout(orientation='vertical')
        layout.add_widget(tab)
        layout.add_widget(button)
        self.add_widget(layout)
Beispiel #3
0
 def build(self):
     self.icon = 'diceSmall.png'
     mainPanel = TabbedPanel()
     mainPanel.default_tab_text = 'Dice Roll'
     
     mainPanel.add_widget(self.tabProbabilityTesting())
     mainPanel.default_tab_content = self.tabDiceRoll()
     return mainPanel
Beispiel #4
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
Beispiel #5
0
    def build(self):

        tb_panel = TabbedPanel()
        #tb_panel.do_default_tab = False
        #building_content= FloatLayout()

        #th_interval_head = TabbedPanelHeader(text="Interval")
        #th_interval = FloatLayout()
        #th_interval.add_widget(date1)
        #date2=datepicker.DatePicker(size_hint = (0.1,0.1))
        #th_interval.add_widget(date2)

        #th_interval_head.content = th_interval

        #th_building_head = TabbedPanelHeader(text="Building")
        #th_building_head.content = building_content

        graph_content = FloatLayout()

        StartDate = Label(text='Start Date:',
                          font_size=('19dp'),
                          size_hint=(0.1, 0.1),
                          pos_hint={
                              "x": 0.21,
                              "top": 1
                          })
        graph_content.add_widget(StartDate)

        startmonth = TextInput(text='',
                               font_size=('15dp'),
                               multiline=False,
                               pos_hint={
                                   "x": 1,
                                   "top": 0.5
                               },
                               hint_text="MM",
                               input_filter='int')
        start_month_area = FloatLayout(size_hint=(0.03, 0.04),
                                       pos_hint={
                                           "x": 0.27,
                                           "top": 0.99
                                       })
        start_month_area.add_widget(startmonth)
        graph_content.add_widget(start_month_area)

        slashDate1 = Label(text='/',
                           font_size=('19dp'),
                           size_hint=(0.1, 0.1),
                           pos_hint={
                               "x": 0.29,
                               "top": 1
                           })
        graph_content.add_widget(slashDate1)

        startday = TextInput(multiline=False,
                             font_size=('15dp'),
                             hint_text="DD",
                             pos_hint={
                                 "x": 1,
                                 "top": 0.5
                             },
                             input_filter='float')
        start_day_area = FloatLayout(size_hint=(0.03, 0.04),
                                     pos_hint={
                                         "x": 0.32,
                                         "top": .99
                                     })
        start_day_area.add_widget(startday)
        graph_content.add_widget(start_day_area)

        slashDate2 = Label(text='/',
                           font_size=('19dp'),
                           size_hint=(0.1, 0.1),
                           pos_hint={
                               "x": 0.34,
                               "top": 1
                           })
        graph_content.add_widget(slashDate2)

        startyear = TextInput(multiline=False,
                              font_size=('15dp'),
                              hint_text="YYYY",
                              pos_hint={
                                  "x": 1,
                                  "top": 0.45
                              },
                              input_filter='float')
        start_year_area = FloatLayout(size_hint=(0.04, 0.04),
                                      pos_hint={
                                          "x": 0.36,
                                          "top": .992
                                      })
        start_year_area.add_widget(startyear)
        graph_content.add_widget(start_year_area)

        starthour = TextInput(multiline=False,
                              font_size=('15dp'),
                              hint_text="Hr",
                              pos_hint={
                                  "x": 1,
                                  "top": 0.5
                              },
                              input_filter='float')
        start_hour_area = FloatLayout(size_hint=(0.03, 0.04),
                                      pos_hint={
                                          "x": 0.44,
                                          "top": .99
                                      })
        start_hour_area.add_widget(starthour)
        graph_content.add_widget(start_hour_area)

        colonDate1 = Label(text=':',
                           font_size=('19dp'),
                           size_hint=(0.1, 0.1),
                           pos_hint={
                               "x": 0.46,
                               "top": 1
                           })
        graph_content.add_widget(colonDate1)

        startminute = TextInput(multiline=False,
                                font_size=('15dp'),
                                hint_text="Min",
                                pos_hint={
                                    "x": 1,
                                    "top": 0.5
                                },
                                input_filter='float')
        start_minute_area = FloatLayout(size_hint=(0.03, 0.04),
                                        pos_hint={
                                            "x": 0.49,
                                            "top": .99
                                        })
        start_minute_area.add_widget(startminute)
        graph_content.add_widget(start_minute_area)

        bt3 = ToggleButton(text='AM',
                           group='time1',
                           size_hint=(0.05, 0.025),
                           pos_hint={
                               "x": 0.57,
                               "top": 0.974
                           })
        graph_content.add_widget(bt3)
        bt4 = ToggleButton(text='PM',
                           group='time1',
                           size_hint=(0.05, 0.025),
                           pos_hint={
                               "x": 0.57,
                               "top": 0.95
                           })
        graph_content.add_widget(bt4)

        EndDate = Label(text='End Date:',
                        font_size=('19dp'),
                        size_hint=(0.1, 0.1),
                        pos_hint={
                            "x": 0.21,
                            "top": 0.9
                        })
        graph_content.add_widget(EndDate)

        endmonth = TextInput(text='',
                             font_size=('15dp'),
                             multiline=False,
                             pos_hint={
                                 "x": 1,
                                 "top": 0.5
                             },
                             hint_text="MM",
                             input_filter='int')
        end_month_area = FloatLayout(size_hint=(0.03, 0.04),
                                     pos_hint={
                                         "x": 0.27,
                                         "top": 0.89
                                     })
        end_month_area.add_widget(endmonth)
        graph_content.add_widget(end_month_area)

        slashDate3 = Label(text='/',
                           font_size=('19dp'),
                           size_hint=(0.1, 0.1),
                           pos_hint={
                               "x": 0.29,
                               "top": .9
                           })
        graph_content.add_widget(slashDate3)

        endday = TextInput(multiline=False,
                           font_size=('15dp'),
                           hint_text="DD",
                           pos_hint={
                               "x": 1,
                               "top": 0.5
                           },
                           input_filter='float')
        end_day_area = FloatLayout(size_hint=(0.03, 0.04),
                                   pos_hint={
                                       "x": 0.32,
                                       "top": 0.89
                                   })
        end_day_area.add_widget(endday)
        graph_content.add_widget(end_day_area)

        slashDate4 = Label(text='/',
                           font_size=('19dp'),
                           size_hint=(0.1, 0.1),
                           pos_hint={
                               "x": 0.34,
                               "top": .9
                           })
        graph_content.add_widget(slashDate4)

        endyear = TextInput(multiline=False,
                            font_size=('15dp'),
                            hint_text="YYYY",
                            pos_hint={
                                "x": 1,
                                "top": 0.5
                            },
                            input_filter='float')
        end_year_area = FloatLayout(size_hint=(0.04, 0.04),
                                    pos_hint={
                                        "x": 0.36,
                                        "top": 0.89
                                    })
        end_year_area.add_widget(endyear)
        graph_content.add_widget(end_year_area)

        endhour = TextInput(multiline=False,
                            font_size=('15dp'),
                            hint_text="Hr",
                            pos_hint={
                                "x": 1,
                                "top": 0.5
                            },
                            input_filter='float')
        end_hour_area = FloatLayout(size_hint=(0.03, 0.04),
                                    pos_hint={
                                        "x": 0.44,
                                        "top": 0.89
                                    })
        end_hour_area.add_widget(endhour)
        graph_content.add_widget(end_hour_area)

        colonDate2 = Label(text=':',
                           font_size=('19dp'),
                           size_hint=(0.1, 0.1),
                           pos_hint={
                               "x": 0.46,
                               "top": 0.9
                           })
        graph_content.add_widget(colonDate2)

        endminute = TextInput(multiline=False,
                              font_size=('15dp'),
                              hint_text="Min",
                              pos_hint={
                                  "x": 1,
                                  "top": 0.5
                              },
                              input_filter='float')
        end_minute_area = FloatLayout(size_hint=(0.03, 0.04),
                                      pos_hint={
                                          "x": 0.49,
                                          "top": 0.89
                                      })
        end_minute_area.add_widget(endminute)
        graph_content.add_widget(end_minute_area)

        bt5 = ToggleButton(text='AM',
                           group='time2',
                           size_hint=(0.05, 0.025),
                           pos_hint={
                               "x": 0.57,
                               "top": 0.874
                           })
        graph_content.add_widget(bt5)
        bt6 = ToggleButton(text='PM',
                           group='time2',
                           size_hint=(0.05, 0.025),
                           pos_hint={
                               "x": 0.57,
                               "top": 0.85
                           })
        graph_content.add_widget(bt6)

        #graph settings
        midnightButton = ToggleButton(text='Midnight Markers',
                                      size_hint=(0.25, 0.05),
                                      pos_hint={
                                          "right": 1,
                                          "top": 1
                                      })
        midnightButton.bind(
            on_press=lambda x: (graphSettings.ToggleMidnight()))
        graph_content.add_widget(midnightButton)

        noonButton = ToggleButton(text='Noon Markers',
                                  size_hint=(0.25, 0.05),
                                  pos_hint={
                                      "right": 1,
                                      "top": .951
                                  })
        noonButton.bind(on_press=lambda x: (graphSettings.ToggleNoon()))
        graph_content.add_widget(noonButton)

        global ampm1
        ampm1 = "AM"  #default
        global ampm2
        ampm2 = "AM"  #default

        def ampmSET1(self):
            ampm1 = "AM"

        def ampmSET2(self):
            ampm1 = "PM"

        def ampmSET3(self):
            ampm2 = "AM"

        def ampmSET4(self):
            ampm2 = "PM"

        bt3.bind(on_press=ampmSET1)
        bt4.bind(on_press=ampmSET2)
        bt5.bind(on_press=ampmSET3)
        bt6.bind(on_press=ampmSET4)

        def buttonClicked(self):

            graph_area = FloatLayout(size_hint=(0.75, 0.8),
                                     pos_hint={
                                         "left": 0,
                                         "top": 0.9
                                     })

            plt.gcf().clear()

            try:
                sMonth = int(startmonth.text)
                sDay = int(startday.text)
                sYear = int(startyear.text)

                sHour = int(starthour.text)
                sMin = int(startminute.text)

                eMonth = int(endmonth.text)
                eDay = int(endday.text)
                eYear = int(endyear.text)

                eHour = int(endhour.text)
                eMin = int(endminute.text)

                if sMonth > 12:
                    sMonth = 12
                if sMonth < 0:
                    sMonth = 0

                if sMonth in [4, 6, 9, 11]:
                    if sDay > 30:
                        sDay = 30
                elif sMonth in [1, 3, 5, 7, 8, 10, 12]:
                    if sDay > 31:
                        sDay = 31
                elif sMonth == 2:
                    sDay = 28
                if sDay < 0:
                    sDay = 0

                if sYear > 2020:
                    sYear = 2020
                if sYear < 2000:
                    sYear = 2000

                if sHour > 12:
                    sHour = 12
                if sHour < 0:
                    sHour = 0

                if sMin > 59:
                    sMin = 59
                if sMin < 0:
                    sMin = 0

                if eMonth > 12:
                    eMonth = 12
                if eMonth < 0:
                    eMonth = 0

                if eMonth in [4, 6, 9, 11]:
                    if eDay > 30:
                        eDay = 30
                elif eMonth in [1, 3, 5, 7, 8, 10, 12]:
                    if eDay > 31:
                        eDay = 31
                elif eDay == 2:
                    eDay = 28
                if eDay < 0:
                    eDay = 0

                if eYear > 2020:
                    eYear = 2020
                if eYear < 2000:
                    eYear = 2000

                if eHour > 12:
                    eHour = 12
                if eHour < 0:
                    eHour = 0

                if eMin > 59:
                    eMin = 59
                if eMin < 0:
                    eMin = 0

                if sHour < 10:
                    sHour = "0" + str(sHour)
                if sMin < 10:
                    sMin = "0" + str(sMin)

                if eHour < 10:
                    eHour = "0" + str(eHour)
                if eMin < 10:
                    eMin = "0" + str(eMin)

                startinterval = (" " + str(sMonth) + "/" + str(sDay) + "/" +
                                 str(sYear) + " " + str(sHour) + ":" +
                                 str(sMin) + ":" + "00 " + ampm1)
                endinterval = (" " + str(eMonth) + "/" + str(eDay) + "/" +
                               str(eYear) + " " + str(eHour) + ":" +
                               str(eMin) + ":" + "00 " + ampm2)

                database.SetInterval(startinterval, endinterval)
            except:
                plt.gcf().clear()
                graph_area.add_widget(
                    Label(text="No data for given parameters",
                          font_size="30dp",
                          pos_hint={
                              "x": 0,
                              "y": 0.1
                          },
                          color=(1, 0, 0, 1)))
                graph_content.add_widget(graph_area)
                return 0

            if database.ReadData() == False or len(
                    database.selectedBuildings) == 0:
                plt.gcf().clear()
                graph_area.add_widget(
                    Label(text="No data for given parameters",
                          font_size="30dp",
                          pos_hint={
                              "x": 0,
                              "y": 0.1
                          },
                          color=(1, 0, 0, 1)))
                graph_content.add_widget(graph_area)
                return 0
            #if database has no data return a graph error

            # Initialize graph after prospects
            # Loop for grabbing buildings and data points
            ticks = []
            labels = []
            timestamps = []
            kilowatts = []
            for buildingNum in range(0, len(database.buildingsData)):
                timestamps = []
                kilowatts = []
                for dataPoint in range(
                        0,
                        len(database.buildingsData[buildingNum].dataPoints)):
                    timestamps.append(
                        database.SetDateToUnix(
                            database.buildingsData[buildingNum].
                            dataPoints[dataPoint].timestamp))
                    kilowatts.append(
                        float(database.buildingsData[buildingNum].
                              dataPoints[dataPoint].kilowatts))
                plt.plot(timestamps,
                         kilowatts,
                         label=str(database.buildingsData[buildingNum].name))
                plt.xlabel('Timestamp')
                plt.ylabel('Kilowatts')
                plt.legend()

            #midnight and noon lines
            if graphSettings.midnight == True:
                for midnight in timestamps:
                    if (midnight % 86400) == 0:
                        plt.axvline(x=(midnight),
                                    linestyle=('--'),
                                    color=(0, 0, 0, 1))

            #for noon in
            if graphSettings.noon == True:
                for noon in timestamps:
                    if (noon % 86400) == 43200:
                        plt.axvline(x=(noon),
                                    linestyle=('--'),
                                    color=(1, 0, 0, 1))

            tickNum = 7
            for x in range(0, tickNum):
                ticks.append(
                    (x *
                     ((database.unixInterval[1] - database.unixInterval[0]) /
                      tickNum) + database.unixInterval[0]))
                # print(self.ticks[x])#verifies the graph ticks
                label = database.SetUnixToLabel(
                    (x *
                     ((database.unixInterval[1] - database.unixInterval[0]) /
                      tickNum) + database.unixInterval[0]))
                labels.append(label)
                # print(self.labels[x])#verifies the graph tick labels
            ticks.append(database.unixInterval[1])
            labels.append(database.SetUnixToLabel(database.unixInterval[1]))
            plt.xticks(ticks=ticks, labels=labels, rotation=15)
            plt.title("Dynamic Kilowatt/hr Graph")
            plt.grid()

            graphwidget = FigureCanvasKivyAgg((plt.gcf()))
            graph_area.add_widget(graphwidget)
            graph_content.add_widget(graph_area)

        ok = Button(text="Graph",
                    size_hint=(.2, .2),
                    pos_hint={
                        "x": 0,
                        "top": 1
                    })
        ok.bind(on_press=buttonClicked)
        graph_content.add_widget(ok)

        buildingButtons = []

        def createButton(name, index):
            button = ToggleButton(text=name,
                                  size_hint=(0.25, 0.05),
                                  pos_hint={
                                      "right": 1,
                                      "y": 0.05 * index
                                  })
            button.bind(
                on_press=lambda x: (database.ChangeBuilding(index + 1)))
            graph_content.add_widget(button)

        for i, val in enumerate(database.buildings):
            createButton(val, i)

        #_lgraph_head = TabbedPanelHeader(text='Graphs')
        #th_lgraph_head.content = graph_content

        tb_panel.default_tab_content = graph_content

        tb_panel.default_tab_text = "Graphs"

        #tb_panel.add_widget(th_interval_head)
        #tb_panel.add_widget(th_building_head)
        #tb_panel.add_widget(th_lgraph_head)

        return tb_panel
Beispiel #6
0
 def coin_page(self):
     mainview = ModalView(size_hint=(0.75, 0.75))
     grid = GridLayout(
         rows=2,
         cols=1,
         padding=[10, 15, 10, 30]  # left, top, right, bottom
     )
     # Area to contain price graphs located at the top half of the screen.
     graph_box = BoxLayout(orientation="vertical",
                           size_hint_y=0.5,
                           size_hint_x=.6)
     # Will contain the alerts below graph - once user sets them
     alarm_box = GridLayout(cols=2, size_hint_x=1, size_hint_y=.5)
     # First row of alerts box contains current price.
     self.current_price = coin_gecko.get_crypto_fiat_price(
         cryptoCurrency=self.current_coin)
     live_price_text = 'The current price is $' \
                       + str(self.current_price)
     live_price_label = Label(text="", size_hint_x=.5)
     dummy_label = Label(text=live_price_text, size_hint_x=.5)
     alarm_box.add_widget(live_price_label)
     alarm_box.add_widget(dummy_label)
     # Second row of alerts box contains alerts input box
     set_alarm_label = Label(text='Set Target Price: ', size_hint_x=0.5)
     self.alarm_textinput = TextInput(multiline=False, size_hint_x=0.5)
     # method actioned to check text input
     self.alarm_textinput.bind(text=self.on_text)
     alarm_box.add_widget(set_alarm_label)
     alarm_box.add_widget(self.alarm_textinput)
     # Third row of alerts box to contain buttons to set alerts
     alarm_button_less_than = Button(text="<", size_hint_x=1)
     alarm_button_more_than = Button(text=">", size_hint_x=1)
     alarm_box.add_widget(alarm_button_less_than)
     alarm_box.add_widget(alarm_button_more_than)
     # methods called on press of third row buttons, and then alerts added to log
     alarm_button_less_than.bind(on_release=self.alert_callback_less_than)
     alarm_button_more_than.bind(on_release=self.alert_callback_more_than)
     # Fourth row of alerts box will contain the alerts log.
     # self.scroll_label = ScrollableLabel(size_hint_x=1) #shown as self.history in sentdex tutorial
     # how to use self for input/label while not using self for old alerts
     # existing alerts
     scrollable_label = ScrollableLabel(size_hint_x=1)  # existing alerts
     alarm_box.add_widget(scrollable_label)
     # new alerts
     self.new_alerts_scrollable_label = ScrollableLabel(size_hint_x=1)
     alarm_box.add_widget(self.new_alerts_scrollable_label)
     self.price_chart()
     # Fourth row of alerts box continued
     graph_tabs = TabbedPanel(pos_hint={'center_x': .5, 'center_y': 1})
     graph_tabs.default_tab_text = '24hr'
     graph_tabs.default_tab.bind = self.one_day_chart()
     graph_tabs.default_tab_content = self.graph
     # graph title
     seven_days_tab = TabbedPanelHeader(text='7 days')
     seven_days_tab.bind = self.seven_day_chart()
     seven_days_tab.content = self.graph
     graph_tabs.add_widget(seven_days_tab)
     # make the actual plots
     graph_box.add_widget(graph_tabs)
     grid.add_widget(graph_box)
     grid.add_widget(alarm_box)
     # grid.add_widget(scrollable_label)
     mainview.add_widget(grid)
     mainview.open()
     parsedatabase.check_alerts(scrollable_label)
Beispiel #7
0
    def __init__(self, app, music_player):
        """Create main GUI

        Arguments:
        parent -- parent application to this widget
        music_player -- audio generator for full application
        network -- network client and server handler

        """

        # Initialize Tkinter, and instruct it hide root window
        self.tk_root = Tkinter.Tk()
        self.tk_root.withdraw()

        # Perform widget initializations
        super(GUI, self).__init__()

        # OVERALL STRUCTURE
        WINDOW_WIDTH = 800
        WINDOW_HEIGHT = 600
        OUTER_PADDING = 20

        # Set default parameters to be used in accurately loading an
        # initial state to the GUI
        self.app = app
        self.music_player = music_player
        self.track_id = MusicPlayer.WAVETABLE_A
        self.popup_count = 0

        # Turn off multi-touch in this GUI
        Config.set('input', 'mouse', 'mouse,disable_multitouch')

        # Determine image directory
        IMAGE_DIR = system.get_images_dir()

        # For dynamic GUI coloring
        self.TRACK_COLORS = [[.7, .4, .9, 1.0], 
                             [.6, .9, .4, 1.0], 
                             [.8, .5, .3, 1.0]]
        self.colorables = []

        # Create widget for the main layout. This will be added separately
        # from each of our popup windows
        self.main_layout = NSWidget()
        self.add_widget(self.main_layout)

        # BUTTON GRID
        NOTE_BUTTON_WIDTH = 48
        NOTE_BUTTON_HEIGHT = 48
        NOTE_BUTTON_PADDING = 7
        ROW_LABEL_WIDTH = 54
        ROW_LABEL_HEIGHT = NOTE_BUTTON_HEIGHT
        ROW_LABEL_FONT_SIZE = 10
        NOTE_BUTTON_ROWS = MusicPlayer.NUM_ROWS
        NOTE_BUTTON_COLS = MusicPlayer.NUM_COLS

        GRID_WIDTH = NOTE_BUTTON_PADDING + ROW_LABEL_WIDTH + \
                     NOTE_BUTTON_PADDING + (NOTE_BUTTON_COLS * 
                     (NOTE_BUTTON_WIDTH + NOTE_BUTTON_PADDING))
        GRID_HEIGHT = NOTE_BUTTON_PADDING + (NOTE_BUTTON_ROWS * 
                      (NOTE_BUTTON_HEIGHT + NOTE_BUTTON_PADDING))
        GRID_X = OUTER_PADDING
        GRID_Y = WINDOW_HEIGHT - OUTER_PADDING - GRID_HEIGHT

        PLAYHEAD_WIDTH = NOTE_BUTTON_WIDTH + 4
        PLAYHEAD_HEIGHT = GRID_HEIGHT
        PLAYHEAD_OPACITY = .5
        PLAYHEAD_COLOR = Color(1.0, 1.0, 1.0)

        # Playhead
        playhead_widget = Widget()
        playhead_canvas = Canvas()
        playhead_canvas.add(PLAYHEAD_COLOR)
        playhead = Rectangle(size=[PLAYHEAD_WIDTH, PLAYHEAD_HEIGHT])
        playhead_canvas.add(playhead)
        playhead_canvas.opacity = PLAYHEAD_OPACITY
        playhead_widget.canvas = playhead_canvas
        self.main_layout.add_widget(playhead_widget)
        self.playhead = playhead

        # For each row, create labels and notes
        self.row_labels = []
        self.note_buttons = []

        row_top = GRID_Y + GRID_HEIGHT - NOTE_BUTTON_PADDING

        for row in range(0, NOTE_BUTTON_ROWS):
            col_x = GRID_X + NOTE_BUTTON_PADDING

            # Make label for row
            row_label = Label(text=str(row), width=ROW_LABEL_WIDTH, 
                              height=ROW_LABEL_HEIGHT, 
                              text_size=[ROW_LABEL_WIDTH, ROW_LABEL_HEIGHT],
                              font_size=ROW_LABEL_FONT_SIZE, halign='center',
                              valign='middle')
            row_label.x = col_x
            row_label.top = row_top
            self.main_layout.add_widget(row_label)
            self.row_labels.append(row_label)

            col_x = col_x + ROW_LABEL_WIDTH + NOTE_BUTTON_PADDING
            
            # Create all buttons for row
            row_notes = []
            for col in range(0, NOTE_BUTTON_COLS):
                col_button = NSToggleButton(width=NOTE_BUTTON_WIDTH,
                                          height=NOTE_BUTTON_HEIGHT)
                col_button.id = 'row' + str(row) + ',col' + str(col)
                col_button.x = col_x
                col_button.top = row_top
                col_button.bind(on_press=self.trigger_note)
                row_notes.append(col_button)
                self.main_layout.add_widget(col_button)
                self.colorables.append(col_button)
                col_x = col_x + NOTE_BUTTON_WIDTH + NOTE_BUTTON_PADDING
                
            self.note_buttons.append(row_notes)
            row_top = row_top - NOTE_BUTTON_PADDING - NOTE_BUTTON_HEIGHT

        # Set playhead start position
        leftmost_note = self.note_buttons[0][0]
        playhead_x = leftmost_note.center_x - (PLAYHEAD_WIDTH / 2)
        playhead_y = GRID_Y
        self.playhead.pos = [playhead_x, playhead_y]

        # PLAYBACK MENU
        PLAYBACK_X = OUTER_PADDING
        PLAYBACK_Y = OUTER_PADDING
        PLAYBACK_WIDTH = GRID_WIDTH
        PLAYBACK_HEIGHT = WINDOW_HEIGHT - OUTER_PADDING - GRID_HEIGHT - \
                          OUTER_PADDING - OUTER_PADDING
        PLAYBACK_CENTER_Y = PLAYBACK_Y + (PLAYBACK_HEIGHT / 2)
        PLAYBACK_TOP = PLAYBACK_Y + PLAYBACK_HEIGHT

        PLAY_BUTTON_WIDTH = 48
        PLAY_BUTTON_HEIGHT = 48
        PLAYALL_BUTTON_WIDTH = 60
        PLAYALL_BUTTON_HEIGHT = PLAY_BUTTON_HEIGHT / 2
        PLAYALL_BUTTON_FONT_SIZE = 8
        PLAYALL_BUTTON_TEXT_SIZE = [PLAYALL_BUTTON_WIDTH, 
                                    PLAYALL_BUTTON_HEIGHT]
        PAGE_BUTTON_WIDTH = 20
        PAGE_BUTTON_HEIGHT = 30
        NUM_PAGE_BUTTONS = MusicPlayer.NUM_PAGES
        PAGE_LABEL_WIDTH = (PAGE_BUTTON_WIDTH * NUM_PAGE_BUTTONS)
        PAGE_LABEL_HEIGHT = 20
        PAGE_LABEL_FONT_SIZE = 10
        PAGE_LABEL_OFFSET = 5
        TRACK_BUTTON_WIDTH = 48
        TRACK_BUTTON_HEIGHT = 48
        NUM_TRACK_BUTTONS = MusicPlayer.NUM_TRACKS
        NUM_PLAYBACK_ELEMENTS = 4
        TRACK_LABEL_WIDTH = TRACK_BUTTON_WIDTH * NUM_TRACK_BUTTONS
        TRACK_LABEL_HEIGHT = PAGE_LABEL_HEIGHT
        TRACK_LABEL_FONT_SIZE = PAGE_LABEL_FONT_SIZE
        TRACK_LABEL_TEXT_SIZE = [TRACK_LABEL_WIDTH, TRACK_LABEL_HEIGHT]
        TRACK_LABEL_OFFSET = PAGE_LABEL_OFFSET

        PLAYBACK_PADDING = (PLAYBACK_WIDTH - (PAGE_BUTTON_WIDTH * 
                            NUM_PAGE_BUTTONS) - (PLAY_BUTTON_WIDTH) - 
                            (TRACK_BUTTON_WIDTH * NUM_TRACK_BUTTONS) - 
                            PLAYALL_BUTTON_WIDTH) / (NUM_PLAYBACK_ELEMENTS + 1)
        
        # Play/pause button
        PLAY_BUTTON_X = PLAYBACK_X + PLAYBACK_PADDING
        # TODO: add a border for this button
        play_button = ToggleButton(width=PLAY_BUTTON_WIDTH, 
                             height=PLAY_BUTTON_HEIGHT)
        play_button.bind(on_press=self.play_pause)
        play_button.background_normal = \
            os.path.join(IMAGE_DIR, "media-playback-start-4.png")
        play_button.background_down = \
            os.path.join(IMAGE_DIR, "media-playback-pause-4.png")
        play_button.x = PLAY_BUTTON_X
        play_button.center_y = PLAYBACK_CENTER_Y
        self.play_button = play_button
        self.main_layout.add_widget(play_button)
        self.colorables.append(play_button)

        # Buttons to play one page or all
        one_page_button = NSToggleButton(width=PLAYALL_BUTTON_WIDTH,
                                       height=PLAYALL_BUTTON_HEIGHT,
                                       text='One page',
                                       text_size=PLAYALL_BUTTON_TEXT_SIZE,
                                       font_size=PLAYALL_BUTTON_FONT_SIZE,
                                       halign='center', valign='middle')
        one_page_button.bind(on_press=self.play_one_page)
        one_page_button.x = play_button.right + PLAYBACK_PADDING
        one_page_button.top = PLAYBACK_CENTER_Y + PLAYALL_BUTTON_HEIGHT
        self.one_page_button = one_page_button
        self.main_layout.add_widget(one_page_button)
        self.colorables.append(one_page_button)

        all_pages_button = NSToggleButton(width=PLAYALL_BUTTON_WIDTH,
                                        height=PLAYALL_BUTTON_HEIGHT,
                                        text='All pages', 
                                        text_size=PLAYALL_BUTTON_TEXT_SIZE,
                                        font_size=PLAYALL_BUTTON_FONT_SIZE,
                                        halign='center', valign='middle')
        all_pages_button.bind(on_press=self.play_all_pages)
        all_pages_button.x = one_page_button.x
        all_pages_button.top = PLAYBACK_CENTER_Y
        self.all_pages_button = all_pages_button
        self.main_layout.add_widget(all_pages_button)
        self.colorables.append(all_pages_button)
        
        if music_player.play_all == False:
            one_page_button.state = 'down'
            all_pages_button.state = 'normal'
        elif music_player.play_all == True:
            one_page_button.state = 'normal'
            all_pages_button.state = 'down'

        # Page selection buttons
        self.page_buttons = []
        page_buttons = []
        page_label = Label(text='Page Select', text_size=[PAGE_LABEL_WIDTH, 
                           PAGE_LABEL_HEIGHT], font_size=PAGE_LABEL_FONT_SIZE,
                           width=PAGE_LABEL_WIDTH, height=PAGE_LABEL_HEIGHT,
                           halign='center', valign='middle')
        page_button_x = all_pages_button.right + PLAYBACK_PADDING
        page_label.x = page_button_x
        page_label.top = PLAYBACK_CENTER_Y - (PAGE_BUTTON_HEIGHT / 2) - \
                         PAGE_LABEL_OFFSET
        self.main_layout.add_widget(page_label)
        for page_index in range(0, NUM_PAGE_BUTTONS):
            page_id = 'page' + str(page_index)
            page_button = NSToggleButton(width=PAGE_BUTTON_WIDTH,
                                       height=PAGE_BUTTON_HEIGHT, id=page_id)
            page_button.bind(on_press=self.select_page)
            page_button.x = page_button_x
            page_button.center_y = PLAYBACK_CENTER_Y
            page_buttons.append(page_button)
            self.main_layout.add_widget(page_button)
            self.colorables.append(page_button)
            page_button_x += PAGE_BUTTON_WIDTH

        self.page_buttons = page_buttons

        # Select the current music player's page with the GUI
        page_buttons[music_player.page_index].state = 'down'

        # Track selection buttons
        TRACK_BUTTON_FONT_SIZE = 10
        TRACK_BUTTON_TEXT_SIZE = [TRACK_BUTTON_WIDTH, TRACK_BUTTON_HEIGHT]
        
        track_text = ["Bass", "Lead", "Drum"]
        track_buttons = []
        self.track_buttons = []
        track_button_x = page_buttons[len(page_buttons) - 1].right + \
                         PLAYBACK_PADDING
        for track_index in range(0, NUM_TRACK_BUTTONS):
            track_id = 'track' + str(track_index)
            track_button = NSToggleButton(text=track_text[track_index],
                                        width=TRACK_BUTTON_WIDTH, 
                                        height=TRACK_BUTTON_HEIGHT, id=track_id,
                                        text_size=TRACK_BUTTON_TEXT_SIZE,
                                        font_size=TRACK_BUTTON_FONT_SIZE,
                                        halign='center', valign='middle')
            track_button.bind(on_press=self.select_track)
            track_button.x = track_button_x
            track_button.center_y = PLAYBACK_CENTER_Y
            track_buttons.append(track_button)
            self.main_layout.add_widget(track_button)
            track_button_x += TRACK_BUTTON_WIDTH
        
        self.track_buttons = track_buttons        
    
        # Select the current track in the GUI
        track_buttons[self.track_id].state = 'down'

        leftmost_track_button = self.track_buttons[0]

        track_label = Label(text='Instrument Select', 
                           text_size=TRACK_LABEL_TEXT_SIZE,
                           font_size=TRACK_LABEL_FONT_SIZE,
                           width=TRACK_LABEL_WIDTH, 
                           height=TRACK_LABEL_HEIGHT,
                           halign='center', valign='middle')
        track_label.x = leftmost_track_button.x
        track_label.top = leftmost_track_button.y - TRACK_LABEL_OFFSET
        # self.main_layout.add_widget(track_label)

        # SETTINGS TABS
        TABS_X = OUTER_PADDING + GRID_WIDTH + OUTER_PADDING
        TABS_Y = GRID_Y
        TABS_WIDTH = WINDOW_WIDTH - OUTER_PADDING - GRID_WIDTH - \
                     OUTER_PADDING - OUTER_PADDING
        TABS_HEIGHT = GRID_HEIGHT
        
        # Element is button, label, etc. Section is vertical group of elements
        TAB_SECTION_PADDING = 20
        TAB_ELEMENT_PADDING = 10

        # Note: it's a good idea to make these tabs the size of our icons,
        # which is 48x48
        TAB_HEADER_WIDTH = 48
        TAB_HEADER_HEIGHT = TAB_HEADER_WIDTH
        TAB_HEADER_FONT_SIZE = 20
        SECTION_LABEL_FONT_SIZE = 16
        SECTION_LABEL_WIDTH = TABS_WIDTH - TAB_SECTION_PADDING * 2
        SECTION_LABEL_HEIGHT = 30
        SECTION_LABEL_TEXT_SIZE = [SECTION_LABEL_WIDTH, SECTION_LABEL_HEIGHT]
        ELEMENT_LABEL_FONT_SIZE = 10
        ELEMENT_LABEL_WIDTH = TABS_WIDTH - TAB_ELEMENT_PADDING * 2
        ELEMENT_LABEL_HEIGHT = 20
        ELEMENT_LABEL_TEXT_SIZE = [ELEMENT_LABEL_WIDTH, ELEMENT_LABEL_HEIGHT]
        TAB_CONTENT_HEIGHT = TABS_HEIGHT - TAB_HEADER_HEIGHT
        TAB_CONTENT_TOP = TABS_Y + TAB_CONTENT_HEIGHT

        # Create main tabbed panel
        tabs = TabbedPanel(tab_width=TAB_HEADER_WIDTH, 
                           tab_height=TAB_HEADER_HEIGHT, width=TABS_WIDTH, 
                           height=TABS_HEIGHT)
        tabs.x = TABS_X
        tabs.y = TABS_Y
        self.main_layout.add_widget(tabs)
        self.tabs = tabs

        # Music tab (default)
        music_tab_content = Widget(width=TABS_WIDTH, height=TAB_CONTENT_HEIGHT)
        tabs.default_tab_content = music_tab_content
        tabs.default_tab.text = ""
        # TODO: make these paths absolute?
        tabs.default_tab.background_normal = \
            os.path.join(IMAGE_DIR, "audio-keyboard.png")
        print "@@ default tab bg: ", tabs.default_tab.background_normal
        tabs.default_tab.background_down = \
            os.path.join(IMAGE_DIR, "audio-keyboard-down.png")

        # Global music options
        global_music_label = Label(text='Global', 
                                   font_size=SECTION_LABEL_FONT_SIZE,
                                   width=SECTION_LABEL_WIDTH, 
                                   height=SECTION_LABEL_HEIGHT,
                                   text_size=SECTION_LABEL_TEXT_SIZE,
                                   halign='center', valign='middle')
        global_music_label.center_x = tabs.center_x
        global_music_label.top = TAB_CONTENT_TOP - TAB_SECTION_PADDING
        music_tab_content.add_widget(global_music_label)
        
        MUSIC_SLIDER_WIDTH = TABS_WIDTH - 40
        MUSIC_SLIDER_HEIGHT = 20

        # Note: these sliders buttons have a predefined height, so we are a
        # slave to that height for positioning the sliders
        global_volume_slider = NSSlider(min=MusicPlayer.MIN_VOLUME, 
                                        max=MusicPlayer.MAX_VOLUME,
                                        value=music_player.global_volume,
                                        orientation='horizontal',
                                        height=MUSIC_SLIDER_HEIGHT,
                                        width=MUSIC_SLIDER_WIDTH)
        global_volume_slider.bind(on_touch_move=self.change_global_volume)
        global_volume_slider.center_x = tabs.center_x
        global_volume_slider.top = global_music_label.y - TAB_ELEMENT_PADDING
        music_tab_content.add_widget(global_volume_slider)
        self.global_volume_slider = global_volume_slider
        self.colorables.append(global_volume_slider)

        global_volume_label = Label(text='Volume',
                                    font_size=ELEMENT_LABEL_FONT_SIZE,
                                    width=ELEMENT_LABEL_WIDTH,
                                    height=ELEMENT_LABEL_HEIGHT,
                                    text_size=ELEMENT_LABEL_TEXT_SIZE,
                                    halign='center', valign='middle')
        global_volume_label.center_x = tabs.center_x
        global_volume_label.top = global_volume_slider.y - TAB_ELEMENT_PADDING
        music_tab_content.add_widget(global_volume_label)
        
        global_tempo_slider = NSSlider(min=MusicPlayer.MIN_TEMPO, 
                                       max=MusicPlayer.MAX_TEMPO,
                                       value=music_player.tempo,
                                       orientation='horizontal',
                                       height=MUSIC_SLIDER_HEIGHT,
                                       width=MUSIC_SLIDER_WIDTH)
        global_tempo_slider.bind(on_touch_move=self.change_global_tempo)
        global_tempo_slider.center_x = tabs.center_x
        global_tempo_slider.top = global_volume_label.y - TAB_ELEMENT_PADDING
        music_tab_content.add_widget(global_tempo_slider)
        self.global_tempo_slider = global_tempo_slider
        self.colorables.append(global_tempo_slider)

        global_tempo_label = Label(text='Tempo',
                                   font_size=ELEMENT_LABEL_FONT_SIZE,
                                   width=ELEMENT_LABEL_WIDTH,
                                   height=ELEMENT_LABEL_HEIGHT,
                                   text_size=ELEMENT_LABEL_TEXT_SIZE,
                                   halign='center', valign='middle')
        global_tempo_label.center_x = tabs.center_x
        global_tempo_label.top = global_tempo_slider.y - TAB_ELEMENT_PADDING
        music_tab_content.add_widget(global_tempo_label)

        # Instrument settings
        track_music_label = Label(text='Instrument', 
                                  font_size=SECTION_LABEL_FONT_SIZE,
                                  width=SECTION_LABEL_WIDTH, 
                                  height=SECTION_LABEL_HEIGHT,
                                  text_size=SECTION_LABEL_TEXT_SIZE,
                                  halign='center', valign='middle')
        track_music_label.center_x = tabs.center_x
        track_music_label.top = global_tempo_label.y - TAB_SECTION_PADDING
        music_tab_content.add_widget(track_music_label)
        
        track_volume_initial = music_player.get_volume(self.track_id)
        track_volume_slider = NSSlider(min=MusicPlayer.MIN_VOLUME, 
                                       max=MusicPlayer.MAX_VOLUME,
                                       value=track_volume_initial,
                                       orientation='horizontal',
                                       height=MUSIC_SLIDER_HEIGHT,
                                       width=MUSIC_SLIDER_WIDTH)
        track_volume_slider.bind(on_touch_move=self.change_track_volume)
        track_volume_slider.center_x = tabs.center_x
        track_volume_slider.top = track_music_label.y - TAB_ELEMENT_PADDING
        music_tab_content.add_widget(track_volume_slider)
        self.track_volume_slider = track_volume_slider
        self.colorables.append(track_volume_slider)

        track_volume_label = Label(text='Volume',
                                   font_size=ELEMENT_LABEL_FONT_SIZE,
                                   width=ELEMENT_LABEL_WIDTH,
                                   height=ELEMENT_LABEL_HEIGHT,
                                   text_size=ELEMENT_LABEL_TEXT_SIZE,
                                   halign='center', valign='middle')
        track_volume_label.center_x = tabs.center_x
        track_volume_label.top = track_volume_slider.y - TAB_ELEMENT_PADDING
        music_tab_content.add_widget(track_volume_label)
        
        track_reverb_initial = music_player.get_reverb(self.track_id)
        track_reverb_slider = NSSlider(min=MusicPlayer.MIN_REVERB,
                                       max=MusicPlayer.MAX_REVERB,
                                       value=track_reverb_initial,
                                       orientation='horizontal',
                                       height=MUSIC_SLIDER_HEIGHT,
                                       width=MUSIC_SLIDER_WIDTH)
        track_reverb_slider.bind(on_touch_move=self.change_track_reverb)
        track_reverb_slider.center_x = tabs.center_x
        track_reverb_slider.top = track_volume_label.y - TAB_ELEMENT_PADDING
        music_tab_content.add_widget(track_reverb_slider)
        self.track_reverb_slider = track_reverb_slider
        self.colorables.append(track_reverb_slider)

        track_reverb_label = Label(text='Reverb',
                                   font_size=ELEMENT_LABEL_FONT_SIZE,
                                   width=ELEMENT_LABEL_WIDTH,
                                   height=ELEMENT_LABEL_HEIGHT,
                                   text_size=ELEMENT_LABEL_TEXT_SIZE,
                                   halign='center', valign='middle')
        track_reverb_label.center_x = tabs.center_x
        track_reverb_label.top = track_reverb_slider.y - TAB_ELEMENT_PADDING
        music_tab_content.add_widget(track_reverb_label)

        # Network tab
        network_tab = TabbedPanelHeader()
        network_tab.text = ""
        network_tab.background_normal = \
            os.path.join(IMAGE_DIR, "network-wired-2.png")
        network_tab.background_down = \
            os.path.join(IMAGE_DIR, "network-wired-2-down.png")
        tabs.add_widget(network_tab)
        
        TEXT_INPUT_HEIGHT = 30
        PORT_INPUT_WIDTH = 70
        IP_INPUT_WIDTH = TABS_WIDTH - TAB_SECTION_PADDING - \
                         PORT_INPUT_WIDTH - TAB_ELEMENT_PADDING - \
                         TAB_SECTION_PADDING
        PORT_LABEL_TEXT_SIZE = [PORT_INPUT_WIDTH, ELEMENT_LABEL_HEIGHT]
        IP_LABEL_TEXT_SIZE = [IP_INPUT_WIDTH, ELEMENT_LABEL_HEIGHT]
        NETWORK_BUTTON_WIDTH = TABS_WIDTH - TAB_SECTION_PADDING * 2
        NETWORK_BUTTON_HEIGHT = 80
        NETWORK_BUTTON_FONT_SIZE = 16
        NETWORK_BUTTON_TEXT_SIZE = [NETWORK_BUTTON_WIDTH, NETWORK_BUTTON_HEIGHT]

        SERVER_PORT_TEXT = 'Server Port'
        SERVER_IP_TEXT = 'Server IP Address'
        network_tab_content = Widget(width=TABS_WIDTH, height=TAB_CONTENT_HEIGHT)
        network_tab.content = network_tab_content

        # Server input labels
        server_port_label = Label(text=SERVER_PORT_TEXT, 
                                  width=PORT_INPUT_WIDTH,
                                  height=ELEMENT_LABEL_HEIGHT,
                                  text_size=PORT_LABEL_TEXT_SIZE,
                                  font_size=ELEMENT_LABEL_FONT_SIZE)
        server_port_label.top = TAB_CONTENT_TOP - TAB_SECTION_PADDING
        server_port_label.x = TABS_X + TAB_SECTION_PADDING
        network_tab_content.add_widget(server_port_label)

        server_ip_label = Label(text=SERVER_IP_TEXT, 
                                  width=IP_INPUT_WIDTH,
                                  height=ELEMENT_LABEL_HEIGHT,
                                  text_size=IP_LABEL_TEXT_SIZE,
                                  font_size=ELEMENT_LABEL_FONT_SIZE)
        server_ip_label.top = server_port_label.top
        server_ip_label.x = server_port_label.right + TAB_ELEMENT_PADDING
        network_tab_content.add_widget(server_ip_label)

        # Server startup input
        server_port_input = NSTextInput(text='', 
                                        width=PORT_INPUT_WIDTH,
                                        height=TEXT_INPUT_HEIGHT,
                                        multiline=False)
        server_port_input.bind(focus=self.select_text_input)
        server_port_input.original_text = SERVER_PORT_TEXT
        server_port_input.x = server_port_label.x
        server_port_input.top = server_port_label.y - TAB_ELEMENT_PADDING
        network_tab_content.add_widget(server_port_input)
        self.server_port_input = server_port_input

        server_ip_input = NSTextInput(text='',
                                      width=IP_INPUT_WIDTH,
                                      height=TEXT_INPUT_HEIGHT,
                                      multiline=False)
        server_ip_input.bind(focus=self.select_text_input)
        server_ip_input.original_text=SERVER_IP_TEXT
        server_ip_input.x = server_ip_label.x
        server_ip_input.top = server_port_input.top
        network_tab_content.add_widget(server_ip_input)
        self.server_ip_input = server_ip_input

        server_start_button = NSDisableButton(text='Start server', 
                                     width=NETWORK_BUTTON_WIDTH,
                                     height=NETWORK_BUTTON_HEIGHT,
                                     text_size=NETWORK_BUTTON_TEXT_SIZE,
                                     font_size=NETWORK_BUTTON_FONT_SIZE,
                                     halign='center', valign='middle')
        server_start_button.bind(on_press=self.start_server)
        server_start_button.center_x = tabs.center_x
        server_start_button.top = server_ip_input.y - TAB_ELEMENT_PADDING
        network_tab_content.add_widget(server_start_button)
        self.server_start_button = server_start_button

        join_server_button = NSDisableButton(text='Join server',
                                    width=NETWORK_BUTTON_WIDTH,
                                    height=NETWORK_BUTTON_HEIGHT,
                                    text_size=NETWORK_BUTTON_TEXT_SIZE,
                                    font_size=NETWORK_BUTTON_FONT_SIZE,
                                    halign='center', valign='middle')
        join_server_button.bind(on_press=self.ask_join_server)
        join_server_button.x = server_start_button.x
        join_server_button.top = server_start_button.y - TAB_ELEMENT_PADDING
        network_tab_content.add_widget(join_server_button)
        self.join_server_button = join_server_button

        end_connection_button = NSDisableButton(text='End connection',
                                       width=NETWORK_BUTTON_WIDTH,
                                       height=NETWORK_BUTTON_HEIGHT,
                                       text_size=NETWORK_BUTTON_TEXT_SIZE,
                                       font_size=NETWORK_BUTTON_FONT_SIZE,
                                       halign='center', valign='middle')
        end_connection_button.bind(on_press=self.ask_end_connection)
        end_connection_button.disable()
        end_connection_button.x = server_start_button.x
        end_connection_button.top = join_server_button.y - TAB_ELEMENT_PADDING
        network_tab_content.add_widget(end_connection_button)
        self.end_connection_button = end_connection_button
        
        # System options tab
        system_tab = TabbedPanelHeader()
        system_tab.background_normal = \
            os.path.join(IMAGE_DIR, "media-floppy.png")
        system_tab.background_down = \
            os.path.join(IMAGE_DIR, "media-floppy-down.png")
        tabs.add_widget(system_tab)

        system_tab_content = Widget(width=TABS_WIDTH, height=TAB_CONTENT_HEIGHT)
        system_tab.content = system_tab_content

        NUM_SYSTEM_BUTTONS = 3
        SYSTEM_BUTTON_PADDING = 20
        SYSTEM_BUTTON_FONT_SIZE = 24
        SYSTEM_BUTTON_WIDTH = TABS_WIDTH - SYSTEM_BUTTON_PADDING * 2
        SYSTEM_BUTTON_HEIGHT = (TAB_CONTENT_HEIGHT - SYSTEM_BUTTON_PADDING *
                               (NUM_SYSTEM_BUTTONS + 1)) / NUM_SYSTEM_BUTTONS
        SYSTEM_BUTTON_TEXT_SIZE = [SYSTEM_BUTTON_WIDTH, SYSTEM_BUTTON_HEIGHT]

        # Load button
        load_button = NSDisableButton(text='Load', width=SYSTEM_BUTTON_WIDTH,
                                      height=SYSTEM_BUTTON_HEIGHT,
                                      text_size=SYSTEM_BUTTON_TEXT_SIZE,
                                      font_size=SYSTEM_BUTTON_FONT_SIZE,
                                      halign='center', valign='middle')
        load_button.bind(on_press=self.load_file)
        load_button.center_x = tabs.center_x
        load_button.top = TAB_CONTENT_TOP - SYSTEM_BUTTON_PADDING
        system_tab_content.add_widget(load_button)
        self.load_button = load_button

        # Save button
        save_button = NSDisableButton(text='Save', width=SYSTEM_BUTTON_WIDTH,
                                      height=SYSTEM_BUTTON_HEIGHT,
                                      text_size=SYSTEM_BUTTON_TEXT_SIZE,
                                      font_size=SYSTEM_BUTTON_FONT_SIZE,
                                      halign='center', valign='middle')
        save_button.bind(on_press=self.save_file)
        save_button.center_x = tabs.center_x
        save_button.top = load_button.y - SYSTEM_BUTTON_PADDING
        system_tab_content.add_widget(save_button)        

        # Quit button
        quit_button = NSDisableButton(text='Quit', width=SYSTEM_BUTTON_WIDTH,
                                      height=SYSTEM_BUTTON_HEIGHT,
                                      text_size=SYSTEM_BUTTON_TEXT_SIZE, 
                                      font_size=SYSTEM_BUTTON_FONT_SIZE,
                                      halign='center', valign='middle')
        quit_button.bind(on_press=self.request_exit)
        quit_button.center_x = tabs.center_x
        quit_button.top = save_button.y - SYSTEM_BUTTON_PADDING
        system_tab_content.add_widget(quit_button)        

        # APPLICATION TITLE
        TITLE_WIDTH = TABS_WIDTH
        TITLE_HEIGHT = 50
        TITLE_TEXT_SIZE = [TITLE_WIDTH, TITLE_HEIGHT]
        TITLE_FONT_SIZE = 30
        SUBTITLE_WIDTH = TITLE_WIDTH
        SUBTITLE_HEIGHT = 30
        SUBTITLE_TEXT_SIZE = [SUBTITLE_WIDTH, SUBTITLE_HEIGHT]
        SUBTITLE_FONT_SIZE = 15
        TITLE_X = TABS_X

        title_label = Label(text='NetSeq', width=TITLE_WIDTH,
                            height=TITLE_HEIGHT, halign='center', 
                            valign='middle', text_size=TITLE_TEXT_SIZE,
                            font_size=TITLE_FONT_SIZE)
        title_label.top = PLAYBACK_TOP
        title_label.x = TITLE_X
        self.main_layout.add_widget(title_label)

        subtitle_label = Label(text='Music with Friends',
                               width=SUBTITLE_WIDTH,
                               height=SUBTITLE_HEIGHT,  
                               text_size=SUBTITLE_TEXT_SIZE,
                               font_size=SUBTITLE_FONT_SIZE,
                               halign='center', valign='middle')
        subtitle_label.top = title_label.y
        subtitle_label.x = TITLE_X
        self.main_layout.add_widget(subtitle_label)

        # Finishing steps
        self.set_color(self.track_id)
        self.reload_row_labels()
Beispiel #8
0
	def build(self):
	#*******ROOTWIDGET*******
		layout = GridLayout(rows=2)		
	#*******SUB-WIDGETS*******
		layoutTop = GridLayout(cols=3,rows=1)#SUB-WIDGET-1
		layoutTop.size_hint = (1, 0.1)
		layoutMid = FloatLayout()#SUB-WIDGET-2
		layoutMid.size_hint = (1, 1)
		
	#*******CONTENT-OF-SUB-WIDGET-1*******	
		menubtn = Button(text='Menu')
		menubtn.size_hint = (0.1, 0.1)
		head = Label(text='PRO-FORMA',size_hint_y = None,size_hint_x=None, width=200)
		head.size_hint = (0.8, 0.1)
		backbtn = Button(text='Drop')
		backbtn.size_hint = (0.1, 0.1)
		#dropbtn = Button()
	#*******CONTENT-OF-SUB-WIDGET-2*******
		tp_panel = TabbedPanel()
		tp_panel.default_tab_text = "Global News"	
		
		layoutnews = GridLayout(rows=2)
		upperlayout = GridLayout(cols=3, pos_hint ={'center_x': .5, 'center_y': .5},row_force_default=True, row_default_height=40, size_hint_y=None, height = 50, size_hint_x=1)
		lowerlayout = GridLayout(row=1)
		
		upperlayout.add_widget(Button(text='S', size_hint=(0.1, None)))
		upperlayout.add_widget(TextInput(text='search', size_hint=(0.8, None), focus=True, multiline=False))
		upperlayout.add_widget(Button(text='settings', size_hint=(0.1, None)))
		
		lowerlayout.add_widget(Label())
		
		layoutnews.add_widget(upperlayout)
		layoutnews.add_widget(lowerlayout)
		tp_panel.default_tab_content = layoutnews
		
		#*******TAB1*******	
		th_tab1 = TabbedPanelHeader(text = 'Pro-Forma')
		#*******SCROLLABILITY-WIDGET*******
		scroll = ScrollView(size_hint=(1, None), size=(800, 1000))
		
		mainlayout = GridLayout(cols = 1, spacing = 10, size_hint_y=None, size_hint_x=1)
		mainlayout.bind(minimum_height=mainlayout.setter('height'))
		#*******LAYOUT-FOR-PROPERTY-INFORMATION*******
		layouttab1 = GridLayout(cols=2,rows=6, pos_hint ={'center_x': .5, 'center_y': .5},row_force_default=True, row_default_height=40, size_hint_y=None, height = 250, size_hint_x=1)
		#*******LAYOUT-FOR-UNIT-MIX*******
		layoutmix = GridLayout(cols=4, pos_hint ={'center_x': .5, 'center_y': .5},row_force_default=True, row_default_height=40,size_hint_y=None, height = 80)
		#*******LAYOUT-FOR-EXPENSES*******
		layoutexpense = GridLayout(cols=2, pos_hint ={'center_x': .5, 'center_y': .5},row_force_default=True, row_default_height=40, size_hint_y=None, height = 960)
		#*******LAYOUT-FOR-ACCOUNTS*******
		layoutacc = GridLayout(cols=2, pos_hint ={'center_x': .5, 'center_y': .5},row_force_default=True, row_default_height=40,size_hint_y=None, height = 240)
		#*******CONTENT1*****
		mainlayout.add_widget(Label(text='Property Information',size_hint=(None, 1)))
		#*******CONTENT2*******
		layouttab1.add_widget(Label(text= 'Property Name', font_size=15, size_hint=(0.4, None)))
		layouttab1.add_widget(TextInput(text='input', font_size=15, halign ='left', valign='middle',size_hint=(0.6, None),multiline=False, focus=True))
		layouttab1.add_widget(Label(text= 'Property Address', font_size=15, size_hint=(0.4, None)))
		layouttab1.add_widget(TextInput(text='input', font_size=15, halign ='left', valign='middle',size_hint=(0.6, None),multiline=False, focus=True))
		layouttab1.add_widget(Label(text= 'Town/City', font_size=15, size_hint=(0.4, None)))
		layouttab1.add_widget(TextInput(text='input', font_size=15, halign ='left', valign='middle',size_hint=(0.6, None),multiline=False, focus=True))
		layouttab1.add_widget(Label(text= 'Asking Price', font_size=15, size_hint=(0.4, None)))
		layouttab1.add_widget(TextInput(text='input', font_size=15, halign ='left', valign='middle',size_hint=(0.6, None),multiline=False, focus=True))
		layouttab1.add_widget(Label(text= 'Total Units', font_size=15, size_hint=(0.4, None)))
		layouttab1.add_widget(TextInput(text='input', font_size=15, halign ='left', valign='middle',size_hint=(0.6, None),multiline=False, focus=True))
		layouttab1.add_widget(Label(text= 'Square Footage', font_size=15, size_hint=(0.4, None)))
		layouttab1.add_widget(TextInput(text='input', font_size=15, halign ='left', valign='middle',size_hint=(0.6, None),multiline=False, focus=True))
		mainlayout.add_widget(layouttab1)
		#*******CONTENT3*******
		mainlayout.add_widget(Label(text='Unit Mix',size_hint_x=None, width=200, size_hint_y=None, height=50))
		#*******CONTENT4*******
		layoutmix.add_widget(Label(text='# of Units'))
		layoutmix.add_widget(Label(text='Unit Type'))
		layoutmix.add_widget(Label(text='SquareFeet'))
		layoutmix.add_widget(Label(text='Monthly Rent'))
		layoutmix.add_widget(TextInput(text='Input', font_size=15))
		layoutmix.add_widget(TextInput(text='Input', font_size=15))
		layoutmix.add_widget(TextInput(text='Input', font_size=15))
		layoutmix.add_widget(TextInput(text='Input', font_size=15))
		mainlayout.add_widget(layoutmix)
		#*******CONTENT7*******
		mainlayout.add_widget(Label(text='Accounts',size_hint_x=None, width=200, size_hint_y=None, height=50))
		#*******CONTENT7*******
		layoutacc.add_widget(Label(text='Purchase Price'))
		layoutacc.add_widget(TextInput(text='Input'))
		layoutacc.add_widget(Label(text='Deposit'))
		layoutacc.add_widget(TextInput(text='Input'))
		layoutacc.add_widget(Label(text='Loan Amount'))
		layoutacc.add_widget(TextInput(text='Input'))
		layoutacc.add_widget(Label(text='Annual Interest'))
		layoutacc.add_widget(TextInput(text='Input'))
		layoutacc.add_widget(Label(text='Period'))
		layoutacc.add_widget(TextInput(text='Input'))
		layoutacc.add_widget(Label(text='Total Cash Outlay'))
		layoutacc.add_widget(TextInput(text='Input'))
		mainlayout.add_widget(layoutacc)
		#*******CONTENT5*******
		mainlayout.add_widget(Label(text='Expenses',size_hint_x=None, width=200, size_hint_y=None, height=50))
		#*******CONTENT6*******
		layoutexpense.add_widget(Label(text='Accounting'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15,))
		layoutexpense.add_widget(Label(text='Advertising'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='Bank Charges'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='Electricity'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='Gas'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='Security'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='All insurance'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='Permits and fees'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='Maintenance'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='Trash Pick-up'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		layoutexpense.add_widget(Label(text='All other'))
		layoutexpense.add_widget(TextInput(text='Input', font_size=15))
		mainlayout.add_widget(layoutexpense)
		#*******CALLING-MAINLAYOUT-IN-TAB1*******
		scroll.add_widget(mainlayout)
		th_tab1.content = scroll
		tp_panel.add_widget(th_tab1)
		
		#___*******TAB3*******___#
		th_tab3 = TabbedPanelHeader(text = 'Saved Reports')
		tp_panel.add_widget(th_tab3)
	
	#*******ADDING-CONTENTS-OF-SUB-WIDGETS*******
		layoutTop.add_widget(menubtn)
		layoutTop.add_widget(head)
		layoutTop.add_widget(backbtn)
		layoutMid.add_widget(tp_panel)
	#*******ADDING-CONTENTS-OF-ROOT-WIDGET*******
		layout.add_widget(layoutTop)
		layout.add_widget(layoutMid)
	#*******CALLING-THE-ROOT-WIDGET*******	
		return layout
Beispiel #9
0
    def __init__(self):
        super(MyWidget, self).__init__()
        
        self.cos_table = CosTable([(0,0), (100,1), (1000,.25), (8191,0)])
        self.osc_out = Osc(table=self.cos_table, freq=220)

        # For each element of the GUI, make sure to
        # 1. Create a unique reference attached to this object for
        #   future manipulation. e.g. self.main_box = main_box after you've
        #   created a BoxLayout called main_box

        # Interesting things about Kivy UI programming:
        # 1. y starts counting from bottom left
        # 2. set size_hint to '[None, None]' for all new widgets if defining
        #       the size and manually

        # MAIN LAYOUT
        main_layout = FloatLayout(size=[800,600], orientation='horizontal')
        self.main_layout = main_layout
        self.add_widget(main_layout)

        # TABS WITH GAME CONTROL
        # Tabbed panel for music, settings, network
        # Y-position of tabbed panel depends on tab height!
        tabs = TabbedPanel(tab_width=50, size=[160, 480], pos=[0, 120],
                           size_hint=(None, None))
        self.tabs = tabs
        main_layout.add_widget(tabs)

        # Music tab
        music_button = Button(text="Music things")
        tabs.default_tab_content = music_button
        tabs.default_tab.text = "Music"

        # Network tab
        network_tab = TabbedPanelHeader(text="Net")
        tabs.add_widget(network_tab)
        network_layout = BoxLayout(orientation="vertical", padding=10)
        server_button = Button(text="Start server")
        ip_label = Label(text="Your IP is\n123.234.456.789");
        client_label = Label(text="Connect to server: ");
        server_ip_input = TextInput(text="Enter server IP")
        network_layout.add_widget(server_button)
        network_layout.add_widget(ip_label)
        network_layout.add_widget(client_label)
        network_layout.add_widget(server_ip_input)
        network_tab.content = network_layout

        # Global tab
        global_tab = TabbedPanelHeader(text="Global")
        tabs.add_widget(global_tab)
        global_button = Button(text="Global things")
        global_tab.content = global_button
        # END TABS

        # RIGHT-SIDE LAYOUT: NOTES GRID AND PLAYBACK UI
        music_layout = FloatLayout(size=[640, 600], pos=[161, 0],
                                   size_hint=[None, None])
        self.music_layout = music_layout
        main_layout.add_widget(music_layout)

        # NOTES GRID
        # Right now Kivy isn't really paying attention to button size and
        # padding. Later on, we'll fix this with a FloatLayout
        note_rows = note_cols = 8
        padding_between = 5
        note_grid = GridLayout(size=[640, 480], pos=[161, 121], 
                               size_hint=[None, None], rows=note_rows, 
                               cols=note_cols, padding=padding_between)
        music_layout.add_widget(note_grid)

        edge_padding = 30

        grid_start_x = note_grid.x + edge_padding
        grid_end_x = note_grid.right - edge_padding
        grid_start_y = note_grid.y + edge_padding
        grid_end_y = note_grid.top - edge_padding
        notes_matrix = []

        note_width = grid_end_x - grid_start_x - padding_between * \
                    (note_rows - 1)
        note_height = grid_end_y - grid_start_y - padding_between * \
                      (note_rows - 1)

        # Adding a rectangle to test playback indicator
        self.playback_indicator = Rectangle(pos=[161,121], size=[75, 480])
        self.playback_canvas = Canvas()
        playback_widget = Widget()
        self.playback_canvas.add(self.playback_indicator)
        self.playback_canvas.opacity = .5    
        playback_widget.canvas = self.playback_canvas
        music_layout.add_widget(playback_widget)


        for row in range(0, note_rows):
            for col in range(0, note_cols):
                new_id = str(row) + "," + str(col)
                new_button = ToggleButton(text=new_id, id=new_id, 
                                          width=note_width, 
                                          height=note_height)
                active_color = (1, 0, 0, 1)
                new_button.background_color = active_color
                new_button.bind(on_press=self.play_note)
                note_grid.add_widget(new_button)
        
        # PLAYBACK BUTTONS
        playback = Button(text="For playback", size=[640, 120], 
                          size_hint=[None, None], pos=[161, 0])
        music_layout.add_widget(playback)