Accessing element of kivy from another class

3,175 views
Skip to first unread message

SANDEEP KUSHWAHA

unread,
Feb 11, 2016, 1:26:05 AM2/11/16
to Kivy users support
Hi All,
I have defined two class say A and B.A is defined above B.I want to access member of B from A,which i am not able to as it is raising error stating not defined.Any help will be haighly appreciated!!!

Oon-Ee Ng

unread,
Feb 11, 2016, 3:44:22 AM2/11/16
to kivy-...@googlegroups.com
Some example code would help here, it is not clear what 'member'
you're referring to. A function? A class function? An attribute?
> --
> You received this message because you are subscribed to the Google Groups
> "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

SANDEEP KUSHWAHA

unread,
Feb 11, 2016, 5:21:20 AM2/11/16
to kivy-...@googlegroups.com
Actually i want to update the label defined in class B from class A.I am trying to bind,but it's not happening


You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/lu-0fE5IEkc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

ZenCODE

unread,
Feb 11, 2016, 4:19:39 PM2/11/16
to Kivy users support
As Oon-Ee Ng says, post some runnable code and we can try help :-) There are many, many ways to do this. The best way depends on how you have structured you app.

SANDEEP KUSHWAHA

unread,
Feb 12, 2016, 1:43:07 AM2/12/16
to kivy-...@googlegroups.com
class BrowseFile(Popup):


    def __init__(self,**kwargs):
        super(BrowseFile,self).__init__(**kwargs)
        ok_b = self.ids.ok_btn
        ok_b.bind(on_press = self.update_driver_path)

    def update_driver_path(self,evt=None):
        print "driver path inside display port :",driver_path
        self.dismiss()
        upd = return_uploaddriver()
        print "type of upd",type(upd)
#       upd.ids.driver_id.text = driver_path

        upd.ids.driver_id.bind(text=self.update_label)
      #  self.update_label()   
        print "update driver path :",upd.ids.driver_id.text

    def update_label(self,instance,value):
        print "inside update_label\n"
      #  upd = return_uploaddriver()
       # upd.ids.driver_id.text = driver_path
        print "update driver path :",upd.ids.driver_id.text

and one class :UploadDriver

class UploadDriver(BoxLayout):
    driver_path_label = StringProperty('')
    mypopup1 = BrowseFile()

    def __init__(self,**kwargs):
        super(UploadDriver,self).__init__(**kwargs)
    #global popup1
    global thrd_lb
    global t1,t2
    global report_flag
    folder_selected = StringProperty()
    portpopup = PortPop()
    threadpop = ThreadPopup()




kv file:


<UploadDriver>:

    id: uploadId

    BoxLayout:
        orientation:'vertical'
        spacing: 20
        padding: 10
        pos_hint: {'x':0.5 ,'y': 0.1}
        size_hint: 0.7,0.7

        BoxLayout:
            orientation: 'horizontal'
            spacing: 60
            pos_hint: {'x':0 ,'y': 0.2}

            Label:
                text: 'Upload driver path'
                color: .4,.6,.1,.8
                id: driver_id
                size_hint: 0.1, None
                height: 50
                text_size: None, None
                canvas.before:
                    Color:
                        rgba: .3, .3, .3, .3
                    Rectangle:
                        size: self.size
                        pos: self.pos

            Button:
                text: 'Browse'
                size_hint: None, None
                height: 50
                width: 100
                on_press: root.select_port()

<BrowseFile>:


    BoxLayout:
        orientation: 'vertical'
        FileChooserListView:
            id: filechooser
            on_selection: root.selected_file(filechooser.selection)
            dirselect: True
        Label:
            id: text_input
            text:'you clicked on :'

        BoxLayout:
            orientation: 'horizontal'

            Button:
                id: ok_btn
                text: 'OK'
                size_hint: None, None
                height: 30
                width: 70
                pos_hint: {'x':0 ,'y': .5}
            #  on_press: root.port_open()


I am trying to update label in class UploadDriver from Class BrowseFile.




On Fri, Feb 12, 2016 at 2:49 AM, ZenCODE <zenkey....@gmail.com> wrote:
As Oon-Ee Ng says, post some runnable code and we can try help :-) There are many, many ways to do this. The best way depends on how you have structured you app.

--

ZenCODE

unread,
Feb 12, 2016, 8:11:38 AM2/12/16
to Kivy users support
Unfortunately, you have just given the code for these 2 classes. It does not tell us how they are related or give any indication of the structure of your app. And this is what's important when linking them.

So, without a runnable example, we can only guess. I'll guess that UploadDriver is a class that creates a BrowseFile class? Then you might want to pass a reference into your UploadDriver class instance.

So, add this to you BrowseFile class.

    class BrowseFile(Popup):
        upload_driver = ObjectProperty()

Then, when you instantiate it from the UploadDriver instance, you go

    browse_file = BrowseFile(upload_driver=self, ......)

Then, inside BrowseFile, you can access the UploadDriver instance as

    self.upload_driver.my_propery = my_value

Or such like. It depends on you program flow and how and where you instantiate your BrowseFile class. The best solution is only clear given the exact context.

Good luck.

SANDEEP KUSHWAHA

unread,
Feb 12, 2016, 10:12:42 AM2/12/16
to kivy-...@googlegroups.com

Thank you very much for your constant help.I am new to kivy...and really appreciate your help.
My problem is that....basically I want to bind text property of label defind in Upload driver class through Browse file class...but this binding is not happening.I have defined a callback function inside bind method.I currently don't have the code segment but will surely send once I get it.

--

SANDEEP KUSHWAHA

unread,
Feb 17, 2016, 1:56:35 AM2/17/16
to kivy-...@googlegroups.com
please look into the code segment below:
I have tried all possible means to update label on click of a button that is included in a popup with filechooser.Also i have define two below class in kivy.Kivy code i have sent you earlier.Hope u can help me out of this!!!
Some lines are commented,that are indication to  ways i have tried to achieve this.

class BrowseFile(Popup):

        
    UploadDriver = ObjectProperty()

    def __init__(self,**kwargs):
        super(BrowseFile,self).__init__(**kwargs)
        ok_b = self.ids.ok_btn
        ok_b.bind(on_press=self.UploadDriver.update_label)        

    def update_driver_path(self,instance):
        self.dismiss()
        upd = return_uploaddriver()
        print "type of upd",type(upd)
        upd.update_label()
# upd.ids.driver_id.bind(text=self.ids.input_text('text')
        print "update driver path :",upd.ids.driver_id.text

 #   def update_label(self,instance):
  #      print "inside update_label\n"
      #  upd.ids.driver_id.text = driver_path
   #     print "update driver path :",upd.ids.driver_id.text
 
    def selected_file(self, filename):
        global browse_flag
        global store_path
        global driver_path
        if browse_flag == 0:
            driver_path = filename[0]
            self.ids.text_input.text = driver_path

        elif browse_flag == 1:
            
            store_path = filename[0]
            self.ids.text_input.text = store_path
            browse_flag = 0


            
The other class UploadDriver look like this:

class UploadDriver(BoxLayout):
    driver_path_label = StringProperty('')
    mypopup1 = BrowseFile()
    
    def __init__(self,**kwargs):
        browse_file = BrowseFile(UploadDriver=self)
        super(UploadDriver,self).__init__(**kwargs)
    #global popup1 
    global thrd_lb  
    global t1,t2 
    global report_flag
    folder_selected = StringProperty()
    portpopup = PortPop()
    threadpop = ThreadPopup()

    
    def update_label(self):
        self.ids.driver_id.text = driver_path
        print "driver path....."    , self.ids.driver_id.text


    def add_to_label(self,store_path1):
        global store_path
        print "inside add_to_label"
 
        self.mypopup1.dismiss()

        self.ids.upload_port.text = store_path
      

Oon-Ee Ng

