当前位置: 首页>>代码示例>>Python>>正文


Python Network.get_clipboard方法代码示例

本文整理汇总了Python中network.Network.get_clipboard方法的典型用法代码示例。如果您正苦于以下问题:Python Network.get_clipboard方法的具体用法?Python Network.get_clipboard怎么用?Python Network.get_clipboard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在network.Network的用法示例。


在下文中一共展示了Network.get_clipboard方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_connect

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_clipboard [as 别名]
    def test_connect(self):
        port1 = random.randint(20000, 30000)
        port2 = random.randint(20000, 30000)
        n1 = Network(port1)
        n2 = Network(port2)
        n1.start()
        n2.start()
        time.sleep(WAIT_TIME)

        m = 'hasdgbaeswbjf'
        n2.set_clipboard(m)
        time.sleep(WAIT_TIME)

        n1.connect('localhost', port2)
        time.sleep(WAIT_TIME)

        self.assertEqual(m, n1.get_clipboard())

        n1.stop()
        n2.stop()
开发者ID:syncboard,项目名称:syncboard,代码行数:22,代码来源:test_network.py

示例2: TestSimple

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_clipboard [as 别名]
class TestSimple(unittest.TestCase):
    def setUp(self):
        self.port1 = random.randint(20000, 30000)
        self.port2 = random.randint(20000, 30000)
        self.n1 = Network(self.port1)
        self.n2 = Network(self.port2)
        self.n1.start()
        self.n2.start()

        # give everything time to get going
        time.sleep(WAIT_TIME)

        # establish connection
        self.n2.connect('localhost', self.port1)
        time.sleep(WAIT_TIME)

    # test simple clipboard syncing
    def test_simple(self):
        m1 = 'test 1'
        self.n2.set_clipboard(m1)
        time.sleep(WAIT_TIME)

        self.assertEqual(self.n1.get_clipboard(), m1)

        m2 = 'test 2'
        self.n1.set_clipboard(m2)
        time.sleep(WAIT_TIME)

        self.assertEqual(self.n2.get_clipboard(), m2)

    def test_disconnect_from_client(self):
        self.n2.set_clipboard('test')
        time.sleep(WAIT_TIME)
        self.assertEqual(self.n1.get_clipboard(), 'test')

        self.n2.disconnect('localhost')
        time.sleep(WAIT_TIME)

        m = "test %d" % random.randint(0, 1000)
        self.n2.set_clipboard(m)
        time.sleep(WAIT_TIME)

        self.assertNotEqual(self.n1.get_clipboard(), m)

    def test_disconnect_from_server(self):
        self.n2.set_clipboard('test')
        time.sleep(WAIT_TIME)
        self.assertEqual(self.n1.get_clipboard(), 'test')

        self.n1.disconnect('localhost')
        time.sleep(WAIT_TIME)

        m = "test %d" % random.randint(0, 1000)
        self.n2.set_clipboard(m)
        time.sleep(WAIT_TIME)

        self.assertNotEqual(self.n1.get_clipboard(), m)

    def test_reconnect(self):
        self.n2.disconnect('localhost')
        time.sleep(WAIT_TIME)
        self.n1.connect('localhost', self.port2)
        time.sleep(WAIT_TIME)

        self.n1.set_clipboard('asdf 5')
        time.sleep(WAIT_TIME)
        self.assertEqual(self.n2.get_clipboard(), 'asdf 5')

    def tearDown(self):
        # give it enough time to execute before tearing down
        time.sleep(WAIT_TIME)
        self.n1.stop()
        self.n2.stop()
开发者ID:syncboard,项目名称:syncboard,代码行数:75,代码来源:test_network.py

示例3: __init__

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_clipboard [as 别名]
class Session:
    def __init__(self):
        # TODO: consider saving and loading the connections list to a file
        #       to preserve the list between sessions
        self._con_mgr = ConnectionManager()

        # The data on the common clipboard.
        self._clipboard_data = None
        # Type of data on the clipboard (eg. text, bitmap, etc.)
        # This should be one of the supported types in info.py
        self._data_type = None
        # None will mean that this client is owner, otherwise it should be a
        # Connection object.
        self._data_owner = None

        # TODO add command line switch to change port, which would be passed in
        # here
        self._network = Network(con_callback=self._new_connection_request,
                                dis_callback=self._disconnect_request)
        self._network.start()

    def _new_connection_request(self, address, port):
        conn = self._con_mgr.get_connection(address)
        if conn:
            #conn.status = Connection.REQUEST
            conn.status = Connection.CONNECTED
        else:
            #self._con_mgr.new_connection("", address, Connection.REQUEST)
            self._con_mgr.new_connection("", address, Connection.CONNECTED)

    def _disconnect_request(self, address, port):
        conn = self._con_mgr.get_connection(address)
        if conn:
            conn.status = Connection.NOT_CONNECTED

    def get_clipboard_data(self):
        self._clipboard_data = self._network.get_clipboard()
        return self._clipboard_data

    def get_clipboard_data_type(self):
        self._data_type = self._network.get_clipboard_data_type()
        return self._data_type

    def get_clipboard_data_owner(self):
        return self._data_owner

    def set_clipboard_data(self, data, data_type):
        """
            This is called (by the gui) when the user pastes to the app.
        """
        self._clipboard_data = data
        self._network.set_clipboard(self._clipboard_data)
        self._data_type = data_type
        self._data_owner = None

    def connections(self):
        """
            Returns a list of all the connections
        """
        return self._con_mgr.connections

    def get_connection(self, address):
        """
            Returns the Connection object that has the given address
        """
        return self._con_mgr.get_connection(address)

    def new_connection(self, alias, address):
        """
            Creates a new Connection to the given address and if there is
            a Syncboard app running at that address then that user will
            see a new connection appear (with the address on this end) with
            status REQUEST.

            After this has executed:
            New Connection on both ends.
            Connection on this end status: PENDING
            Conneciton on other end status: REQUEST
        """
        self._network.connect(address)
        self._con_mgr.new_connection(alias, address)

    def accept_connection(self, address):
        """
            Called when the user accepts the request from the Connection with
            the given address. Meaning, there was a Connection with status
            REQUEST and user accepted it.

            Before this is called:
            Connection on this end status: REQUEST
            Conneciton on other end status: PENDING

            After this has executed:
            Connection on this end status: CONNECTED
            Conneciton on other end status: CONNECTED
        """
        conn = self.get_connection(address)
        if conn:
            print "Connection from %s accepted" % address
            conn.status = Connection.CONNECTED
#.........这里部分代码省略.........
开发者ID:syncboard,项目名称:syncboard,代码行数:103,代码来源:session.py


注:本文中的network.Network.get_clipboard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。