# Path: message_box.py
# class MessageBox(Popup):
#     text = StringProperty('')
#     cb = ObjectProperty()
# 
#     ok_text = StringProperty('OK')
#     cancel_text = StringProperty('Cancel')
# 
#     def ok(self):
#         if self.cb:
#             self.cb(True)
#         self.dismiss()
# 
#     def cancel(self):
#         if self.cb:
#             self.cb(False)
#         self.dismiss()


    import wx
import threading
import os.path
import subprocess as sp
import time
from kivy.clock import mainthread
from message_box import MessageBox

    def open(self, start_dir="", title="", cb=None):
        self.cb = cb
        self.title = title
        self.start_dir = start_dir
        threading.Thread(target=self._open_dialog).start()

    def _open_dialog(self):
        path = None
        try:
            if self.use_wx:
                path = self._wx_get_path()

            elif self.use_zenity:
                os.unsetenv('WINDOWID')  # needed so dialog pops up infront of my window
                path = self._run_command(['zenity', '--title', self.title, '--file-selection', '--filename', self.start_dir + '/', '--file-filter', 'GCode files | *.g *.gcode *.nc *.gc *.ngc'])

            elif self.use_kdialog:
                path = self._run_command(['kdialog', '--title', self.title, '--getopenfilename', self.start_dir, 'GCode Files (*.g *.gcode *.nc *.gc *.ngc)'])
            else:
                self.failed = True

        except Exception:
            self.failed = True

        self._loaded(path)

    @mainthread
    def _loaded(self, path):
        if self.failed:

# Path: message_box.py
# class MessageBox(Popup):
#     text = StringProperty('')
#     cb = ObjectProperty()
# 
#     ok_text = StringProperty('OK')
#     cancel_text = StringProperty('Cancel')
# 
#     def ok(self):
#         if self.cb:
#             self.cb(True)
#         self.dismiss()
# 
#     def cancel(self):
#         if self.cb:
#             self.cb(False)
#         self.dismiss()


# Path: native_file_chooser.py
    import wx
import threading
import os.path
import subprocess as sp
import time
from kivy.clock import mainthread
from message_box import MessageBox


    def open(self, start_dir="", title="", cb=None):
        self.cb = cb
        self.title = title
        self.start_dir = start_dir
        threading.Thread(target=self._open_dialog).start()

    def _open_dialog(self):
        path = None
        try:
            if self.use_wx:
                path = self._wx_get_path()

            elif self.use_zenity:
                os.unsetenv('WINDOWID')  # needed so dialog pops up infront of my window
                path = self._run_command(['zenity', '--title', self.title, '--file-selection', '--filename', self.start_dir + '/', '--file-filter', 'GCode files | *.g *.gcode *.nc *.gc *.ngc'])

            elif self.use_kdialog:
                path = self._run_command(['kdialog', '--title', self.title, '--getopenfilename', self.start_dir, 'GCode Files (*.g *.gcode *.nc *.gc *.ngc)'])
            else:
                self.failed = True

        except Exception:
            self.failed = True

        self._loaded(path)

    @mainthread
    def _loaded(self, path):
        if self.failed:

            mb = MessageBox(text='File Chooser {} failed - try a different one'.format(NativeFileChooser.type_name))