Пример #1
0
    def __init__(self, title, field_content, record_specs,field_specs,show_refs,initial_media_dir,
                        pp_home_dir,pp_profile_dir,initial_tab,callback):

        self.callback=callback
        self.frame_width=800   # frame for 2 columns
        self.col_width=400     # width of a column
        self.field_width= 200  # width of data field, label must fit in col_width-field_width- 15
        self.fields_height=300
        self.rows_in_col=15
        self.tab_height=100
        self.okcancel_height=100


        super(WebEditItem, self).__init__('<b>'+title+'</b>','',width=self.frame_width+700,height=self.fields_height+self.tab_height+self.okcancel_height,
                                          confirm_name='OK',cancel_name='Cancel')

        self.field_content = field_content   # dictionary - the track parameters to be edited and returned
                                                                 # key is field name e.g. omx-window
        self.record_specs= record_specs  # list of field names and seps/tabs in the order that they appear
        self.field_specs=field_specs          # dictionary of specs referenced by field name
        
        self.show_refs=show_refs            # used for droppdown of list of shows
        self.show_refs.append('')
        
        self.initial_media_dir=initial_media_dir
        self.pp_home_dir=pp_home_dir
        self.pp_profile_dir=pp_profile_dir
        self.initial_tab=initial_tab


        # create a Tabbed Editor
        self.tabview= TabView(self.frame_width,self.fields_height,30)


        # tabs are created dynamically from pp_definitions.py
        # get fields for this record using the record type in the loaded record
        record_fields=self.record_specs[self.field_content['type']]

        # init results of building the form
        self.tab_row=1 # row on form
        self.field_objs=[]  # list of field objects in record fields order, not for sep or tab
        self.field_index=0 # index to self.field_objs incremented after each field except tab and sep
                                        # can be used as an index to self.field_objs and self.button_objs
        self.button_objs=[]   # list of button objects in record field order , not for sep or tab =None for non-buttons
        
        self.col_row=0
        self.current_col=None
        self.col_1=None
        # populate the dialog box using the record fields to determine the order
        for field in record_fields:
            # get list of values where required
            values=[]
            if self.field_specs[field]['shape']in("option-menu",'spinbox'):
                # print 'should be field name', field
                # print 'should be shape',self.field_specs[field]['shape']
                if field in ('sub-show','start-show'):
                    values=self.show_refs                    
                else:
                    values=self.field_specs[field]['values']
            else:
                values=[]
            # make the entry
            obj,button=self.make_entry(field,self.field_specs[field],values)
            if obj is not  None:
                self.field_objs.append(obj)
                self.button_objs.append(button)
                self.field_index +=1

        #construct the tabview
        self.tabview.construct_tabview()
        
        # frame for tabbed editor
        self.root_frame = gui.HBox(width=self.tabview.get_width() + 100, height=self.fields_height+self.tab_height) #1
        self.root_frame.append(self.tabview,key='switch')
        self.append_field(self.root_frame,'cont')

        #adjust width of dialog box
        self.style['width']=gui.to_pix(self.tabview.get_width() + 100)
         
        return None
