Example #1
0
	def run(self):
		self.app = NSApplication.sharedApplication()
		self.app.setDelegate_(self)
		
		nib = NSNib.alloc().initWithContentsOfURL_(NSURL.fileURLWithPath_(os.path.dirname(__file__) + '/cocoa_util/MainMenu.nib'))
		nib.instantiateNibWithOwner_topLevelObjects_(self, None)
		
		origin = [100,200]
		size = [800,600]
		self.view = WebView.alloc().initWithFrame_frameName_groupName_(NSMakeRect(0,0, *size), None, None)
		self.view.setAutoresizingMask_(NSViewHeightSizable | NSViewWidthSizable)
		self.view.setPolicyDelegate_(self)
		
		self.htmlView = self.view.mainFrame()
		self.scroll_keeper = ScrollKeeper(self.htmlView)
		self.view.setFrameLoadDelegate_(self)
		window_mask = NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
		window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
			NSMakeRect(*(origin + size)), window_mask, NSBackingStoreBuffered, True)
		window.setTitle_("Autonose")
		self.doUpdate("<h1>loading...</h1>")
		
		window.contentView().addSubview_(self.view)
		window.makeKeyAndOrderFront_(None)
		self.app.activateIgnoringOtherApps_(True)
		try:
			self.app.run()
		except KeyboardInterrupt:
			self.doExit()
Example #2
0
    def applicationDidFinishLaunching_(self, aNotification):
        self.webView = WebView.alloc().initWithFrame_(((0, 0), (1, 1)))
        
        self.loadDelegate = LoadDelegate.alloc().init()
        self.webView.setFrameLoadDelegate_(self.loadDelegate)

        request = NSURLRequest.requestWithURL_(NSURL.URLWithString_(self.url))
        self.webView.mainFrame().loadRequest_(request)
Example #3
0
def renderTemplate(webView: WebView, name: str, **values):
    html = render_template(name, **values)
    frame = webView.mainFrame()
    resource_path = os.environ.get('RESOURCEPATH', os.path.dirname(__file__))
    logger.debug('resource_path = %r', resource_path)
    baseUrl = NSURL.fileURLWithPath_(
        os.path.join(resource_path, 'static', '')
    )
    frame.loadHTMLString_baseURL_(html, baseUrl)
Example #4
0
    def __init__(self):

        self.debug = False

        # Glyph and font data
        self.glyph = None
        self.LIBKEY = "com.andyclymer.zPosition"
        self.pointData = {}  # dict of x,y,z for each pointID

        self.tempPath = tempfile.mkstemp()[1]
        self.tempHTMLPath = self.tempPath + ".html"

        self.w = vanilla.Window((620, 740),
                                "3D Projection Preview",
                                autosaveName="ProjectionPreview")
        self.w.bind("resize", self.windowResizedCallback)

        topHeight = 65
        self.w.refreshButton = vanilla.SquareButton(
            (10, 10, 130, 25),
            "Reload glyph data",
            callback=self.refreshPreviewCallback,
            sizeStyle="small")

        x = 150
        self.w.zoomScaleChoice = vanilla.PopUpButton(
            (x, 10, 70, 25), ["50%", "75%", "100%", "150%"],
            sizeStyle="small",
            callback=self.refreshPreviewCallback)
        self.w.zoomScaleChoice.set(2)
        self.w.strokeWidth = vanilla.EditText((x + 90, 10, 40, 25), "90")
        self.w.strokeWidth.enable(False)
        self.w.doStrokeBox = vanilla.CheckBox(
            (x + 140, 10, 100, 25),
            "Stroke",
            sizeStyle="small",
            value=False,
            callback=self.refreshPreviewCallback)

        self.w.note = vanilla.TextBox(
            (10, 43, -10, 25),
            "Note: Requires an internet connection for the Zdog library to load, http://www.zzz.dog/",
            sizeStyle="small")

        # Web view
        self.w.webView = WebView.alloc().initWithFrame_(((0, 0), (500, 500)))
        self.w.scroll = vanilla.ScrollView((10, topHeight, -10, -10),
                                           self.w.webView,
                                           hasHorizontalScroller=False,
                                           hasVerticalScroller=False)

        self.w.open()
        self.refreshPreviewCallback(None)
