def __init__(self, hostname, address, portNumber, container): logging.debug('Creating new MatrixDisplay object') self.hatSize = 8 self.imageSize = 1000 self.hostname = hostname self.address = address self.portNumber = portNumber self.sweepx = 1 self.sweepy = 1 self.cancellable = Gio.Cancellable.new() self.runPublisher = False self.timeoutSource = None # Use cairo to do the matrix stuff self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.imageSize, self.imageSize) self.context = cairo.Context(self.surface) # Create gtk stuff builder = Gtk.Builder.new_from_resource('/uk/co/beardandsandals/UnicornEmu/remotehost.ui') builder.connect_signals(self) self.frame = builder.get_object('unicornemuRemoteHost') self.drawingArea = builder.get_object('drawingArea') self.tcolours = {'r': (1, 0, 0), 'red': (1, 0, 0), 'g': (0, 1, 0), 'green': (0, 1, 0), 'b': (0, 0, 1), 'blue': (0, 0, 1), 'c': (0, 1, 1), 'cyan': (0, 1, 1), 'm': (1, 0, 1), 'magenta': (1, 0, 1), 'y': (1, 1, 0), 'yellow': (1, 1, 0), 'w': (1, 1, 1), 'white': (1, 1, 1), '0': (0, 0, 0), 'off': (0, 0, 0), '1': (1, 1, 1), 'on': (1, 1, 1), 'z': (0, 0, 0), 'invert': (0, 0, 0), 'random' : (0,0,0)} self.lastColour = (0,0,0) if hostname == 'localhost': self.hostname_for_title = GLib.get_host_name() self.drawingArea.set_size_request(500, 500) else: self.hostname_for_title = hostname self.drawingArea.set_size_request(100, 100) container.pack_start(self.frame, True, True, 0) logging.debug('Surface matrix') self.context.scale(float(self.surface.get_width()) / self.hatSize, -float(self.surface.get_height()) / self.hatSize) self.context.translate(-1, -(self.hatSize + 1)) logmatrix(logging.debug, self.context.get_matrix()) for x in range(1,self.hatSize + 1): for y in range(1,self.hatSize + 1): self.context.set_source_rgba(random.random(), random.random(), random.random()) self.context.rectangle(x, y, 1, 1) self.context.fill() self.update() # Connect to scratch self.socketClient = Gio.SocketClient.new() # Keep this hanging about in case of time outs etc. logging.debug('Started connection process') if len(self.address) > 0: self.socketClient.connect_to_host_async(self.address, self.portNumber, self.cancellable, self.connect_to_host_async_callback, None) else: self.socketClient.connect_to_host_async(self.hostname, self.portNumber, self.cancellable, self.connect_to_host_async_callback, None)
def get_host_name(): name = GLib.get_host_name() utf8_name = None if name: utf8_name = nofail_locale_to_utf8(name) return utf8_name
def client_status(self, message): entry = self.shell_player.get_playing_entry() if entry: m = self.entry_details(entry) self.set_playing_position(m) p = self.shell_player.get_playing() m['playing'] = p[1] else: m = { 'playing': False, 'id': 0 } m['hostname'] = GLib.get_host_name() return m
def __init__(self): conf = {} conf_dir = os.path.join(GLib.get_user_config_dir(), "pysyncthing") conf_path = os.path.join(conf_dir, "conf.json") logger.debug("Looking for config in %s", conf_path) if os.path.exists(conf_path): with open(conf_path) as fp: conf = json.load(fp) self.name = conf.get("name", GLib.get_host_name()) logger.debug("Local device is called %s", self.name) # FIXME: Generate and store certs in GNOME-keyring ensure_certs() self.certificate = Gio.TlsCertificate.new_from_files("client.crt", "client.key") pem = self.certificate.get_property("certificate-pem") self.device_fingerprint = get_fingerprint(pem) pem = self.certificate.get_property("certificate-pem") self.device_id = get_device_id(pem) self.server = SyncServer(self) self.discovery = [ AnnounceLocal(self), DiscoverLocal(self), ] self.devices = {} for device in conf.get("devices", []): self.add_pair(device["id"]) self.folders = [] for folder in conf.get("folders", []): self.folders.append(Folder( folder["name"], folder["path"], [self.devices[device] for device in folder["devices"] if device in folder["devices"]], ))
def __init__(self, application, *args): # Constants self.localHostname = GLib.get_host_name() # Local variables self.zeroconfToThumbnailMap = {} # indexed by zeoconf domain and name # Set up the gui self.builder = Gtk.Builder.new_from_resource('/uk/co/beardandsandals/UnicornEmu/unicornemu.ui') self.builder.connect_signals(self) mainWindow = self.builder.get_object('unicornEmuApplicationWindow') mainWindow.set_application(application) mainWindow.show() self.primaryMatrix = self.MatrixDisplay(application.hostname, "", 42001, self.builder.get_object('unicornEmuLocalDisplayBox')) self.runZeroconf = False if application.zeroconfSupport: # Run the zeroconf service browser # Easiest to use my own thread. I would really like to integrate this better with GOBject. # More research needed on this self.zeroconfBrowserThread = threading.Thread(target = self.runZeroconfBrowser) self.runZeroconf = True self.zeroconfBrowserThread.start()
def get_user_email(): return "{}@{}".format(GLib.get_user_name(), GLib.get_host_name())
def get_hostname(): return GLib.get_host_name()