Пример #2
0
class WebEditItem(AdaptableDialog):
    
    def __init__(self, title, field_content, record_specs,field_specs,show_refs,initial_media_dir,
                        pp_home_dir,pp_profile_dir,initial_tab,callback):

        self.callback=callback
        self.frame_width=800   # frame for 2 columns
        self.col_width=400     # width of a column
        self.field_width= 200  # width of data field, label must fit in col_width-field_width- 15
        self.fields_height=300
        self.rows_in_col=15
        self.tab_height=100
        self.okcancel_height=100


        super(WebEditItem, self).__init__('<b>'+title+'</b>','',width=self.frame_width+700,height=self.fields_height+self.tab_height+self.okcancel_height,
                                          confirm_name='OK',cancel_name='Cancel')

        self.field_content = field_content   # dictionary - the track parameters to be edited and returned
                                                                 # key is field name e.g. omx-window
        self.record_specs= record_specs  # list of field names and seps/tabs in the order that they appear
        self.field_specs=field_specs          # dictionary of specs referenced by field name
        
        self.show_refs=show_refs            # used for droppdown of list of shows
        self.show_refs.append('')
        
        self.initial_media_dir=initial_media_dir
        self.pp_home_dir=pp_home_dir
        self.pp_profile_dir=pp_profile_dir
        self.initial_tab=initial_tab


        # create a Tabbed Editor
        self.tabview= TabView(self.frame_width,self.fields_height,30)


        # tabs are created dynamically from pp_definitions.py
        # get fields for this record using the record type in the loaded record
        record_fields=self.record_specs[self.field_content['type']]

        # init results of building the form
        self.tab_row=1 # row on form
        self.field_objs=[]  # list of field objects in record fields order, not for sep or tab
        self.field_index=0 # index to self.field_objs incremented after each field except tab and sep
                                        # can be used as an index to self.field_objs and self.button_objs
        self.button_objs=[]   # list of button objects in record field order , not for sep or tab =None for non-buttons
        
        self.col_row=0
        self.current_col=None
        self.col_1=None
        # populate the dialog box using the record fields to determine the order
        for field in record_fields:
            # get list of values where required
            values=[]
            if self.field_specs[field]['shape']in("option-menu",'spinbox'):
                # print 'should be field name', field
                # print 'should be shape',self.field_specs[field]['shape']
                if field in ('sub-show','start-show'):
                    values=self.show_refs                    
                else:
                    values=self.field_specs[field]['values']
            else:
                values=[]
            # make the entry
            obj,button=self.make_entry(field,self.field_specs[field],values)
            if obj is not  None:
                self.field_objs.append(obj)
                self.button_objs.append(button)
                self.field_index +=1

        #construct the tabview
        self.tabview.construct_tabview()
        
        # frame for tabbed editor
        self.root_frame = gui.HBox(width=self.tabview.get_width() + 100, height=self.fields_height+self.tab_height) #1
        self.root_frame.append(self.tabview,key='switch')
        self.append_field(self.root_frame,'cont')

        #adjust width of dialog box
        self.style['width']=gui.to_pix(self.tabview.get_width() + 100)
         
        return None

    def show_tab(self,key):
        self.tabview.show(key)      


    # create an entry in an editor panel
    def make_entry(self,field,field_spec,values):
        # print 'make entry',self.field_index,field,field_spec
        if self.col_row >= self.rows_in_col:
            self.current_col=self.col_1
        
        # print 'make entry',self.col_row, self.current_col        
        
        if field_spec['shape']=='tab':
            width=len(field_spec['text'])*8+4
            self.current_tab = self.tabview.add_tab(width,field_spec['name'],field_spec['text'])
            # print 'make tab', field_spec['name']
            self.current_tab.set_layout_orientation(gui.Widget.LAYOUT_HORIZONTAL)
            self.col_0=gui.Widget(width=self.frame_width/2) #0
            self.col_0.set_layout_orientation(gui.Widget.LAYOUT_VERTICAL)
            self.col_1=gui.Widget(width=self.frame_width/2) #0
            self.col_1.set_layout_orientation(gui.Widget.LAYOUT_VERTICAL)

            self.current_tab.append(self.col_0,key='col_0')
            self.current_tab.append(self.col_1,key='col_1')

            self.current_col=self.col_0
            self.col_row=1
            # print '\nNEW TAB',self.col_row
            self.tab_row=1
            return None,None
        
        elif field_spec['shape']=='sep':
            self.current_col.append(gui.Label('',width=self.field_width,height=10))
            self.tab_row+=1
            self.col_row+=1
            return None,None

        else:

            # print 'replace param in make entry',field
            # print 'content', field, self.field_content[field]
            # is it in the field content dictionary
            if not field in self.field_content:
                print "Value for field not found in opened file: " + field
                return None,None
            else:

                # bodge  - assumes only type is read only
                if field_spec['read-only']=='yes':
                    obj=(gui.Label(self.field_content[field],width=self.field_width,height=20))
                    obj.style['font-weight']='bold'

                
                elif field_spec['shape']in ('entry','browse','font','colour'):
                    obj=gui.TextInput(single_line=True,width=self.field_width,height=20)
                    obj.set_value(self.field_content[field])
                    
                elif field_spec['shape']=='text':
                    obj=gui.TextInput(width=self.field_width,height=110,single_line=False)
                    obj.set_value(self.field_content[field])
                    # extra lines
                    self.col_row+=5

                elif field_spec['shape']=='spinbox':
                    print 'spinbox not implemented'
                    return None,None

                    
                elif field_spec['shape']=='option-menu':
                    obj=gui.DropDown(width=self.field_width,height=25)
                    for key, value in enumerate(values):
                        item=gui.DropDownItem(value,width=self.field_width,height=25)
                        obj.append(item, key=key)
                    content=self.field_content[field]
                    if self.field_content[field] not in values:
                        obj.style['color'] = 'red'
                        content=values[0]
                    obj.set_value(content)
                    # print self.field_content[field],obj.get_value(),values


                else:
                    print"Uknown shape for: " + field
                    return None,None
                
                # create buttons where required
                if field_spec['shape']=='browse':
                    button=self.browse_button(20,20,'','browse_button',self.field_index,field_spec['text'])
                    
                elif field_spec['shape']=='colour':
                    if ColourMap().exists(self.field_content[field]) is True:
                        colour=ColourMap().lookup(self.field_content[field])
                    else:
                        colour=self.field_content[field]
                    button= gui.ColorPicker(colour,width=20, height=20)
                    button.set_on_change_listener(self.color_picker_changed)
                    
                else:
                    button=None

                append_with_label(self.current_col,field_spec['text'],obj,button,width=self.col_width)
                self.tab_row+=1
                self.col_row+=1
                return obj,button

    def confirm_dialog(self):
        # OK button is pressed so update the field values in the profile
        # self.field_content - dictionary - the track parameters to be edited and returned
        # key is field name e.g. omx-window
                                                                     
        # get list of fields in the record in the same order as the form was generated
        record_fields=self.record_specs[self.field_content['type']]
        
        field_index=0 # index to self.field_objs - not incremented for tab and sep

        for field in record_fields:
            # get the details of this field
            field_spec=self.field_specs[field]
            #print  'reading row',field_index,field_spec['shape']
            
            # and get the value
            if field_spec['shape']not in ('sep','tab'):

                #bodge for type which is a label
                if field_spec['read-only']=='yes':
                    self.field_content[field]=self.field_objs[field_index].get_text().strip()

                # get result of button from button and also put it in field
                elif field_spec['shape'] in ('colour'):
                    # button is actually a color picker
                    self.field_content[field]=self.button_objs[field_index].get_value().strip()
                    self.field_objs[field_index].set_value(self.field_content[field])

                else:
                    self.field_content[field]=str(self.field_objs[field_index].get_value()).strip()
                    # print field_spec['shape'],field_spec['text']+':  ',self.field_content[field]

                    
                # print field_spec['shape'],field_spec['text']+':  ',self.field_content[field]    
                field_index +=1
        # print 'edit item hide'
        self.hide()
        self.callback()



# browse button

    def browse_button(self,w,h,label,base_name,field_index,title):
        # create a button that returns the key to on_click_listener
        bname=base_name+str(field_index)
        but=gui.Button(label,width=w,height=h)
        # f = lambda  _bname=field_index: self.open_fileselection_dialog( _bname)
        # fname='self.'+base_name+'_' + str(field_index)
        # setattr(self, fname, f)
        but.set_on_click_listener(self.open_fileselection_dialog,field_index,title)
        return but


    def open_fileselection_dialog(self,widget,browse_field_index,title):
        self.browse_field_index=browse_field_index
        self.file_dialog=FileSelectionDialog(title,'Select File',False, self.initial_media_dir,callback=self.on_fileselection_dialog_callback)
        self.file_dialog.show(self._base_app_instance)
    

    def on_fileselection_dialog_callback(self,flist):
        # a list() of filenames and folders is returned
        if len(flist)==0:
            OKDialog('Select File','nothing selected').show(self._base_app_instance)
            return
        file_path=os.path.normpath(flist[0])
        # print "file path ", file_path

        result=calculate_relative_path(file_path,self.pp_home_dir,self.pp_profile_dir)
        self.field_objs[self.browse_field_index].set_value(result)
        

        
# colour picker

    def color_picker_changed(self,widget,result):
        self.update_colour_fields()
        # print 'colour picked',result


    def update_colour_fields(self):
        # copy result of colour picker into the text field
        record_fields=self.record_specs[self.field_content['type']]
        field_index=0 # index to self.field_objs - not incremented for tab and sep
        for field in record_fields:
            field_spec=self.field_specs[field]
            if field_spec['shape']not in ('sep','tab'):
                if field_spec['shape'] in ('colour'):
                    self.field_objs[field_index].set_value(self.button_objs[field_index].get_value())
                field_index +=1
    def __init__(self, title, field_content, record_specs,field_specs,show_refs,initial_media_dir,
                        pp_home_dir,pp_profile_dir,initial_tab,callback):

        self.callback=callback
        self.frame_width=800   # frame for 2 columns
        self.col_width=400     # width of a column
        self.field_width= 200  # width of data field, label must fit in col_width-field_width- 15
        self.fields_height=300
        self.rows_in_col=15
        self.tab_height=100
        self.okcancel_height=100


        super(WebEditItem, self).__init__('<b>'+title+'</b>','',width=self.frame_width+700,height=self.fields_height+self.tab_height+self.okcancel_height,
                                          confirm_name='OK',cancel_name='Cancel')

        self.field_content = field_content   # dictionary - the track parameters to be edited and returned
                                                                 # key is field name e.g. omx-window
        self.record_specs= record_specs  # list of field names and seps/tabs in the order that they appear
        self.field_specs=field_specs          # dictionary of specs referenced by field name
        
        self.show_refs=show_refs            # used for droppdown of list of shows
        self.show_refs.append('')
        
        self.initial_media_dir=initial_media_dir
        self.pp_home_dir=pp_home_dir
        self.pp_profile_dir=pp_profile_dir
        self.initial_tab=initial_tab


        # create a Tabbed Editor
        self.tabview= TabView(self.frame_width,self.fields_height,30)


        # tabs are created dynamically from pp_definitions.py
        # get fields for this record using the record type in the loaded record
        record_fields=self.record_specs[self.field_content['type']]

        # init results of building the form
        self.tab_row=1 # row on form
        self.field_objs=[]  # list of field objects in record fields order, not for sep or tab
        self.field_index=0 # index to self.field_objs incremented after each field except tab and sep
                                        # can be used as an index to self.field_objs and self.button_objs
        self.button_objs=[]   # list of button objects in record field order , not for sep or tab =None for non-buttons
        
        self.col_row=0
        self.current_col=None
        self.col_1=None
        # populate the dialog box using the record fields to determine the order
        for field in record_fields:
            # get list of values where required
            values=[]
            if self.field_specs[field]['shape']in("option-menu",'spinbox'):
                # print 'should be field name', field
                # print 'should be shape',self.field_specs[field]['shape']
                if field in ('sub-show','start-show'):
                    values=self.show_refs                    
                else:
                    values=self.field_specs[field]['values']
            else:
                values=[]
            # make the entry
            obj,button=self.make_entry(field,self.field_specs[field],values)
            if obj is not  None:
                self.field_objs.append(obj)
                self.button_objs.append(button)
                self.field_index +=1

        #construct the tabview
        self.tabview.construct_tabview()
        
        # frame for tabbed editor
        self.root_frame = gui.HBox(width=self.tabview.get_width() + 100, height=self.fields_height+self.tab_height) #1
        self.root_frame.append(self.tabview,key='switch')
        self.append_field(self.root_frame,'cont')

        #adjust width of dialog box
        self.style['width']=gui.to_pix(self.tabview.get_width() + 100)
         
        return None
class WebEditItem(AdaptableDialog):
    
    def __init__(self, title, field_content, record_specs,field_specs,show_refs,initial_media_dir,
                        pp_home_dir,pp_profile_dir,initial_tab,callback):

        self.callback=callback
        self.frame_width=800   # frame for 2 columns
        self.col_width=400     # width of a column
        self.field_width= 200  # width of data field, label must fit in col_width-field_width- 15
        self.fields_height=300
        self.rows_in_col=15
        self.tab_height=100
        self.okcancel_height=100


        super(WebEditItem, self).__init__('<b>'+title+'</b>','',width=self.frame_width+700,height=self.fields_height+self.tab_height+self.okcancel_height,
                                          confirm_name='OK',cancel_name='Cancel')

        self.field_content = field_content   # dictionary - the track parameters to be edited and returned
                                                                 # key is field name e.g. omx-window
        self.record_specs= record_specs  # list of field names and seps/tabs in the order that they appear
        self.field_specs=field_specs          # dictionary of specs referenced by field name
        
        self.show_refs=show_refs            # used for droppdown of list of shows
        self.show_refs.append('')
        
        self.initial_media_dir=initial_media_dir
        self.pp_home_dir=pp_home_dir
        self.pp_profile_dir=pp_profile_dir
        self.initial_tab=initial_tab


        # create a Tabbed Editor
        self.tabview= TabView(self.frame_width,self.fields_height,30)


        # tabs are created dynamically from pp_definitions.py
        # get fields for this record using the record type in the loaded record
        record_fields=self.record_specs[self.field_content['type']]

        # init results of building the form
        self.tab_row=1 # row on form
        self.field_objs=[]  # list of field objects in record fields order, not for sep or tab
        self.field_index=0 # index to self.field_objs incremented after each field except tab and sep
                                        # can be used as an index to self.field_objs and self.button_objs
        self.button_objs=[]   # list of button objects in record field order , not for sep or tab =None for non-buttons
        
        self.col_row=0
        self.current_col=None
        self.col_1=None
        # populate the dialog box using the record fields to determine the order
        for field in record_fields:
            # get list of values where required
            values=[]
            if self.field_specs[field]['shape']in("option-menu",'spinbox'):
                # print 'should be field name', field
                # print 'should be shape',self.field_specs[field]['shape']
                if field in ('sub-show','start-show'):
                    values=self.show_refs                    
                else:
                    values=self.field_specs[field]['values']
            else:
                values=[]
            # make the entry
            obj,button=self.make_entry(field,self.field_specs[field],values)
            if obj is not  None:
                self.field_objs.append(obj)
                self.button_objs.append(button)
                self.field_index +=1

        #construct the tabview
        self.tabview.construct_tabview()
        
        # frame for tabbed editor
        self.root_frame = gui.HBox(width=self.tabview.get_width() + 100, height=self.fields_height+self.tab_height) #1
        self.root_frame.append(self.tabview,key='switch')
        self.append_field(self.root_frame,'cont')

        #adjust width of dialog box
        self.style['width']=gui.to_pix(self.tabview.get_width() + 100)
         
        return None

    def show_tab(self,key):
        self.tabview.show(key)      


    # create an entry in an editor panel
    def make_entry(self,field,field_spec,values):
        # print 'make entry',self.field_index,field,field_spec
        if self.col_row >= self.rows_in_col:
            self.current_col=self.col_1
        
        # print 'make entry',self.col_row, self.current_col        
        
        if field_spec['shape']=='tab':
            width=len(field_spec['text'])*8+4
            self.current_tab = self.tabview.add_tab(width,field_spec['name'],field_spec['text'])
            # print 'make tab', field_spec['name']
            self.current_tab.set_layout_orientation(gui.Widget.LAYOUT_HORIZONTAL)
            self.col_0=gui.Widget(width=self.frame_width/2) #0
            self.col_0.set_layout_orientation(gui.Widget.LAYOUT_VERTICAL)
            self.col_1=gui.Widget(width=self.frame_width/2) #0
            self.col_1.set_layout_orientation(gui.Widget.LAYOUT_VERTICAL)

            self.current_tab.append(self.col_0,key='col_0')
            self.current_tab.append(self.col_1,key='col_1')

            self.current_col=self.col_0
            self.col_row=1
            # print '\nNEW TAB',self.col_row
            self.tab_row=1
            return None,None
        
        elif field_spec['shape']=='sep':
            self.current_col.append(gui.Label('',width=self.field_width,height=10))
            self.tab_row+=1
            self.col_row+=1
            return None,None

        else:

            # print 'replace param in make entry',field
            # print 'content', field, self.field_content[field]
            # is it in the field content dictionary
            if not field in self.field_content:
                print "Value for field not found in opened file: " + field
                return None,None
            else:

                # bodge  - assumes only type is read only
                if field_spec['read-only']=='yes':
                    obj=(gui.Label(self.field_content[field],width=self.field_width,height=20))
                    obj.style['font-weight']='bold'

                
                elif field_spec['shape']in ('entry','browse','font','colour'):
                    obj=gui.TextInput(single_line=True,width=self.field_width,height=20)
                    obj.set_value(self.field_content[field])
                    
                elif field_spec['shape']=='text':
                    obj=gui.TextInput(width=self.field_width,height=110,single_line=False)
                    obj.set_value(self.field_content[field])
                    # extra lines
                    self.col_row+=5

                elif field_spec['shape']=='spinbox':
                    print 'spinbox not implemented'
                    return None,None

                    
                elif field_spec['shape']=='option-menu':
                    obj=gui.DropDown(width=self.field_width,height=25)
                    for key, value in enumerate(values):
                        item=gui.DropDownItem(value,width=self.field_width,height=25)
                        obj.append(item, key=key)
                    obj.set_value(self.field_content[field])

                else:
                    print"Uknown shape for: " + field
                    return None,None
                
                # create buttons where required
                if field_spec['shape']=='browse':
                    button=self.browse_button(20,20,'','browse_button',self.field_index,field_spec['text'])
                    
                elif field_spec['shape']=='colour':
                    if ColourMap().exists(self.field_content[field]) is True:
                        colour=ColourMap().lookup(self.field_content[field])
                    else:
                        colour=self.field_content[field]
                    button= gui.ColorPicker(colour,width=20, height=20)
                    button.set_on_change_listener(self.color_picker_changed)
                    
                else:
                    button=None

                append_with_label(self.current_col,field_spec['text'],obj,button,width=self.col_width)
                self.tab_row+=1
                self.col_row+=1
                return obj,button

    def confirm_dialog(self):
        # OK button is pressed so update the field values in the profile
        # self.field_content - dictionary - the track parameters to be edited and returned
        # key is field name e.g. omx-window
                                                                     
        # get list of fields in the record in the same order as the form was generated
        record_fields=self.record_specs[self.field_content['type']]
        
        field_index=0 # index to self.field_objs - not incremented for tab and sep

        for field in record_fields:
            # get the details of this field
            field_spec=self.field_specs[field]
            #print  'reading row',field_index,field_spec['shape']
            
            # and get the value
            if field_spec['shape']not in ('sep','tab'):

                #bodge for type which is a label
                if field_spec['read-only']=='yes':
                    self.field_content[field]=self.field_objs[field_index].get_text().strip()

                # get result of button from button and also put it in field
                elif field_spec['shape'] in ('colour'):
                    # button is actually a color picker
                    self.field_content[field]=self.button_objs[field_index].get_value().strip()
                    self.field_objs[field_index].set_value(self.field_content[field])

                else:
                    self.field_content[field]=str(self.field_objs[field_index].get_value()).strip()
                    
                # print field_spec['shape'],field_spec['text']+':  ',self.field_content[field]    
                field_index +=1
        # print 'edit item hide'
        self.hide()
        self.callback()



# browse button

    def browse_button(self,w,h,label,base_name,field_index,title):
        # create a button that returns the key to on_click_listener
        bname=base_name+str(field_index)
        but=gui.Button(label,width=w,height=h)
        # f = lambda  _bname=field_index: self.open_fileselection_dialog( _bname)
        # fname='self.'+base_name+'_' + str(field_index)
        # setattr(self, fname, f)
        but.set_on_click_listener(self.open_fileselection_dialog,field_index,title)
        return but


    def open_fileselection_dialog(self,widget,browse_field_index,title):
        self.browse_field_index=browse_field_index
        self.file_dialog=FileSelectionDialog(title,'Select File',False, self.initial_media_dir,callback=self.on_fileselection_dialog_callback)
        self.file_dialog.show(self._base_app_instance)
    

    def on_fileselection_dialog_callback(self,flist):
        # a list() of filenames and folders is returned
        if len(flist)==0:
            OKDialog('Select File','nothing selected').show(self._base_app_instance)
            return
        file_path=os.path.normpath(flist[0])
        # print "file path ", file_path

        result=calculate_relative_path(file_path,self.pp_home_dir,self.pp_profile_dir)
        self.field_objs[self.browse_field_index].set_value(result)
        

        
# colour picker

    def color_picker_changed(self,widget,result):
        self.update_colour_fields()
        # print 'colour picked',result


    def update_colour_fields(self):
        # copy result of colour picker into the text field
        record_fields=self.record_specs[self.field_content['type']]
        field_index=0 # index to self.field_objs - not incremented for tab and sep
        for field in record_fields:
            field_spec=self.field_specs[field]
            if field_spec['shape']not in ('sep','tab'):
                if field_spec['shape'] in ('colour'):
                    self.field_objs[field_index].set_value(self.button_objs[field_index].get_value())
                field_index +=1
