# 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: input_box.py
# class InputBox(Popup):
#     text = StringProperty('')
#     value = StringProperty('')
#     cb = ObjectProperty()
# 
#     ok_text = StringProperty('OK')
#     cancel_text = StringProperty('Cancel')
# 
#     def __init__(self, **kwargs):
#         self.window = Window
#         super(InputBox, self).__init__(**kwargs)
#         self.content = self.ids["content"]
# 
#     def on_open(self):
#         self.ids.input.focus = True
# 
#     def ok(self):
#         if self.cb:
#             s = self.ids.input.text
#             self.cb(s)
#         self.dismiss()
# 
#     def cancel(self):
#         if self.cb:
#             self.cb(None)
#         self.dismiss()


from kivy.uix.scatter import Scatter
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.logger import Logger, LOG_LEVELS
from kivy.graphics import Color, Line, Scale, Translate, PopMatrix, PushMatrix, Rectangle
from kivy.graphics import InstructionGroup
from kivy.properties import NumericProperty, BooleanProperty, ListProperty, ObjectProperty
from kivy.graphics.transformation import Matrix
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.clock import Clock, mainthread
from kivy.core.text import Label as CoreLabel
from message_box import MessageBox
from input_box import InputBox
import logging
import sys
import re
import math
import time
import traceback
    too_many = BooleanProperty(False)

    def __init__(self, comms=None, is_standalone=False, **kwargs):
        super(GcodeViewerScreen, self).__init__(**kwargs)
        self.app = App.get_running_app()
        self.last_file_pos = None
        self.canv = InstructionGroup()
        self.bind(pos=self._redraw, size=self._redraw)
        self.tx = 0
        self.ty = 0
        self.scale = 1.0
        self.comms = comms
        self.twod_mode = self.app.is_cnc
        self.rval = 0.0
        self.max_vectors = -1
        if not is_standalone:
            self.slice_size = self.app.config.get('Viewer', 'slice')
            self.above_layer = -self.slice_size
            self.max_vectors = self.app.config.getint('Viewer', 'vectors')

    def loading(self):
        self.valid = False
        self.li = Image(source='img/image-loading.gif')
        self.add_widget(self.li)
        self.ids.surface.canvas.remove(self.canv)
        # give loading image a chance to display
        Clock.schedule_once(self._load_file)

    def _loaded(self, ok):
        if not ok:

# 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: input_box.py
# class InputBox(Popup):
#     text = StringProperty('')
#     value = StringProperty('')
#     cb = ObjectProperty()
# 
#     ok_text = StringProperty('OK')
#     cancel_text = StringProperty('Cancel')
# 
#     def __init__(self, **kwargs):
#         self.window = Window
#         super(InputBox, self).__init__(**kwargs)
#         self.content = self.ids["content"]
# 
#     def on_open(self):
#         self.ids.input.focus = True
# 
#     def ok(self):
#         if self.cb:
#             s = self.ids.input.text
#             self.cb(s)
#         self.dismiss()
# 
#     def cancel(self):
#         if self.cb:
#             self.cb(None)
#         self.dismiss()


# Path: viewer.py
from kivy.uix.scatter import Scatter
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.logger import Logger, LOG_LEVELS
from kivy.graphics import Color, Line, Scale, Translate, PopMatrix, PushMatrix, Rectangle
from kivy.graphics import InstructionGroup
from kivy.properties import NumericProperty, BooleanProperty, ListProperty, ObjectProperty
from kivy.graphics.transformation import Matrix
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.clock import Clock, mainthread
from kivy.core.text import Label as CoreLabel
from message_box import MessageBox
from input_box import InputBox
import logging
import sys
import re
import math
import time
import traceback

    too_many = BooleanProperty(False)

    def __init__(self, comms=None, is_standalone=False, **kwargs):
        super(GcodeViewerScreen, self).__init__(**kwargs)
        self.app = App.get_running_app()
        self.last_file_pos = None
        self.canv = InstructionGroup()
        self.bind(pos=self._redraw, size=self._redraw)
        self.tx = 0
        self.ty = 0
        self.scale = 1.0
        self.comms = comms
        self.twod_mode = self.app.is_cnc
        self.rval = 0.0
        self.max_vectors = -1
        if not is_standalone:
            self.slice_size = self.app.config.get('Viewer', 'slice')
            self.above_layer = -self.slice_size
            self.max_vectors = self.app.config.getint('Viewer', 'vectors')

    def loading(self):
        self.valid = False
        self.li = Image(source='img/image-loading.gif')
        self.add_widget(self.li)
        self.ids.surface.canvas.remove(self.canv)
        # give loading image a chance to display
        Clock.schedule_once(self._load_file)

    def _loaded(self, ok):
        if not ok:

            mb = MessageBox(text='File not found: {} or Parse error'.format(self.app.gcode_file))