unread,
Feb 17, 2016, 2:38:45 AM2/17/16
to kivy-...@googlegroups.com
As ZenCode has explained, your code is not sufficient. You are showing
two classes but you're not showing how/where they're being used in
your app.

As an analogy, if you asked me how to get from the bedroom to the
kitchen, I'd only be able to answer that if I knew the map of your
house. You're showing us how the bedroom and kitchen look, but we have
no idea what the house is like.

On Wed, Feb 17, 2016 at 2:56 PM, SANDEEP KUSHWAHA
> You received this message because you are subscribed to the Google Groups
> "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an

SANDEEP KUSHWAHA

unread,
Feb 17, 2016, 3:44:23 AM2/17/16
to kivy-...@googlegroups.com
i am posting the entire code now:

import kivy
kivy.require('1.1.3')

import random
import shlex, subprocess
import thread
import time
import os,sys, glob
import signal
import threading
import multiprocessing
import webbrowser
from multiprocessing import Process,Lock, Condition

from kivy.app import App
from kivy.clock import Clock
from threading import Thread
from kivy.metrics import Metrics
from kivy.properties import NumericProperty
from kivy.properties import StringProperty
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.scatter import Scatter
from kivy.uix.treeview import TreeView, TreeViewLabel
from kivy.uix.widget import Widget
from kivy.uix.dropdown import DropDown
from kivy.base import runTouchApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.uix.progressbar import ProgressBar
from kivy.properties import ObjectProperty
from kivy.core.text import Label
from functools import partial

Builder.load_file('homepage.kv')
Builder.load_file('porting.kv')
Builder.load_file('uploaddriver.kv')
Builder.load_file('customdb.kv')
Builder.load_file('popup.kv')

driver_path = StringProperty('')
store_path = ""
source_ver_path = ""
dest_ver_path = ""
select_os1 = ""
select_os2 = ""
select_ver1 = ""
select_ver2 = ""
dmt_pid = 0
browse_flag = 0
source_kernel_path = ''
dest_kernel_path = ''

#thrd_lb = " Auto Porting Unsuccessfull.. Please try Again "
thrd_lb = " Create custom DB Unsuccessfull... Please Try Again.. "
popup1 = Popup()
popup2 = Popup()
report_flag = 0



class Showcase(FloatLayout):
    pass


class SourceKernel(Popup):
    source_kernel_label = ""

    def selected_path(self,source_path):
        global source_kernel_path
        source_kernel_path = source_path[0]

    def dismiss_popup(self):
        self.dismiss()
        #self.clear_widgets()
        #self.add_widget(HomePage())

    def call_cancel(self):
        global source_kernel_path
        source_kernel_path = ""
        self.dismiss()

class DestinationKernel(Popup):
    source_kernel_label = ""

    def selected_dest_path(self,source_path):
        global dest_kernel_path
        dest_kernel_path = source_path[0]

    def dismiss_popup(self):
        self.dismiss()
        #self.clear_widgets()
        #self.add_widget(HomePage())

    def call_cancel(self):
        global dest_kernel_path
        dest_kernel_path = ""
        self.dismiss()


class BrowseFile(Popup):

        
    UploadDriver = ObjectProperty()

    def __init__(self,**kwargs):
        super(BrowseFile,self).__init__(**kwargs)
        ok_b = self.ids.ok_btn
        ok_b.bind(on_press=self.UploadDriver.update_label)        

    def update_driver_path(self,instance):
        self.dismiss()
        upd = return_uploaddriver()
        print "type of upd",type(upd)
        upd.update_label()
        print "update driver path :",upd.ids.driver_id.text

 #   def update_label(self,instance):
  #      print "inside update_label\n"
      #  upd.ids.driver_id.text = driver_path
   #     print "update driver path :",upd.ids.driver_id.text
 
    def selected_file(self, filename):
        global browse_flag
        global store_path
        global driver_path
        if browse_flag == 0:
            driver_path = filename[0]
            self.ids.text_input.text = driver_path

        elif browse_flag == 1:
            
            store_path = filename[0]
            self.ids.text_input.text = store_path
            browse_flag = 0
    def cancel_port(self):