Пример #5
0
    def __init__(self, title, field_content, record_specs,field_specs,show_refs,initial_media_dir,
                        pp_home_dir,initial_tab,callback):

        self.callback=callback
        self.frame_width=450
        self.frame_height=400
        self.field_width= 250
        self.ffn_width=400
        self.ffn_height=300

        super(WebEditItem, self).__init__('<b>'+title+'</b>','',width=self.ffn_width+700,height=600,autohide_ok=False)

        self.field_content = field_content   # dictionary - the track parameters to be edited and returned
                                                                 # key is field name e.g. omx-window
        self.record_specs= record_specs  # list of field names and seps/tabs in the order that they appear
        self.field_specs=field_specs          # dictionary of specs referenced by field name
        
        self.show_refs=show_refs            # used for droppdown of list of shows
        self.show_refs.append('')
        
        self.initial_media_dir=initial_media_dir
        self.pp_home_dir=pp_home_dir
        self.initial_tab=initial_tab

        # Create a File Folder Navigator in a frame
        self.ffn = gui.FileFolderNavigator(False,self.initial_media_dir,True,False)#width=self.ffn_width, height=self.ffn_height

        # with some buttons
        self.ffn_select=gui.Button('Select',width=100,height=30)
        self.ffn_cancel=gui.Button('Cancel',width=100,height=30)
        self.ffn_select.set_on_click_listener(self,'on_fileselection_dialog_select')
        self.ffn_cancel.set_on_click_listener(self,'on_fileselection_dialog_cancel')
        self.ffn_button_frame=gui.HBox(width=self.ffn_width+60,height=30)
        self.ffn_button_frame.append(self.ffn_cancel)
        self.ffn_button_frame.append(self.ffn_select)

        # and error label for ffn
        self.ffn_error=gui.Label('',width=self.ffn_width,height=20)

        # frame for ffn and buttons
        self.ffn_frame=gui.VBox(width=self.ffn_width+60, height=self.ffn_height+90) #10
        self.ffn_frame.append(self.ffn,key='ffn')
        self.ffn_frame.append(self.ffn_error,key='ffn_error')
        self.ffn_frame.append(self.ffn_button_frame,key='ffn_buttons')

  

        # create a Tabbed Editor
        self.tabview= TabView(self.frame_width,self.frame_height,30)


        # tabs are created dynamically from pp_definitions.py
        # get fields for this record using the record type in the loaded record
        record_fields=self.record_specs[self.field_content['type']]

        # init results of building the form
        self.tab_row=1 # row on form
        self.field_objs=[]  # list of field objects in record fields order, not for sep or tab
        self.field_index=0 # index to self.field_objs incremented after each field except tab and sep
                                        # can be used as an index to self.field_objs and self.button_objs
        self.button_objs=[]   # list of button objects in record field order , not for sep or tab =None for non-buttons
        
        # populate the dialog box using the record fields to determine the order
        for field in record_fields:
            # get list of values where required
            values=[]
            if self.field_specs[field]['shape']in("option-menu",'spinbox'):
                # print 'should be field name', field
                # print 'should be shape',self.field_specs[field]['shape']
                if field in ('sub-show','start-show'):
                    values=self.show_refs                    
                else:
                    values=self.field_specs[field]['values']
            else:
                values=[]
            # make the entry
            obj,button=self.make_entry(field,self.field_specs[field],values)
            if obj is not  None:
                self.field_objs.append(obj)
                self.button_objs.append(button)
                self.field_index +=1

        #construct the tabview
        self.tabview.construct_tabview()
        
        # frame for file navigator and tabbed editor
        # conent of frame is switched between ffn and tabview
        self.root = gui.HBox(width=self.tabview.get_width() + 100, height=self.frame_height+ 100) #1
        self.root.append(self.tabview,key='switch')
        self.add_field('cont',self.root)

        #adjust width of diaolg box
        self.style['width']=gui.to_pix(self.tabview.get_width() + 200)
        
        self.set_on_confirm_dialog_listener(self,'confirm')      
        return None