Example #5
0
def main():
    # Create a new application instance ...
    a=NSApplication.sharedApplication()
    # ... and create its delgate.  Note the use of the
    # Objective C constructors below, because Delegate
    # is a subcalss of an Objective C class, NSObject
    delegate = Delegate.alloc().init()
    # Tell the application which delegate object to use.
    a.setDelegate_(delegate)

    # Now we can can start to create the window ...
    #screen = NSScreen.mainScreen()
    #frame = screen.frame()
    #frame.size.width = 1000
    #frame.size.height = 600
    frame = ((200.0, 300.0), (250.0, 100.0))
    # (Don't worry about these parameters for the moment. They just specify
    # the type of window, its size and position etc)
    s = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
    b = NSBackingStoreBuffered
    d = False
    w = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(frame, s, b, d)
    # ... tell it which delegate object to use (here it happens
    # to be the same delegate as the application is using)...
    w.setDelegate_(delegate)
    # ... and set some properties. Unicode strings are preferred.
    w.setTitle_(u'Hello, World!')
    # All set.  Now we can show the window ...
    w.makeKeyAndOrderFront_(w)
    # ... and start the application


    # Webview: Optional part of this sample
    rect = Foundation.NSMakeRect(100,350,600,800)
    webview = WebView.alloc()
    webview.initWithFrame_(rect)
    win = webview.windowScriptObject()
    win.evaluateWebScript_("""
            function sayHi() {
                return "Hello from hi.js";
            }
        """)
    str = win.evaluateWebScript_("sayHi();")
    print(str)
    AppHelper.runEventLoop()
Example #6
0
    def initWithFrame_controller_(self, frame, controller):
        self = WebView.initWithFrame_frameName_groupName_(self, frame, controller.__xui_resource__ + '_main', None)
        if self is None:
            return
        self.setMaintainsBackForwardList_(objc.NO)
        self.setEditable_(objc.NO)
        self.setPreferencesIdentifier_('DropboxXUI')
        preferences = self.preferences()
        preferences.setAutosaves_(objc.NO)
        preferences.setPlugInsEnabled_(objc.NO)
        preferences.setJavaEnabled_(objc.NO)
        preferences.setJavaScriptCanOpenWindowsAutomatically_(objc.NO)
        preferences.setUserStyleSheetEnabled_(objc.NO)
        preferences.setCacheModel_(WebCacheModelDocumentViewer)
        preferences.setTabsToLinks_(objc.YES)
        report_webkit_version()
        if MAC_VERSION >= MOUNTAIN_LION:
            try:
                preferences.setSuppressesIncrementalRendering_(objc.YES)
            except AttributeError:
                pass
            except Exception:
                unhandled_exc_handler()

        if MAC_VERSION >= SNOW_LEOPARD:
            try:
                preferences.setAcceleratedCompositingEnabled_(CocoaSettings.is_accelerated_compositing_supported())
            except AttributeError:
                pass
            except Exception:
                unhandled_exc_handler()

        XUIHost.__init__(self, controller)
        self.theDelegate = WebViewDelegate.alloc().initWithHost_(self)
        self.setFrameLoadDelegate_(self.theDelegate)
        self.setUIDelegate_(self.theDelegate)
        self.setPolicyDelegate_(self.theDelegate)
        self.mainFrame().frameView().setAllowsScrolling_(objc.NO)
        data = controller._get_view_data().encode('utf-8')
        self.mainFrame().loadHTMLString_baseURL_(data, NSURL.URLWithString_('about:xui'))
        self.mainTrackingArea = None
        return self