Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Bitte an Programmierer

Allgemeines zum Thema EventGhost
Post Reply
ze_sniper1
Posts: 29
Joined: Sat Aug 19, 2006 2:50 pm

Bitte an Programmierer

Post by ze_sniper1 »

Hallo,

habe seid langer Zeit wieder mal eine aktuelle Version von Event Ghost geladen.
Leider funktioniert ein Plugin, dass mir seinerzeit ein Bekannter geschrieben hat, nicht mehr.
Eigentlich sind es zwei Plugins. Aber f├╝r den Anfang reicht mal eines :wink:

Hier der Code:

Code: Select all

import asynchat, asyncore, md5, random, socket, string

import wx
import wx.lib.intctrl as IntCtrl

import eg


class Text:
    port = "Port:"
    password = "Password:"
    event_prefix = "Event Prefix:"
    


class Server_Handler (asynchat.async_chat):
    """Telnet engine class. Implements command line user interface."""
    
    def __init__ (self, sock, addr, hex_md5, cookie, handler, server_ref):
        self.handler = handler
        self.server_ref = server_ref
        
        # Call constructor of the parent class
        asynchat.async_chat.__init__(self, sock)

        # Set up input line terminator
        self.set_terminator('\n')

        # Initialize input data buffer
        self.data = ''
        self.state = self.state1
	self.ip = addr[0]
        self.payload = [self.ip]
        self.hex_md5 = hex_md5
        self.cookie = cookie
	                
    def handle_close(self):
        self.handler.EndLastEvent()
        asynchat.async_chat.handle_close(self)
    
    
    def collect_incoming_data (self, data):
        """Put data read from socket to a buffer
        """
        # Collect data in input buffer
	self.data = self.data + data


    def found_terminator (self):
        """This method is called by asynchronous engine when it finds
           command terminator in the input stream
        """   
	
        # Take the complete line
        line = self.data

        # Reset input buffer
        self.data = ''

        #call state handler
        self.state(line)


    def initiate_close(self):
	if self.writable():
            self.push("close\n")
        self.handler.EndLastEvent()
        self.state = self.state1
 

    def state1(self, line):
        """get keyword "quintessence\n"
           and send cookie
        """
        if line.startswith("quintessence"):
            self.state = self.state3
            self.push("accept\n")
        else:
            self.initiate_close()
                
                
    def state2(self, line):
        """get md5 digest
        """
        line = string.strip(line)[-32:]
        if line == "":
            pass
        elif line.upper() == self.hex_md5:
            self.push("accept\n")
            self.state = self.state3
        else:
            eg.PrintError("NetworkReceiver md5 error")
            self.initiate_close()
            
            
    def state3(self, line):
	line = line.strip()
        if line == "close":
            self.initiate_close()
        elif line[:8] == "payload ":
            self.payload.append(line[8:])
        else:
            if line == "ButtonReleased":
                self.handler.EndLastEvent()
            else:
                if self.payload[-1] == "withoutRelease":
                    self.handler.TriggerEnduringEvent(line, self.payload)
                else:
                    self.handler.TriggerEvent(line, self.payload)
            self.payload = [self.ip]
            
            

class Server(asyncore.dispatcher):
    
    def __init__ (self, port, password, handler):
        self.handler = handler
        m = md5.new()
        self.cookie = hex(random.randrange(65536))
        self.cookie = self.cookie[len(self.cookie) - 4:]
        m.update(self.cookie + ":" + password)
        self.hex_md5 = m.hexdigest().upper()

        # Call parent class constructor explicitly
        asyncore.dispatcher.__init__(self)
        
        # Create socket of requested type
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)

        # Set it to re-use address
        self.set_reuse_addr()
        
        # Bind to all interfaces of this host at specified port
        self.bind(('', port))
        
        # Start listening for incoming requests
        self.listen(5)


    def handle_accept (self):
        """Called by asyncore engine when new connection arrives"""
        # Accept new connection
        (sock, addr) = self.accept()
        Server_Handler(sock, addr, self.hex_md5, self.cookie, self.handler, self)



class NetworkReceiverToolsack(eg.PluginClass):
    canMultiLoad = True
    text = Text
    
    def __start__(self, port, password, prefix):
        self.port = port
        self.password = password
        self.info.eventPrefix = prefix
        self.server = Server(self.port, self.password, self)
        
        
    def __stop__(self):
        if self.server:
            self.server.close()
        self.server = None


    def Configure(self, port=1024, password="", prefix="TCP"):
        text = self.text
        dialog = eg.ConfigurationDialog(self)
        text1 = wx.StaticText(dialog, -1, text.port)
        ctrl1 = IntCtrl.IntCtrl(dialog, -1, port)
        text2 = wx.StaticText(dialog, -1, text.password)
        ctrl2 = wx.TextCtrl(dialog, -1, password, style=wx.TE_PASSWORD)
        text3 = wx.StaticText(dialog, -1, text.event_prefix)
        ctrl3 = wx.TextCtrl(dialog, -1, prefix)
        
        mySizer = wx.FlexGridSizer(cols=2)
        mySizer.Add(text1, 0, wx.EXPAND|wx.ALL, 5)
        mySizer.Add(ctrl1, 0, wx.EXPAND|wx.ALL, 5)
        mySizer.Add(text2, 0, wx.EXPAND|wx.ALL, 5)
        mySizer.Add(ctrl2, 0, wx.EXPAND|wx.ALL, 5)
        mySizer.Add(text3, 0, wx.EXPAND|wx.ALL, 5)
        mySizer.Add(ctrl3, 0, wx.EXPAND|wx.ALL, 5)

        dialog.sizer.Add(mySizer)
        
        if dialog.AffirmedShowModal():
            return ctrl1.GetValue(), ctrl2.GetValue(), ctrl3.GetValue()

Ich vermude mal das hängt mit der Umstellung auf Phyton 2.6 zusammen, oder?
Ich selber bin programmiertechnisch was Phyton angeht eine Niete. Mein Bekannter von damals ist leider nicht mehr greifbar.

Bitte um Hilfe

mfg
ze_sniper1
Prinz
Plugin Developer
Posts: 194
Joined: Mon Apr 07, 2008 4:58 am

Re: Bitte an Programmierer

Post by Prinz »

-------> PM
Mein HTPC:
Mainboard: Gigabyte GA-G33M-DS2R
CPU: Intel E5200
OS: WinXP SP3
Graphic card: NVIDIA GeForce 210 512MB
TV-Cards: 2 * Digital Everywhere FloppyDTV-C, Terratec Cinergy 1200 DVB-C
HTPC software: DVB Viewer / EventGhost
Post Reply