Пример #6
0
class WebEditItem(gui.GenericDialog):
    
    def __init__(self, title, field_content, record_specs,field_specs,show_refs,initial_media_dir,
                        pp_home_dir,initial_tab,callback):

        self.callback=callback
        self.frame_width=450
        self.frame_height=400
        self.field_width= 250
        self.ffn_width=400
        self.ffn_height=300

        super(WebEditItem, self).__init__('<b>'+title+'</b>','',width=self.ffn_width+700,height=600,autohide_ok=False)

        self.field_content = field_content   # dictionary - the track parameters to be edited and returned
                                                                 # key is field name e.g. omx-window
        self.record_specs= record_specs  # list of field names and seps/tabs in the order that they appear
        self.field_specs=field_specs          # dictionary of specs referenced by field name
        
        self.show_refs=show_refs            # used for droppdown of list of shows
        self.show_refs.append('')
        
        self.initial_media_dir=initial_media_dir
        self.pp_home_dir=pp_home_dir
        self.initial_tab=initial_tab

        # Create a File Folder Navigator in a frame
        self.ffn = gui.FileFolderNavigator(False,self.initial_media_dir,True,False)#width=self.ffn_width, height=self.ffn_height

        # with some buttons
        self.ffn_select=gui.Button('Select',width=100,height=30)
        self.ffn_cancel=gui.Button('Cancel',width=100,height=30)
        self.ffn_select.set_on_click_listener(self,'on_fileselection_dialog_select')
        self.ffn_cancel.set_on_click_listener(self,'on_fileselection_dialog_cancel')
        self.ffn_button_frame=gui.HBox(width=self.ffn_width+60,height=30)
        self.ffn_button_frame.append(self.ffn_cancel)
        self.ffn_button_frame.append(self.ffn_select)

        # and error label for ffn
        self.ffn_error=gui.Label('',width=self.ffn_width,height=20)

        # frame for ffn and buttons
        self.ffn_frame=gui.VBox(width=self.ffn_width+60, height=self.ffn_height+90) #10
        self.ffn_frame.append(self.ffn,key='ffn')
        self.ffn_frame.append(self.ffn_error,key='ffn_error')
        self.ffn_frame.append(self.ffn_button_frame,key='ffn_buttons')

  

        # create a Tabbed Editor
        self.tabview= TabView(self.frame_width,self.frame_height,30)


        # tabs are created dynamically from pp_definitions.py
        # get fields for this record using the record type in the loaded record
        record_fields=self.record_specs[self.field_content['type']]

        # init results of building the form
        self.tab_row=1 # row on form
        self.field_objs=[]  # list of field objects in record fields order, not for sep or tab
        self.field_index=0 # index to self.field_objs incremented after each field except tab and sep
                                        # can be used as an index to self.field_objs and self.button_objs
        self.button_objs=[]   # list of button objects in record field order , not for sep or tab =None for non-buttons
        
        # populate the dialog box using the record fields to determine the order
        for field in record_fields:
            # get list of values where required
            values=[]
            if self.field_specs[field]['shape']in("option-menu",'spinbox'):
                # print 'should be field name', field
                # print 'should be shape',self.field_specs[field]['shape']
                if field in ('sub-show','start-show'):
                    values=self.show_refs                    
                else:
                    values=self.field_specs[field]['values']
            else:
                values=[]
            # make the entry
            obj,button=self.make_entry(field,self.field_specs[field],values)
            if obj is not  None:
                self.field_objs.append(obj)
                self.button_objs.append(button)
                self.field_index +=1

        #construct the tabview
        self.tabview.construct_tabview()
        
        # frame for file navigator and tabbed editor
        # conent of frame is switched between ffn and tabview
        self.root = gui.HBox(width=self.tabview.get_width() + 100, height=self.frame_height+ 100) #1
        self.root.append(self.tabview,key='switch')
        self.add_field('cont',self.root)

        #adjust width of diaolg box
        self.style['width']=gui.to_pix(self.tabview.get_width() + 200)
        
        self.set_on_confirm_dialog_listener(self,'confirm')      
        return None

    def show_tab(self,key):
        self.tabview.show(key)      


    # create an entry in an editor panel
    def make_entry(self,field,field_spec,values):
        # print 'make entry',self.field_index,field,field_spec
        if field_spec['shape']=='tab':
            width=len(field_spec['text'])*8+4
            self.current_tab = self.tabview.add_tab(width,field_spec['name'],field_spec['text'])
            # print 'make tab', field_spec['name']
            self.tab_row=1
            return None,None
        elif field_spec['shape']=='sep':
            self.current_tab.append(gui.Label('',width=self.frame_width,height=10))
            self.tab_row+=1
            return None,None

        else:

            # print 'replace param in make entry',field
            # print 'content', field, self.field_content[field]
            # is it in the field content dictionary
            if not field in self.field_content:
                print "Value for field not found in opened file: " + field
                return None,None
            else:

                # bodge  - assumes only type is read only
                if field_spec['read-only']=='yes':
                    obj=(gui.Label(self.field_content[field],width=self.field_width,height=20))
                    obj.style['font-weight']='bold'

                
                elif field_spec['shape']in ('entry','browse','font','colour'):
                    obj=gui.TextInput(single_line=True,width=self.field_width,height=20)
                    obj.set_value(self.field_content[field])
                    
                elif field_spec['shape']=='text':
                    obj=gui.TextInput(width=self.field_width,height=80,single_line=False)
                    obj.set_value(self.field_content[field])

                elif field_spec['shape']=='spinbox':
                    print 'spinbox not implemented'
                    return None,None

                    
                elif field_spec['shape']=='option-menu':
                    obj=gui.DropDown(width=self.field_width,height=20)
                    for key, value in enumerate(values):
                        item=gui.DropDownItem(value,width=200,height=20)
                        obj.append(item, key=key)
                    obj.set_value(self.field_content[field])

                else:
                    print"Uknown shape for: " + field
                    return None,None
                
                # create buttons where required
                if field_spec['shape']=='browse':
                    button=self.browse_button(20,20,'','browse_button',self.field_index)
                    
                elif field_spec['shape']=='colour':
                    if ColourMap().exists(self.field_content[field]) is True:
                        colour=ColourMap().lookup(self.field_content[field])
                    else:
                        colour=self.field_content[field]
                    button= gui.ColorPicker(colour,width=20, height=20)
                    button.set_on_change_listener(self, 'color_picker_changed' )
                    
                else:
                    button=None

                append_with_label(self.current_tab,field_spec['text'],obj,button,width=self.frame_width)
                self.tab_row+=1    
                return obj,button

    def confirm(self):
        # OK button is pressed so update the field values in the profile
        # self.field_content - dictionary - the track parameters to be edited and returned
        # key is field name e.g. omx-window
                                                                     
        # get list of fields in the record in the same order as the form was generated
        record_fields=self.record_specs[self.field_content['type']]
        
        field_index=0 # index to self.field_objs - not incremented for tab and sep

        for field in record_fields:
            # get the details of this field
            field_spec=self.field_specs[field]
            #print  'reading row',field_index,field_spec['shape']
            
            # and get the value
            if field_spec['shape']not in ('sep','tab'):

                #bodge for type which is a label
                if field_spec['read-only']=='yes':
                    self.field_content[field]=self.field_objs[field_index].get_text()

                # get result of button from button and also put it in field
                elif field_spec['shape'] in ('colour'):
                    # button is actually a color picker
                    self.field_content[field]=self.button_objs[field_index].get_value()
                    self.field_objs[field_index].set_value(self.field_content[field])

                else:
                    self.field_content[field]=str(self.field_objs[field_index].get_value())
                    
                # print field_spec['shape'],field_spec['text']+':  ',self.field_content[field]    
                field_index +=1
        self.hide()
        self.callback()



