base_panel: Initial commit
This commit is contained in:
@@ -10,7 +10,6 @@ from ks_includes.KlippyGcodes import KlippyGcodes
|
||||
|
||||
class ScreenPanel:
|
||||
title_spacing = 50
|
||||
control = {}
|
||||
|
||||
def __init__(self, screen, title, back=True, action_bar=True, printer_name=True):
|
||||
self._screen = screen
|
||||
@@ -20,72 +19,16 @@ class ScreenPanel:
|
||||
self._printer = screen.printer
|
||||
self.labels = {}
|
||||
self._gtk = screen.gtk
|
||||
self.control = {}
|
||||
self.title = title
|
||||
|
||||
self.layout = Gtk.Layout()
|
||||
self.layout.set_size(self._screen.width, self._screen.height)
|
||||
|
||||
action_bar_width = self._gtk.get_action_bar_width() if action_bar == True else 0
|
||||
|
||||
if action_bar == True:
|
||||
self.control_grid = self._gtk.HomogeneousGrid()
|
||||
self.control_grid.set_size_request(action_bar_width - 2, self._screen.height)
|
||||
self.control_grid.get_style_context().add_class('action_bar')
|
||||
|
||||
button_scale = self._gtk.get_header_image_scale()
|
||||
logging.debug("Button scale: %s" % button_scale)
|
||||
|
||||
if back == True:
|
||||
self.control['back'] = self._gtk.ButtonImage('back', None, None, button_scale[0], button_scale[1])
|
||||
self.control['back'].connect("clicked", self._screen._menu_go_back)
|
||||
self.control_grid.attach(self.control['back'], 0, 0, 1, 1)
|
||||
|
||||
self.control['home'] = self._gtk.ButtonImage('main', None, None, button_scale[0], button_scale[1])
|
||||
self.control['home'].connect("clicked", self.menu_return, True)
|
||||
self.control_grid.attach(self.control['home'], 0, 1, 1, 1)
|
||||
else:
|
||||
for i in range(2):
|
||||
self.control['space%s' % i] = Gtk.Label("")
|
||||
self.control_grid.attach(self.control['space%s' % i], 0, i, 1, 1)
|
||||
|
||||
if len(self._config.get_printers()) > 1:
|
||||
self.control['printer_select'] = self._gtk.ButtonImage(
|
||||
'shuffle', None, None, button_scale[0], button_scale[1])
|
||||
self.control['printer_select'].connect("clicked", self._screen.show_printer_select)
|
||||
else:
|
||||
self.control['printer_select'] = Gtk.Label("")
|
||||
self.control_grid.attach(self.control['printer_select'], 0, 2, 1, 1)
|
||||
|
||||
self.control['estop'] = self._gtk.ButtonImage('emergency', None, None, button_scale[0], button_scale[1])
|
||||
self.control['estop'].connect("clicked", self.emergency_stop)
|
||||
self.control_grid.attach(self.control['estop'], 0, 3, 1, 1)
|
||||
#self.layout.put(self.control['estop'], int(self._screen.width/4*3 - button_scale[0]/2), 0)
|
||||
|
||||
try:
|
||||
env = Environment(extensions=["jinja2.ext.i18n"])
|
||||
env.install_gettext_translations(self.lang)
|
||||
j2_temp = env.from_string(title)
|
||||
title = j2_temp.render()
|
||||
except:
|
||||
logging.debug("Error parsing jinja for title: %s" % title)
|
||||
|
||||
self.title = Gtk.Label()
|
||||
self.title.set_size_request(self._screen.width - action_bar_width, self.title_spacing)
|
||||
self.title.set_hexpand(True)
|
||||
self.title.set_halign(Gtk.Align.CENTER)
|
||||
self.title.set_valign(Gtk.Align.CENTER)
|
||||
if printer_name == True:
|
||||
self.set_title("%s | %s" % (self._screen.connected_printer, title))
|
||||
else:
|
||||
self.set_title(title)
|
||||
|
||||
self.content = Gtk.Box(spacing=0)
|
||||
self.content.set_size_request(self._screen.width - action_bar_width, self._screen.height - self.title_spacing)
|
||||
|
||||
if action_bar == True:
|
||||
self.layout.put(self.control_grid, 0, 0)
|
||||
self.layout.put(self.title, action_bar_width, 0)
|
||||
self.layout.put(self.content, action_bar_width, self.title_spacing)
|
||||
|
||||
|
||||
def initialize(self, panel_name):
|
||||
# Create gtk items here
|
||||
@@ -97,6 +40,9 @@ class ScreenPanel:
|
||||
def get(self):
|
||||
return self.layout
|
||||
|
||||
def get_content(self):
|
||||
return self.content
|
||||
|
||||
def get_file_image(self, filename, width=1.6, height=1.6):
|
||||
if not self._files.has_thumbnail(filename):
|
||||
return None
|
||||
@@ -110,6 +56,9 @@ class ScreenPanel:
|
||||
return self._gtk.PixbufFromHttp(loc[1], None, width, height)
|
||||
return None
|
||||
|
||||
def get_title(self):
|
||||
return self.title
|
||||
|
||||
def home(self, widget):
|
||||
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
|
||||
|
||||
@@ -129,7 +78,8 @@ class ScreenPanel:
|
||||
self._screen._menu_go_home()
|
||||
|
||||
def set_title(self, title):
|
||||
self.title.set_label(title)
|
||||
self.title = title
|
||||
#self.title.set_label(title)
|
||||
|
||||
def show_all(self):
|
||||
self._screen.show_all()
|
||||
|
Reference in New Issue
Block a user