Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(please help) having problem in my code #1112

Open
boyintheroom opened this issue Jan 21, 2022 · 2 comments
Open

(please help) having problem in my code #1112

boyintheroom opened this issue Jan 21, 2022 · 2 comments

Comments

@boyintheroom
Copy link

Description of the Bug

1.Hi Developers im new to coding. i tried to make this video uploading app to my firebase storage but im not that good at coding so im stuck at this problem. when upload button is pressed the filechooser is opened and if i select a file it gets uploaded to the firebase But if i cancel and close the filechooser it gives an error.
2. i am unaware if this file chooser works on android or nor...if it does not please help me with this code too. im stuck on this since 6 January ,thats how poor i am.

Code

from kivy.app import App
from kivy.lang import Builder

kv = '''
<MainScreen>:
    name: 'mainscreen'
    MDLabel:
        id:username_info
        text:'Hello Main'
        font_style:'H1'
        halign:'center'

    MDFloatLayout:
        id:floate
        Video:
            id:vid

        MDToolbar:
            title: 'Bottom navigation'
            md_bg_color: .2, .2, .2, 1
            specific_text_color: 1, 1, 1, 1
        MDBottomNavigation:
            panel_color: 1,1,1,1
            MDBottomNavigationItem:
                name: 'screen 1'
                text: 'Home'
                icon: 'home-outline'
                MDRaisedButton:
                    id:upload
                    text:'Upload'
                    pos_hint:{'center_x':.5, 'center_y':.4}
                    on_release:
                        app.file_chooser()
                        upload.disabled=False
'''


class goodApp(MDApp):

    def build(self):
        self.strng = Builder.load_string(help_str)
        self.url  = "link.json"
        return self.strng

    def file_chooser(self):
        filechooser.open_file(on_selection=self.selected)        
    def selected(self,selection):
        config={
              'Api keys of firebase'
        }

        firebase=pyrebase.initialize_app(config)
        storage=firebase.storage()            
        Directory=selection[0]
        Name=re.findall('[ \w-]+\..*',Directory)
        loginEmail = self.strng.get_screen('loginscreen').ids.login_email.text
        storage.child(str(f"{loginEmail}")).child(str(f"{Name}")).put(str(f"{Name[0]}"))

        if selection==True:
            self.root.ids.vid.source=firebase
            self.strng.get_screen('mainscreen').ids.upload.disabled=True
            self.strng.get_screen('mainscreen').manager.current ='uploadscreen'
            self.strng.get_screen('mainscreen').manager.transition.direction='left'            

        if selection==False:
            self.strng.get_screen('mainscreen').ids.upload.disabled=False



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

Logs

[INFO ] [Logger ] Record log in C:\Users\Dheeraj.kivy\logs\kivy_22-01-19_1.txt
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO ] [Kivy ] v2.0.0
[INFO ] [Kivy ] Installed at "C:\Users\Dheeraj\AppData\Roaming\Python\Python38\site-packages\kivy_init_.py"
[INFO ] [Python ] v3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Users\Dheeraj\AppData\Local\Programs\Python\Python38\pythonw.exe"
[INFO ] [Factory ] 186 symbols loaded
[INFO ] [KivyMD ] 0.104.2, git-bc7d1f5, 2021-06-06 (installed at "C:\Users\Dheeraj\AppData\Local\Programs\Python\Python38\lib\site-packages\kivymd_init_.py")
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used
[INFO ] [GL ] OpenGL version <b'2.1 Mesa 10.0.2 (git-675cd84)'>
[INFO ] [GL ] OpenGL vendor <b'VMware, Inc.'>
[INFO ] [GL ] OpenGL renderer <b'Gallium 0.4 on llvmpipe (LLVM 3.4, 128 bits)'>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <b'1.30'>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [KivMob ] init called.
[WARNING] [KivMob ] Ads will not be shown.
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Video ] Provider: null(['video_ffmpeg', 'video_ffpyplayer'] ignored)
[INFO ] [Base ] Start application main loop
Traceback (most recent call last):
File "C:\Users\Dheeraj\AppData\Roaming\Python\Python38\site-packages\plyer\platforms\win\filechooser.py", line 102, in run
self.fname, _, _ = win32gui.GetOpenFileNameW(**args)
pywintypes.error: (0, 'GetOpenFileNameW', 'No error message is available')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Dheeraj\AppData\Roaming\Python\Python38\site-packages\plyer\platforms\win\filechooser.py", line 108, in run
self._handle_selection(self.selection)
File "C:\Users\Dheeraj\Desktop\kivy codes\Dheeraj.py", line 949, in selected
Directory=selection[0]
IndexError: list index out of range
[INFO ] [Base ] Leaving application in progress...

Screenshots

Add images to explain us this bug. Paste urls here.

Remove this section if no images here

Versions

  • OS: win 7 pro
  • Python: 3.7
  • Kivy: latest
  • KivyMD: latest (update everyweek)
@sanjomathew09
Copy link

import re
import pyrebase
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.app import App
from kivy.uix.video import Video
from kivy.core.window import Window
from kivy.utils import platform
from plyer import filechooser
from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.toolbar import MDToolbar
from kivymd.uix.button import MDRaisedButton
from kivymd.uix.bottomnavigation import MDBottomNavigation, MDBottomNavigationItem