# browse button

    def browse_button(self,w,h,label,base_name,field_index):
        # create a button that returns the key to on_click_listener
        bname=base_name+str(field_index)
        but=gui.Button(label,width=w,height=h)
        f = lambda  _bname=field_index: self.open_fileselection_dialog( _bname)
        fname=base_name+'_' + str(field_index)
        setattr(self, fname, f)
        but.set_on_click_listener(self, fname)
        return but


    def open_fileselection_dialog(self,browse_field_index):
        self.browse_field_index=browse_field_index
        self.root.append(self.ffn_frame,key='switch')

    def on_fileselection_dialog_cancel(self):
        self.root.append(self.tabview,key='switch')

    def on_fileselection_dialog_select(self):
        # a list() of filenames and folders is returned
        flist=self.ffn.get_selection_list()
        if len(flist)==0:
            self.ffn_error.set_text('nothing selected')
            return
        file_path=flist[0]
        file_path=os.path.normpath(file_path)
        # print "file path ", file_path
        relpath = os.path.relpath(file_path,self.pp_home_dir)
        # print "relative path ",relpath
        common = os.path.commonprefix([file_path,self.pp_home_dir])
        # print "common ",common
        if common.endswith("pp_home") is False:
            #print file_path
            self.ffn_error.set_text(file_path)
            #self.button_objs[self.field_index]=file_path
        else:
            location = "+" + os.sep + relpath
            location = string.replace(location,'\\','/')
            self.ffn_error.set_text(location)
            self.field_objs[self.browse_field_index].set_value(location)
            self.root.append(self.tabview,key='switch')
            #print location


        
# colour picker

    def color_picker_changed(self,result):
        self.update_colour_fields()
        # print 'colour picked',result


    def update_colour_fields(self):
        # copy result of colour picker into the text field
        record_fields=self.record_specs[self.field_content['type']]
        field_index=0 # index to self.field_objs - not incremented for tab and sep
        for field in record_fields:
            field_spec=self.field_specs[field]
            if field_spec['shape']not in ('sep','tab'):
                if field_spec['shape'] in ('colour'):
                    self.field_objs[field_index].set_value(self.button_objs[field_index].get_value())
                field_index +=1