driver_path = ''
self.dismiss()
 
    def selected_file2(self, filename):
        global store_path
        print "inside selected file2..............."
        global popup2
        #upload_label = UploadDriver.ids.upload_port
        store_path = filename[0]
print "store path: ",store_path
        #popup = Popup(title = 'uplaod label', content=Label(text = self.upload_label), size_hint = (0.5,0.5))
        #popup.open()
        self.ids.text_input.text = store_path

        #popup = Popup(title = 'uplaod label', content=Label(text = driver_path+" ---"+ store_path +" ---"+ source_ver_path +" ---"+ dest_ver_path +" ---"), size_hint = (0.5,0.5))
        #popup.open() 


    def port_open(self):
        global browse_flag
        print "inside port open..........";
        self.ids.text_input.text = "Selected file"
        browse_flag = 1
        #fc = self.ids.filechooser
       # fc.bind(on_selection =lambda widget:  self.selected_file2(fc.selection))
      #  self.ids.ok_btn.bind(on_press = lambda widget: self.update_driver_path)
        self.ids.cancel_btn.bind(on_press = lambda widget: self.cancel_port2())
        self.open()

    def display_label(self):
        print "inside dispaly label............"
        global store_path
        #upload_label = UploadDriver.ids.upload_port
        #store_path = filename[0]
       # popup = Popup(title = 'data passed', content=Label(text = store_path), size_hint = (0.5,0.5))
       # popup.open()

        #self.ids.text_input.text = store_path
        upload_obj.add_to_label(store_path)
        self.dismiss()

    def cancel_port2(self):
        store_path = ''
print "store path :",store_path
        self.dismiss()


class CustomPopup(Popup):
    pass


    



class PortPop(Popup):
    def terminate_call(self):
       
self.dismiss()
proc = subprocess.Popen("ps | grep perl", stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
#print "program output:", out
        s_pid = shlex.split(out)
dmt_pid = s_pid[0]
print "PID_term_bfre:", dmt_pid
os.kill(int(dmt_pid),signal.SIGTERM)
print "PID_term:", dmt_pid
        
    
   # def terminate_customdb(self):
       
# self.dismiss()
# proc = subprocess.Popen("ps | grep  perl ", stdout=subprocess.PIPE, shell=True)
# (out, err) = proc.communicate()
# print "program output:", out
 #       s_pid = shlex.split(out)
# dmt_pid = s_pid[0]
# print "PID_term_bfre:", dmt_pid
# os.kill(int(dmt_pid),signal.SIGTERM)
# print "PID_term:", dmt_pid

    def custom_open(self):
        self.open()
     #   self.ids.cancel_id.bind(on_press = lambda widget: self.terminate_call())


class ThreadPopup(Popup):
    
    global thrd_lb
    global report_flag

    def myopen(self):
        #self.ids.text_input.text = thrd_lb
        #print self.ids.text_input.text
        self.ids.cancel_id.bind(on_press = lambda widget: self.on_call())
        self.open()
 
    def on_call(self):
        print "on_call is called"
        self.dismiss()
        print "on_call had dismissed"
        report_flag = 1
        print "report flag",report_flag

    def on_success(self):
        self.dismiss()
        print "I am in on_success"
        go_to_viewpage()

    def open_ported_driver_folder(self):
        global store_path
        folder_path = "file://"+store_path+"/"
        webbrowser.open(folder_path)

class ThreadPopup2(Popup):
    global thrd_lb


    def finish_open(self):
        self.ids.text_input.text = thrd_lb
        print self.ids.text_input.text
        self.ids.ok_btn.bind(on_press = lambda widget: self.on_ok)
        self.open()

    def on_ok(self):
        self.dismiss()

    
    



class ViewPage(BoxLayout):
    def back(self):
        self.clear_widgets()
        self.add_widget(UploadDriver())


class UploadDriver(BoxLayout):
    driver_path_label = StringProperty('')
    mypopup1 = BrowseFile()
    
    def __init__(self,**kwargs):
        browse_file = BrowseFile(UploadDriver=self)
        super(UploadDriver,self).__init__(**kwargs)
    #global popup1 
    global thrd_lb  
    global t1,t2 
    global report_flag
    folder_selected = StringProperty()
    portpopup = PortPop()
    threadpop = ThreadPopup()

    
    def update_label(self):
        self.ids.driver_id.text = driver_path
        print "driver path....."    , self.ids.driver_id.text


    def add_to_label(self,store_path1):
        global store_path
        print "inside add_to_label"
 
        self.mypopup1.dismiss()

        self.ids.upload_port.text = store_path
      
        


    def select_port(self):
        self.mypopup1.title = "Select Driver to port"
self.mypopup1.size_hint = (0.5,0.9)
self.mypopup1.open(UploadDriver())

    def select_port2(self):
self.mypopup1.title = "Select Driver to port"
self.mypopup1.size_hint = (0.5,0.9)
        self.mypopup1.port_open()
      
    def select_port3(self):
        content = BoxLayout(orientation = 'vertical')
        content.add_widget(BrowseFile3())
        popup = Popup(title = 'Select driver to port', content = content, size_hint = (0.5,1))
        popup.open()

    def select_port4(self):
        content = BoxLayout(orientation = 'vertical')
        content.add_widget(BrowseFile4())
        popup = Popup(title = 'Select driver to port', content = content, size_hint = (0.5,1))
        popup.open()

 
      
    def back_home(self):
        global driver_path
        global store_path
        global select_ver1
        global select_ver2
        global select_os1
        global select_os2
        driver_path = ''
        store_path = '' 
        select_ver1 = ''
        select_ver2 = ''
        select_os1 = ''
        select_os2 = ''
        self.clear_widgets()
        self.add_widget(HomePage())


    def back_upload(self):
        global driver_path
        global store_path
        print"driverpath",driver_path
        driver_path = ''
        store_path = ''
        self.clear_widgets()
        
        self.add_widget(UploadDriver())
        print"driverpath",driver_path
        print"store path",store_path
    




    def progress_func(self):
        self.clear_widgets()
        self.add_widget(Progress()) 

    def scriptCall(self):
        global dmt_pid
        global flag
       
 
        
        t2 = threading.Thread(target =  self.popup_call)
        t2.start()
        self.clear_widgets()
        self.add_widget(HomePage())

   

    def command_call(self):
        
        time.sleep(5)
        
        command = "perl DMT.pl"+" " +driver_path+"/ "+select_ver1+" "+select_ver2+" "+"/home/aricent/LinuxKernel/"+select_ver1+"/ " +" /home/aricent/LinuxKernel/"+select_ver2+"/ " +" 1"
print "command name -", command
        args = shlex.split(command)
        pipe = subprocess.Popen(args,stdout = subprocess.PIPE)
        print "PID:", pipe.pid
        

        exit_status = pipe.wait()
        print "exit status",exit_status
        
         
        self.threadpop.title = "Report"
        self.threadpop.size_hint = (0.4,0.4)
   
        if exit_status == 0:
            print "I am inside if"
            self.portpopup.dismiss()
            self.threadpop.open()

        else: 
            print "i am in else"
            self.portpopup.dismiss()
            self.threadpop.title = "----ERROR---- "
            self.threadpop.size_hint = (0.5,0.5)
            thrd_lb = " Auto Porting Unsuccessfull.. Please try Again "
            self.threadpop.open() 
            
    def popup_call(self):
        print "calling pop up"
        content = BoxLayout(orientation = 'vertical')
        content.add_widget(PortPop())        
        self.portpopup.title = 'Automatic Porting in Progress...Please Wait...'
        self.portpopup.size_hint = (0.5,0.45)
        self.portpopup.auto_dismiss = 'False'
        self.portpopup.open()

        t1 = threading.Thread(target = self.command_call)
        t1.start()

                     

        
def return_uploaddriver():
    up_driver = UploadDriver()
    return(up_driver)



#upload_obj = UploadDriver()
vp = ViewPage()
def go_to_viewpage():
    global t1
    print "I am in go_to_viewpage"
    upload_obj1 = UploadDriver()
    content = BoxLayout(orientation='vertical')
    content.add_widget(ViewPage())


class CustomDb(BoxLayout):
#    global mypopup
    portpopup = PortPop()
    threadpopup = ThreadPopup2()
    def select_source_kernel(self):
        
        mypopup = SourceKernel()
        mycontent = BoxLayout(orientation = 'vertical')
        mycontent.add_widget(SourceKernel())
        mypopup.title ="select source kernel"
        mypopup.size_hint = (0.5,0.5)
        mypopup.open()

    def select_dest_kernel(self):
        mypopup = DestinationKernel()
        mycontent = BoxLayout(orientation = 'vertical')
        mycontent.add_widget(DestinationKernel())
        mypopup.title ="select Destination kernel"
        mypopup.size_hint = (0.5,0.5)
        mypopup.open()

    def back_home(self):
        self.clear_widgets()
        self.add_widget(HomePage())

    
    def reset_custom(self):
        self.clear_widgets()
        self.add_widget(CustomDb())


        
    def continue_customdb(self):
        global dmt_pid
        global flag
       
 
        
        t3 = threading.Thread(target =  self.customdb_popup)
        t3.start()
        self.clear_widgets()
        self.add_widget(HomePage())



   

    def create_customdb(self):
        
        time.sleep(5)
        
        command = "perl CreateDBonly1.pl /home/dmt/LinuxKernel/linux-3.10.65/ /home/dmt/LinuxKernel/linux-3.18.3/"
print "command name -", command
        args = shlex.split(command)
        pipe = subprocess.Popen(args,stdout = subprocess.PIPE)
        print "PID:", pipe.pid
        

        exit_status = pipe.wait()
        print "exit status",exit_status
        
         
   
        if exit_status == 0:
            self.threadpop.title = "Finished"
            self.threadpop.size_hint = (0.4,0.4)
            print "I am inside if"
            self.portpopup.dismiss()
            self.threadpop.open()

        else: 
            print "i am in else"
            self.portpopup.dismiss()
            self.threadpopup.title = "----ERROR---- "
            self.threadpopup.size_hint = (0.5,0.5)
            thrd_lb = " CustomDb Creation Unsuccessfull.. Please try Again "
            self.threadpopup.finish_open() 
           # popup = Popup(title = 'customdb creation unsuccessfull...please try again', size_hint = (0.6,0.6))
           # popup.open()
            
    def customdb_popup(self):
        print "calling pop up"
        content = BoxLayout(orientation = 'vertical')
        content.add_widget(PortPop())        
        self.portpopup.title = 'Creating Custom Database...can take several hours'
        self.portpopup.size_hint = (0.5,0.45)
        self.portpopup.auto_dismiss = 'False'
        self.portpopup.custom_open()

        t4 = threading.Thread(target = self.create_customdb)
        t4.start()



class HomePage(BoxLayout):
    value = NumericProperty(0)
   
    def __init__(self, **kwargs):
        super(HomePage, self).__init__(**kwargs)
        Clock.schedule_interval(self.increment_value, 1 / 30.)
    dir_name = []
        dir = glob.glob('../Database/linux-*')
 
        for dn in dir:
            split_dn = dn.split("/")
            dir_name.append(split_dn[-1])
        dir_name.sort()
        dir_name.append('Custom')

        dropdown_os1 = DropDown()
        dropdown_os2 = DropDown()

        dropdown_ver1 = DropDown()
        dropdown_ver2 = DropDown()

        os = ['Linux' , 'Windows', 'Mac']

        for req_os in os:    
            btn = Button(text =  req_os, size_hint_y= None, height = 44,  background_color= (0.3,0.82,0.9,0.46))

            btn.bind(on_release = lambda btn: dropdown_os1.select(btn.text))
            dropdown_os1.add_widget(btn)

        mainbutton = self.ids.os_source
        mainbutton.bind(on_release = dropdown_os1.open)
        dropdown_os1.bind(on_select=self.on_select_os1)



        for req_os in os:           
            btn_1 = Button(text =  req_os, size_hint_y= None, height = 44,  background_color= (0.3,0.82,0.9,0.46))

            btn_1.bind(on_release = lambda btn_1: dropdown_os2.select(btn_1.text))
            dropdown_os2.add_widget(btn_1)


        mainbutton1 = self.ids.os_dest
        mainbutton1.bind(on_release = dropdown_os2.open)
        dropdown_os2.bind(on_select=self.on_select_os2)
   

        for ver in dir_name:    
            btn_v = Button(text = ver, size_hint_y= None, height = 44 , background_color= (0.3,0.82,0.9,0.46))

            btn_v.bind(on_release = lambda btn_v: dropdown_ver1.select(btn_v.text))
            dropdown_ver1.add_widget(btn_v)

        for ver in dir_name:      
            btn_v1 = Button(text = ver, size_hint_y= None, height = 44 , background_color= (0.3,0.82,0.9,0.46))

            btn_v1.bind(on_release = lambda btn_v1: dropdown_ver2.select(btn_v1.text))
            dropdown_ver2.add_widget(btn_v1)

        mainbutton_v = self.ids.ver_source
        mainbutton_v.bind(on_release = dropdown_ver1.open)

        mainbutton_v1 = self.ids.ver_dest
        mainbutton_v1.bind(on_release = dropdown_ver2.open)

        dropdown_ver1.bind(on_select = self.on_select_ver1)
        dropdown_ver2.bind(on_select = self.on_select_ver2)
        
    


    def on_select_os1(self, *args):
        self.text = args[1]
        setattr(self.ids.os_source, 'text', self.text)
        global select_os1
        select_os1 = self.text

    def on_select_os2(self, *args):
        self.text = args[1]
        setattr(self.ids.os_dest, 'text', self.text)
        global select_os2
        select_os2 = self.text

    def on_select_ver1(self, *args):
        self.text = args[1]
        setattr(self.ids.ver_source, 'text', self.text)
        global select_ver1
        select_ver1 = self.text

    def on_select_ver2(self, *args):
        self.text = args[1]
        setattr(self.ids.ver_dest, 'text', self.text)
        global select_ver2
        select_ver2 = self.text


    def increment_value(self, dt):
        self.value += dt



    def show_upload(self, instance):
        self.clear_widgets()

    def UploadDriver_func(self):


      #  content = BoxLayout(orientation = 'vertical')
        #content.add_widget(Label(text = "Do you want to generate custom database?"))
        content1 = BoxLayout(orientation = 'horizontal', spacing = 10)
      #  if(select_ver1 != '' and select_ver2 != '' and select_ver1 == select_ver2):
       #     flag = 1 
        content2 = AnchorLayout(anchor_x='center', anchor_y='center')
        if((select_ver1 == '' or select_ver2 == '' or select_ver1 == select_ver2) and (select_ver1 != 'Custom' or select_ver2 != 'Custom')):
            
            flag = 1

        elif(select_ver1 == 'Custom' or select_ver2 == 'Custom'):
            flag = 2

            #self.custPop.open()
        else:
            flag = 0
            self.clear_widgets()

            self.add_widget(UploadDriver())


        if flag == 1:


            if((select_ver1 != '' or  select_ver2 != '') and (select_ver1 == select_ver2) and (select_ver1 != 'Custom')):
                popup = Popup(title = 'Source and Destination kernel can\'t be same', content= content2 , size_hint = (0.4,0.3))
            else:
                popup = Popup(title = 'Please Select Both Kernel versions', content= content2 , size_hint = (0.4,0.3))
            
            content2.add_widget(Button(text = " OK ", size_hint = (0.4, 0.4),pos_hint = {'x' : 0.5, 'y' : 0.2},on_press = popup.dismiss))
            popup.open()


        elif flag == 2:
            popup = Popup(title = 'Do you want to generate custom database?', content= content1 , size_hint = (0.4,0.3))
            mybutton = Button(text = "Yes",id = 'yes_btn', size_hint = (0.3,0.4), pos_hint = {'x' : 0.5, 'y' : 0.2},on_press = lambda widget:self.call_customdb(popup))
            content1.add_widget(mybutton)

            content1.add_widget(Button(text = " No ", size_hint = (0.3, 0.4),pos_hint = {'x' : 0.5, 'y' : 0.2},on_press = popup.dismiss))
            
            popup.open()
         #   content.add_widget(content2)


    def myfunc(self,p):
        p.dismiss()
        self.clear_widgets()
        self.add_widget(ViewPage())

    def call_customdb(self,p):
        p.dismiss()
        self.clear_widgets()
        self.add_widget(CustomDb())




class ShowcaseApp(App):
    title = 'Driver Migration Tool'
    def build(self):
        root = BoxLayout(orientation='horizontal', padding=20, spacing=20)
        self.content = content = BoxLayout()
        root.add_widget(content)
        sc = Showcase()
        sc.content.add_widget(root)
        self.content.add_widget(HomePage())
        return sc
      


if __name__ == '__main__':
    ShowcaseApp().run()

SANDEEP KUSHWAHA

unread,
Feb 17, 2016, 4:00:19 AM2/17/16
to kivy-...@googlegroups.com
the flow is something like this:

HomePage->UploadDriver->BrowseFile

PFA screenshot of GUI:

when we click next in HomePage it takes to UploadDriver where we have BrowseFile button,on clicking this we get a popup containing filechooser and two buttons 'ok' and '.
'cancel'. on clicking ok it should update the label in p2 with selected file in popup.




p1.JPG
p2.JPG
p3.JPG

ZenCODE

unread,
Feb 17, 2016, 1:29:55 PM2/17/16
to Kivy users support
Okay, I can't run it, I get an error:

   File "/media/ZenOne/Zen/My Documents/Kivy/kivybits/Temp/main.py", line 40, in <module>
     Builder.load_file('homepage.kv')
   File "/home/fruitbat/Documents/kivy/kivy/kivy/lang/builder.py", line 287, in load_file
     with open(filename, 'r') as fd:
 IOError: [Errno 2] No such file or directory: 'homepage.kv'

Please post that file. But I see there are more.

    Builder.load_file('homepage.kv')
    Builder.load_file('porting.kv')
    Builder.load_file('uploaddriver.kv')
    Builder.load_file('customdb.kv')
    Builder.load_file('popup.kv')

I would  try  guess in the meanwhile. But I can't because I can't see what p2 is either. And I can't see to how this would work, as your

    ok_b.bind(on_press=self.UploadDriver.update_label)

calls a function that does not accept the correct number of parameters?


    def update_label(self):
        self.ids.driver_id.text = driver_path

Perhaps I could just give an example of how to use a popup to pass back a value?

    https://github.com/Zen-CODE/kivybits/blob/master/ColorPickerPopup/main.py

SANDEEP KUSHWAHA

unread,
Feb 17, 2016, 1:35:08 PM2/17/16
to kivy-...@googlegroups.com
i am able to pass the values if both popup and label are defined in the same class.But here i have defined in two separate class UploadDriver and BrowseFile.I read somewhere that it is not possible to update label like that till kivy1.7.
kivy 1.9 does it automatically as when value changes.But finding tough to upgrade with with so many dependencies requirement.

thanks Zenky for all the help!!!

ZenCODE

unread,
Feb 17, 2016, 2:07:44 PM2/17/16
to Kivy users support
:-) If I could run it, it would be so much easier to help. Can you mail me a zip with everything? (I promise I will not distribute it). Or send me a private message with a download link? With Python, it's always possible. The only question is how....
Reply all
Reply to author
Forward
0 new messages