def load_view(self, name, data=None): """ Loads a given view. Replaces previous view, if any. Triggers the input management system.. :param name: name of a view. :param data: optional, some extra data. """ if name not in self.views.keys(): message = "Descriptor has no view with name: {}".format(name) raise WindowError(message) view_path, prepare = self.views.get(name) script = Clutter.Script() script.load_from_file(view_path) script.connect_signals_full(signals.connect_registered, self.application) self.ui = _UI(script) if callable(prepare): if prepare(self.application, self, script, data) == False: return children = self.stage.get_children() main_actor = script.get_object("main") if children: self.input_group.stop_middleware() old_child = children[0] self.stage.replace_child(old_child, main_actor) else: self.stage.add_child(main_actor) self.input_group.load_content(main_actor) self.script = script
def create_stage(self, argv): style = Mx.Style.get_default() style.load_from_file(res.get("style.css")) script = Clutter.Script() script.load_from_file(res.get("script.json")) print(script.list_objects()) return script.get_object("stage")
def __init__(self): super().__init__() self.button = Mx.Button() self.script = Clutter.Script() self.script.load_from_file('concept/mxButton/button.json') self.button = self.script.get_object('button') self.icon = self.script.get_object('icon') handle = Rsvg.Handle() svg = handle.new_from_file('concept/mxButton/edytuj.svg') pixbuf = svg.get_pixbuf() pixbuf = pixbuf.scale_simple(100, 100, 3) self.icon.set_from_data(pixbuf.get_pixels(), Cogl.PixelFormat.RGBA_8888, pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride()) self.add_child(self.button) self.layout = Clutter.BinLayout() self.set_layout_manager(self.layout)
def test_box(self): """Test box layout from JSON""" script = Clutter.Script() script.load_from_data(self.BOX_JSON, len(self.BOX_JSON)) main = script.get_object("main") self.assertTrue(main is not None, "Failed to load object") self.assertEqual(main.get_property("orientation"), Clutter.Orientation.VERTICAL)
def _init_content(self): self.set_layout_manager(Clutter.BinLayout()) json = dirs.get_json_path('loading_screen', '_'.join(['default', pisak.config['skin']])) script = Clutter.Script() script.load_from_file(json) main = script.get_object('main') self.add_actor(main)
def load_ui(self, filename): self.ui = Clutter.Script() try: self.ui.load_from_file(filename) except BaseException as e: logging.warning(e) return False return True
def __init__(self): super().__init__() Mx.Style.get_default() script = Clutter.Script() script.load_from_file("scanning.json") script.connect_signals_full(signals.python_connect) main_actor = script.get_object("main") self.add_child(main_actor) self.layout = Clutter.BinLayout() self.set_layout_manager(self.layout)
def _load_script(self): self.script = Clutter.Script() self.script.load_from_file("button_layout.json") self.script.connect_signals_full(signals.connect_registered) self.view_actor = self.script.get_object("main") self.image = self.script.get_object("image") self.image.set_from_file(os.path.join(res.PATH, "jagoda.jpg")) self.image.set_scale_mode(2) self.set_layout_manager(Clutter.BinLayout()) self.add_child(self.view_actor)
def __init__(self): Clutter.init(None) ui = Clutter.Script() ui.load_from_file("ui-threads.json") stage = ui.get_object("stage") stage.connect("destroy", self.stop) stage.connect("destroy", lambda w: Clutter.main_quit()) self.loader = ui.get_object("loader") self.loader.set_from_file("style/loading.png") self.t = Clutter.PropertyTransition(property_name='rotation-angle-z') self.t.set_from(0) self.t.set_to(360) self.t.set_duration(3000) self.t.set_animatable(self.loader) self.t.set_repeat_count(-1) self.t.start() button1 = ui.get_object("button1") button1.connect("button-press-event", self.execute_in_main) button1.set_reactive(True) button2 = ui.get_object("button2") button2.connect("button-press-event", self.idle_add_event) button2.set_reactive(True) button3 = ui.get_object("button3") button3.connect("button-press-event", self.threads_idle_add_event) button3.set_reactive(True) button4 = ui.get_object("button4") button4.connect("button-press-event", self.execute_in_thread) button4.set_reactive(True) stage = ui.get_object("stage") stage.set_title("Test threads") stage.connect("destroy", self.stop) stage.show_all() self.events = JoinableQueue(10) # UI events needs to happen from within the # main thread. This was the only way I found that would do that. # It looks weirdm, but it works. def execute(event): print("Execute " + event + " from " + str(current_thread())) for i in range(100): hashlib.md5(str(list(range(100000)))) print("Done executing") self.execute = execute stage.show()
def load_view(self, name, data): if name not in self.views.keys(): message = "Descriptor has no view with name: {}".format(name) raise LauncherError(message) view_path, prepare = self.views.get(name) self.script = Clutter.Script() self.script.load_from_file(view_path) self.script.connect_signals_full(signals.connect_registered) prepare(self, self.script, data) children = self.get_children() main_actor = self.script.get_object("main") if children: old_child = children[0] self.replace_child(old_child, main_actor) else: self.add_child(main_actor)
def load_view(self, name, data=None): if name not in self.views.keys(): message = "Descriptor has no view with name: {}".format(name) raise WindowError(message) view_path, prepare = self.views.get(name) self.script = Clutter.Script() self.script.load_from_file(view_path) self.script.connect_signals_full(signals.connect_registered, self.application) self.ui = _UI(self.script) if callable(prepare): prepare(self.application, self, self.script, data) children = self.stage.get_children() main_actor = self.script.get_object("main") if children: self.input_group.stop_middleware() old_child = children[0] self.stage.replace_child(old_child, main_actor) else: self.stage.add_child(main_actor) self.input_group.load_content(main_actor)
print "extrude" def jog_e_retract(self, btn, etc=None, other=None): print "retract" def jog_e_toggle(self, btn, etc=None, other=None): print "Toggle e" if __name__ == '__main__': Clutter.init(sys.argv) style = Mx.Style.get_default() style.load_from_file("style/style.css") ui = Clutter.Script() ui.load_from_file("jog-ui.json") class Config: pass config = Config() config.ui = ui Jog(config) _stage = ui.get_object("stage") _stage.set_title("Jog UI") _stage.connect("destroy", lambda w: Clutter.main_quit()) _stage.show_all() Clutter.main()
def _load_script(self): self.script = Clutter.Script() self.script.load_from_file(JSON_PATH) main = self.script.get_object("main") self.stage.add_child(main)
#! /usr/bin/env python3 from gi.repository import Clutter, Mx Clutter.init(None) Mx.Style.get_default().load_from_file('tests.css') script = Clutter.Script() script.load_from_file('buttons.json') stage = script.get_object('stage') stage.show() stage.connect('destroy', lambda *_: Clutter.main_quit()) button = script.get_object('action-button') action = button.get_property('action') i = 0 def activate(a): global i i += 1 a.set_property('display_name', 'Click {}'.format(i)) a.set_property('icon', 'dialog-information') def lab(b):
def __init__(self): self.version = "1.2.1" logging.info("Starting Toggle " + self.version) file_path = os.path.join("/etc/toggle", "local.cfg") if not os.path.exists(file_path): logging.info(file_path + " does not exist, Creating one") os.mknod(file_path) os.chmod(file_path, 0o777) # Parse the config files. config = CascadingConfigParser([ '/etc/toggle/default.cfg', '/etc/toggle/printer.cfg', '/etc/toggle/local.cfg' ]) # Get loglevel from the Config file level = config.getint('System', 'loglevel') if level > 0: logging.getLogger().setLevel(level) sys.stdout = LoggerWriter(config, logging, 20) sys.stderr = LoggerWriter(config, logging, 50) Clutter.init(None) style = Mx.Style.get_default() style.load_from_file(config.get("System", "stylesheet")) config.ui = Clutter.Script() try: config.ui.load_from_file(config.get("System", "ui")) except: print "Error loading UI" import traceback traceback.print_exc() config.stage = config.ui.get_object("stage") config.stage.connect("destroy", self.stop) config.stage.connect('key-press-event', self.key_press) # Set up tabs config.tabs = CubeTabs(config.ui, 4) config.splash = Splash(config) config.splash.set_status("Starting Toggle " + self.version + "...") config.jog = Jog(config) config.temp_graph = TemperatureGraph(config) config.filament_graph = FilamentGraph(config) # Set up SockJS and REST clients host = config.get("Rest", "hostname") config.rest_client = RestClient(config) # Add other stuff config.volume_stage = VolumeStage(config) config.message = Message(config) config.printer = Printer(config) config.loader = ModelLoader(config) config.plate = Plate(config) config.socks_client = WebSocksClient(config, host="ws://" + host + ":5000") # mouse use_mouse = int(config.get('System', 'mouse')) self.cursor = config.ui.get_object("cursor") if use_mouse: config.stage.connect("motion-event", self.mouse_move) logging.info("Mouse is active") else: logging.info("Mouse is not active") self.cursor.set_opacity(0) config.push_updates = JoinableQueue(10) self.config = config config.plate.make_scale() config.stage.show()
def __init__(self): from .__init__ import __version__ logging.info("Initializing Toggle {}".format(__version__)) file_path = os.path.join("/etc/toggle", "local.cfg") if not os.path.exists(file_path): logging.info(file_path + " does not exist, Creating one") os.mknod(file_path) os.chmod(file_path, 0o666) # Parse the config files. config = CascadingConfigParser([ '/etc/toggle/default.cfg', '/etc/toggle/printer.cfg', '/etc/toggle/local.cfg' ]) # Get loglevel from the Config file level = config.getint('System', 'loglevel') if level > 0: logging.getLogger().setLevel(level) sys.stdout = LoggerWriter(config, logging, logging.INFO) sys.stderr = LoggerWriter(config, logging, logging.FATAL) Clutter.init(None) style = Mx.Style.get_default() style.load_from_file(config.get("System", "stylesheet")) config.ui = Clutter.Script() try: config.ui.load_from_file(config.get("System", "ui")) except: print("Error loading UI") import traceback traceback.print_exc() config.stage = config.ui.get_object("stage") config.stage.connect("destroy", self.stop) config.stage.connect('key-press-event', self.key_press) config.screen_width = config.getint("Screen", "width") config.screen_height = config.getint("Screen", "height") config.screen_rot = config.get("Screen", "rotation") config.screen_full = config.getboolean("Screen", "fullscreen") # Set up tabs config.tabs = CubeTabs(config.ui, 4) config.splash = Splash(config) config.splash.set_status("Starting Toggle {} ...".format(__version__)) config.jog = Jog(config) config.temp_graph = TemperatureGraph(config) config.filament_graph = FilamentGraph(config) m = Network.get_manager() if m == "connman": logging.debug("Using Connman") config.network = ConnMan() elif m == "nm": logging.debug("Using NetworkManager") config.network = NetworkManager() else: logging.warning("Neither NetworkManager nor Connman was found") config.Settings = Settings(config) # Set up SockJS and REST clients config.rest_client = RestClient(config) # Add other stuff config.volume_stage = VolumeStage(config) config.message = Message(config) config.printer = Printer(config) config.loader = ModelLoader(config) config.plate = Plate(config) config.socks_client = WebSocksClient(config) # mouse use_mouse = int(config.get('Input', 'mouse')) self.cursor = config.ui.get_object("cursor") if use_mouse: config.stage.connect("motion-event", self.mouse_move) logging.info("Mouse is active") else: config.stage.connect("touch-event", self.mouse_move) logging.info("Mouse is not active, using touch instead") self.cursor.set_opacity(0) config.mouse_invert_x = config.getboolean('Input', 'mouse_invert_x') config.mouse_invert_y = config.getboolean('Input', 'mouse_invert_y') config.mouse_swap = config.getboolean('Input', 'mouse_swap_xy') config.push_updates = JoinableQueue(10) self.config = config config.plate.make_scale() config.stage.show()