kv = '''
ScreenManager:
MainScreen:
:
name: 'mainscreen'
MDLabel:
id: username_info
text: 'Hello Main'
font_style: 'H1'
halign: 'center'

MDFloatLayout:
    id: floate
    Video:
        id: vid
        source: ''
        pos_hint: {'center_x': 0.5, 'center_y': 0.7}
        size_hint: 0.8, 0.6

    MDToolbar:
        title: 'Bottom navigation'
        md_bg_color: .2, .2, .2, 1
        specific_text_color: 1, 1, 1, 1

    MDBottomNavigation:
        panel_color: 1, 1, 1, 1
        MDBottomNavigationItem:
            name: 'screen 1'
            text: 'Home'
            icon: 'home-outline'

            MDRaisedButton:
                id: upload
                text: 'Upload'
                pos_hint: {'center_x': .5, 'center_y': .4}
                on_release:
                    app.file_chooser()
                    upload.disabled = False

'''

class MainScreen(Screen):
pass

class goodApp(MDApp):
def build(self):
self.strng = Builder.load_string(kv) # Load kv string correctly
return self.strng

def file_chooser(self):
    # Open file chooser and get the selected file
    filechooser.open_file(on_selection=self.selected)        

def selected(self, selection):
    if selection:
        # Firebase configuration
        config = {
            'apiKey': "your-api-key",
            'authDomain': "your-auth-domain",
            'projectId': "your-project-id",
            'storageBucket': "your-storage-bucket",
            'messagingSenderId': "your-messaging-sender-id",
            'appId': "your-app-id",
            'measurementId': "your-measurement-id"
        }
        
        firebase = pyrebase.initialize_app(config)
        storage = firebase.storage()            
        directory = selection[0]
        name = re.findall(r'[ \w-]+\..*', directory)

        # Sample login email (replace with actual login mechanism if needed)
        loginEmail = "[email protected]"
        
        # Upload file to Firebase storage
        storage.child(f"{loginEmail}/{name[0]}").put(directory)

        # Get the URL for the uploaded video
        video_url = storage.child(f"{loginEmail}/{name[0]}").get_url(None)

        # Update the video source in the app
        self.root.get_screen('mainscreen').ids.vid.source = video_url
        self.root.get_screen('mainscreen').ids.vid.state = 'play'

        # Disable the upload button and transition to another screen (optional)
        self.root.get_screen('mainscreen').ids.upload.disabled = True

    else:
        # Handle case where no file was selected
        self.root.get_screen('mainscreen').ids.upload.disabled = False

if name == 'main':
goodApp().run()
Corrected bug

@sanjomathew09
Copy link

import re
import pyrebase
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from plyer import filechooser
from kivymd.app import MDApp

kv = '''
ScreenManager:
MainScreen:

:
name: 'mainscreen'
MDLabel:
id:username_info
text:'Hello Main'
font_style:'H1'
halign:'center'

MDFloatLayout:
    id:floate
    Video:
        id:vid
        source: ''
        pos_hint: {'center_x': 0.5, 'center_y': 0.7}
        size_hint: 0.8, 0.6

    MDToolbar:
        title: 'Bottom navigation'
        md_bg_color: .2, .2, .2, 1
        specific_text_color: 1, 1, 1, 1

    MDBottomNavigation:
        panel_color: 1,1,1,1
        MDBottomNavigationItem:
            name: 'screen 1'
            text: 'Home'
            icon: 'home-outline'

            MDRaisedButton:
                id:upload
                text:'Upload'
                pos_hint:{'center_x':.5, 'center_y':.4}
                on_release:
                    app.file_chooser()
                    upload.disabled=False

'''

class MainScreen(Screen):
pass

class goodApp(MDApp):

def build(self):
    self.strng = Builder.load_string(kv)  # Use kv here instead of help_str
    return self.strng

def file_chooser(self):
    # Open file chooser and get the selected file
    filechooser.open_file(on_selection=self.selected)        

def selected(self, selection):
    if selection:
        # Firebase configuration (replace with actual keys)
        config = {
            'apiKey': "your-api-key",
            'authDomain': "your-auth-domain",
            'projectId': "your-project-id",
            'storageBucket': "your-storage-bucket",
            'messagingSenderId': "your-messaging-sender-id",
            'appId': "your-app-id",
            'measurementId': "your-measurement-id"
        }
        
        firebase = pyrebase.initialize_app(config)
        storage = firebase.storage()            
        directory = selection[0]
        name = re.findall(r'[ \w-]+\..*', directory)

        # Sample login email (replace with actual login mechanism if needed)
        loginEmail = "[email protected]"
        
        # Upload file to Firebase storage
        storage.child(f"{loginEmail}/{name[0]}").put(directory)

        # Get the URL for the uploaded video
        video_url = storage.child(f"{loginEmail}/{name[0]}").get_url(None)

        # Update the video source in the app
        self.root.get_screen('mainscreen').ids.vid.source = video_url
        self.root.get_screen('mainscreen').ids.vid.state = 'play'

        # Disable the upload button and navigate (optional)
        self.root.get_screen('mainscreen').ids.upload.disabled = True

    else:
        # Handle case where no file was selected
        self.root.get_screen('mainscreen').ids.upload.disabled = False

if name == 'main':
goodApp().run()
Corrected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants