Advertisement
goon357

Untitled

Jul 13th, 2020
1,313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.43 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. #!/usr/bin/env python
  6. """
  7. integrator.py (the app)
  8. """
  9.  
  10. import wx
  11. from pubsub import pub
  12. from flask import Flask
  13. from flask_graphql import GraphQLView
  14. from models import db_session
  15. from schema import schema
  16. from models import engine, db_session, Base, Idiom
  17.  
  18. flaskapp = Flask(__name__)
  19. flaskapp.debug = True
  20. flaskapp.add_url_rule(
  21.         '/graphql',
  22.         view_func=GraphQLView.as_view(
  23.             'graphql',
  24.             schema=schema,
  25.             graphiql=True
  26.         )
  27. )
  28.  
  29. flaskapp.run(threaded=True,use_reloader=False)
  30.  
  31. @flaskapp.teardown_appcontext
  32. def shutdown_session(exception=None):
  33.     db_session.remove()
  34.  
  35.  
  36. class IntegratorTarget(wx.TextDropTarget):
  37.     def __init__(self, object):
  38.         wx.DropTarget.__init__(self)
  39.         self.object = object  
  40.        
  41.     def OnDropText(self, x, y, data):
  42.         print(f"<publish>{data}</publish>")
  43.         pub.sendMessage('default', arg1=data)
  44.         return True
  45.  
  46.        
  47. class IntegratorFrame(wx.Frame):
  48.     def __init__(self, parent, title):
  49.         super(IntegratorFrame, self).__init__(parent, title = title,size = wx.DisplaySize())  
  50.         self.panel = wx.Panel(self)
  51.         box = wx.BoxSizer(wx.HORIZONTAL)  
  52.              
  53.         dropTarget = IntegratorTarget(self.panel)
  54.         self.panel.SetDropTarget(dropTarget)
  55.         pub.subscribe(self.catcher, 'default')
  56.        
  57.         self.panel.SetSizer(box)
  58.         self.panel.Fit()
  59.         self.Centre()
  60.         self.Show(True)
  61.  
  62.     def catcher(self,arg1):
  63.         data = arg1
  64.         print(f"<subscribed>{data}</subscribed>\n\n")
  65.         return
  66.      
  67.        
  68. ex = wx.App()
  69.  
  70. Base.metadata.create_all(bind=engine)
  71.  
  72. IntegratorFrame(None,'Praxis:Integrator')
  73. ex.MainLoop()
  74.  
  75. -- eof --
  76.  
  77. """ models.py """
  78.  
  79. from sqlalchemy import *
  80. from sqlalchemy.orm import (scoped_session, sessionmaker, relationship, backref)
  81. from sqlalchemy.ext.declarative import declarative_base
  82.  
  83. engine = create_engine('sqlite:///.praxis/lexicon/unbound.db3', convert_unicode=True)
  84. db_session = scoped_session(sessionmaker(autocommit=False,
  85.                                          autoflush=False,
  86.                                          bind=engine))
  87.  
  88. Base = declarative_base()
  89. # We will need this for querying
  90. Base.query = db_session.query_property()
  91.  
  92. class Idiom(Base):
  93.     __tablename__ = "idiomae"
  94.     id = Column(Integer, primary_key=True)
  95.     src = Column(String)                        # the text of the drag/paste operation
  96.     taxonomy = Column(String)                   # the type of resource referenced in the drag/paste operation
  97.     localblob = Column(String)                  # local path to media referenced in 'src'
  98.     timestamp = Column(DateTime)                # date and time of capture
  99.  
  100. -- eof --
  101.  
  102.  
  103. """  schema.py  """
  104.  
  105. import graphene
  106. from graphene import relay
  107. from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
  108. from models import db_session, Idiom as IdiomaticModel
  109.  
  110.  
  111. class Idiom(SQLAlchemyObjectType):
  112.     class Meta:
  113.         model = IdiomaticModel
  114.         interfaces = (relay.Node, )
  115.  
  116.  
  117. class Query(graphene.ObjectType):
  118.     node = relay.Node.Field()
  119.     # Allows sorting over multiple columns, by default over the primary key
  120.     all_idioms = SQLAlchemyConnectionField(Idiom.connection)
  121.     # Disable sorting over this field
  122.     # all_departments = SQLAlchemyConnectionField(Department.connection, sort=None)
  123.  
  124. schema = graphene.Schema(query=Query)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement