From 0c7d73854d37b4bc908545332a58b04493fc5036 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 11 Jan 2012 15:14:59 -0500 Subject: [PATCH] Converted stats_label to objp. --HG-- branch : objp --- .hgignore | 1 + build.py | 24 ++++++++++++++++++++- cocoa/base/PyStatsLabel.h | 14 ------------ cocoa/base/ResultWindow.m | 2 +- cocoa/base/StatsLabel.h | 8 ++++--- cocoa/base/StatsLabel.m | 23 ++++++++++++++------ cocoa/base/bridge/StatsLabelView.h | 5 +++++ cocoa/inter/stats_label.py | 7 +++--- cocoa/se/dg_cocoa.py | 5 +++++ cocoa/se/dupeguru.xcodeproj/project.pbxproj | 23 ++++++++++++++++++-- 10 files changed, 82 insertions(+), 30 deletions(-) delete mode 100644 cocoa/base/PyStatsLabel.h create mode 100644 cocoa/base/bridge/StatsLabelView.h diff --git a/.hgignore b/.hgignore index 1569a994..95f274c4 100644 --- a/.hgignore +++ b/.hgignore @@ -14,6 +14,7 @@ build dist install installer_tmp-cache +cocoa/autogen cocoa/*/Info.plist cocoa/*/build cocoa/*/*.app diff --git a/build.py b/build.py index 1ae901d9..766aa0c4 100644 --- a/build.py +++ b/build.py @@ -17,7 +17,7 @@ from setuptools import setup, Extension from hscommon import sphinxgen from hscommon.build import (add_to_pythonpath, print_and_do, copy_packages, filereplace, - get_module_version, build_all_cocoa_locs, move_all, copy_sysconfig_files_for_embed) + get_module_version, build_all_cocoa_locs, move_all, copy_sysconfig_files_for_embed, copy_all) from hscommon import loc def parse_args(): @@ -38,6 +38,7 @@ def parse_args(): def build_cocoa(edition, dev): build_cocoa_proxy_module() + build_cocoa_bridging_interfaces() print("Building dg_cocoa.plugin") specific_packages = { 'se': ['core_se'], @@ -56,6 +57,8 @@ def build_cocoa(edition, dev): os.mkdir('build/py') sys.path.insert(0, 'build') collect_dependencies('build/dg_cocoa.py', 'build/py', excludes=['PyQt4']) + # Views are not referenced by python code, so they're not found by the collector. + copy_all('build/inter/*.so', 'build/py/inter') del sys.path[0] copy_sysconfig_files_for_embed('build/py') os.chdir(cocoa_project_path) @@ -170,6 +173,25 @@ def build_cocoa_proxy_module(): ) move_all('CocoaProxy*', 'cocoalib/cocoa') +def build_cocoa_bridging_interfaces(): + print("Building Cocoa Bridging Interfaces") + import objp.o2p + import objp.p2o + add_to_pythonpath('cocoa') + add_to_pythonpath('cocoalib') + from inter.stats_label import PyStatsLabel + objp.o2p.generate_objc_code(PyStatsLabel, 'cocoa/autogen') + objp.p2o.generate_python_proxy_code('cocoa/base/bridge/StatsLabelView.h', 'build/StatsLabelView.m') + exts = [ + Extension("StatsLabelView", ['build/StatsLabelView.m', 'build/ObjP.m'], + extra_link_args=["-framework", "Foundation"]), + ] + setup( + script_args = ['build_ext', '--inplace'], + ext_modules = exts, + ) + move_all('StatsLabelView*', 'cocoa/inter') + def build_pe_modules(ui): print("Building PE Modules") exts = [ diff --git a/cocoa/base/PyStatsLabel.h b/cocoa/base/PyStatsLabel.h deleted file mode 100644 index f9c50526..00000000 --- a/cocoa/base/PyStatsLabel.h +++ /dev/null @@ -1,14 +0,0 @@ -/* -Copyright 2011 Hardcoded Software (http://www.hardcoded.net) - -This software is licensed under the "BSD" License as described in the "LICENSE" file, -which should be included with this package. The terms are also available at -http://www.hardcoded.net/licenses/bsd_license -*/ - -#import -#import "PyGUI.h" - -@interface PyStatsLabel : PyGUI -- (NSString *)display; -@end \ No newline at end of file diff --git a/cocoa/base/ResultWindow.m b/cocoa/base/ResultWindow.m index 7fcb339a..3a4e53ec 100644 --- a/cocoa/base/ResultWindow.m +++ b/cocoa/base/ResultWindow.m @@ -25,7 +25,7 @@ http://www.hardcoded.net/licenses/bsd_license /* Put a cute iTunes-like bottom bar */ [[self window] setContentBorderThickness:28 forEdge:NSMinYEdge]; table = [[ResultTable alloc] initWithPy:[py resultTable] view:matches]; - statsLabel = [[StatsLabel alloc] initWithPy:[py statsLabel] labelView:stats]; + statsLabel = [[StatsLabel alloc] initWithLabelView:stats]; problemDialog = [[ProblemDialog alloc] initWithPy:py]; [self initResultColumns]; [self fillColumnsMenu]; diff --git a/cocoa/base/StatsLabel.h b/cocoa/base/StatsLabel.h index 1fcfac70..7fbc677d 100644 --- a/cocoa/base/StatsLabel.h +++ b/cocoa/base/StatsLabel.h @@ -7,11 +7,13 @@ http://www.hardcoded.net/licenses/bsd_license */ #import -#import "HSGUIController.h" #import "PyStatsLabel.h" -@interface StatsLabel : HSGUIController {} -- (id)initWithPy:(id)aPy labelView:(NSTextField *)aLabelView; +@interface StatsLabel : NSObject { + PyStatsLabel *py; + NSTextField *view; +} +- (id)initWithLabelView:(NSTextField *)aLabelView; - (PyStatsLabel *)py; - (NSTextField *)labelView; @end \ No newline at end of file diff --git a/cocoa/base/StatsLabel.m b/cocoa/base/StatsLabel.m index 295d4be3..b2ea972b 100644 --- a/cocoa/base/StatsLabel.m +++ b/cocoa/base/StatsLabel.m @@ -6,20 +6,31 @@ which should be included with this package. The terms are also available at http://www.hardcoded.net/licenses/bsd_license */ +#import #import "StatsLabel.h" -#import "Utils.h" +#import "ObjP.h" @implementation StatsLabel -- (id)initWithPy:(id)aPy labelView:(NSTextField *)aLabelView +- (id)initWithLabelView:(NSTextField *)aLabelView { - self = [super initWithPy:aPy view:aLabelView]; - [self connect]; + self = [self init]; + view = [aLabelView retain]; + PyGILState_STATE gilState = PyGILState_Ensure(); + PyObject *pModule = PyImport_AddModule("__main__"); + PyObject *pAppInstance = PyObject_GetAttrString(pModule, "APP_INSTANCE"); + PyObject *pStatsLabel = PyObject_GetAttrString(pAppInstance, "stats_label"); + PyObject *pCallback = ObjP_classInstanceWithRef(@"StatsLabelView", @"inter.StatsLabelView", self); + py = [[PyStatsLabel alloc] initWithModel:pStatsLabel Callback:pCallback]; + PyGILState_Release(gilState); + [[self py] connect]; return self; } - (void)dealloc { - [self disconnect]; + [[self py] disconnect]; + [py release]; + [view release]; [super dealloc]; } @@ -30,7 +41,7 @@ http://www.hardcoded.net/licenses/bsd_license - (NSTextField *)labelView { - return (NSTextField *)[self view]; + return (NSTextField *)view; } /* Python --> Cocoa */ diff --git a/cocoa/base/bridge/StatsLabelView.h b/cocoa/base/bridge/StatsLabelView.h new file mode 100644 index 00000000..5bd6ba6b --- /dev/null +++ b/cocoa/base/bridge/StatsLabelView.h @@ -0,0 +1,5 @@ +#import + +@protocol StatsLabelView +- (void)refresh; +@end \ No newline at end of file diff --git a/cocoa/inter/stats_label.py b/cocoa/inter/stats_label.py index 70203373..16788fde 100644 --- a/cocoa/inter/stats_label.py +++ b/cocoa/inter/stats_label.py @@ -1,5 +1,6 @@ -from cocoa.inter import PyGUIObject +from cocoa.inter2 import PyGUIObject class PyStatsLabel(PyGUIObject): - def display(self): - return self.py.display + + def display(self) -> str: + return self.model.display diff --git a/cocoa/se/dg_cocoa.py b/cocoa/se/dg_cocoa.py index 3f71c71a..7ff792cd 100644 --- a/cocoa/se/dg_cocoa.py +++ b/cocoa/se/dg_cocoa.py @@ -22,10 +22,15 @@ from inter.result_table import PyResultTable from inter.stats_label import PyStatsLabel from inter.app_se import DupeGuru +# XXX temporary hack +APP_INSTANCE = None + class PyDupeGuru(PyDupeGuruBase): def init(self): self = super(PyDupeGuru,self).init() self._init(DupeGuru) + global APP_INSTANCE + APP_INSTANCE = self.py return self #---Properties diff --git a/cocoa/se/dupeguru.xcodeproj/project.pbxproj b/cocoa/se/dupeguru.xcodeproj/project.pbxproj index 3a4ba9db..4447a6a2 100644 --- a/cocoa/se/dupeguru.xcodeproj/project.pbxproj +++ b/cocoa/se/dupeguru.xcodeproj/project.pbxproj @@ -14,6 +14,8 @@ CE18004F14BDD854001B6329 /* Python in CopyFiles */ = {isa = PBXBuildFile; fileRef = CE18004C14BDD837001B6329 /* Python */; }; CE18005114BDD87B001B6329 /* py in Resources */ = {isa = PBXBuildFile; fileRef = CE18005014BDD87B001B6329 /* py */; }; CE19BC6411199231007CCEB0 /* progress.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE19BC6111199231007CCEB0 /* progress.xib */; }; + CE1D091814BE0C6400CA6B8C /* ObjP.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1D091514BE0C6400CA6B8C /* ObjP.m */; }; + CE1D091914BE0C6400CA6B8C /* PyStatsLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = CE1D091714BE0C6400CA6B8C /* PyStatsLabel.m */; }; CE27D3C412CCA43800859E67 /* HSAboutBox.m in Sources */ = {isa = PBXBuildFile; fileRef = CE27D3C312CCA43800859E67 /* HSAboutBox.m */; }; CE31819D13D85D9B00B6D649 /* about.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE31819913D85D9B00B6D649 /* about.xib */; }; CE31819E13D85D9B00B6D649 /* ErrorReportWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE31819B13D85D9B00B6D649 /* ErrorReportWindow.xib */; }; @@ -123,6 +125,10 @@ CE18004C14BDD837001B6329 /* Python */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = Python; path = ../../build/Python; sourceTree = ""; }; CE18005014BDD87B001B6329 /* py */ = {isa = PBXFileReference; lastKnownFileType = folder; name = py; path = ../../build/py; sourceTree = ""; }; CE19BC6111199231007CCEB0 /* progress.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = progress.xib; sourceTree = ""; }; + CE1D091414BE0C6400CA6B8C /* ObjP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjP.h; sourceTree = ""; }; + CE1D091514BE0C6400CA6B8C /* ObjP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjP.m; sourceTree = ""; }; + CE1D091614BE0C6400CA6B8C /* PyStatsLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PyStatsLabel.h; sourceTree = ""; }; + CE1D091714BE0C6400CA6B8C /* PyStatsLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PyStatsLabel.m; sourceTree = ""; }; CE27D3C212CCA43800859E67 /* HSAboutBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HSAboutBox.h; path = ../../cocoalib/HSAboutBox.h; sourceTree = SOURCE_ROOT; }; CE27D3C312CCA43800859E67 /* HSAboutBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HSAboutBox.m; path = ../../cocoalib/HSAboutBox.m; sourceTree = SOURCE_ROOT; }; CE31819A13D85D9B00B6D649 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = ../en.lproj/about.xib; sourceTree = ""; }; @@ -214,7 +220,6 @@ CE89240914239CC30024CE4E /* PyPrioritizeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PyPrioritizeList.h; path = ../base/PyPrioritizeList.h; sourceTree = ""; }; CE8C53B61173248F0011B41F /* PyTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PyTable.h; sourceTree = ""; }; CE8C53BB117324CE0011B41F /* HSTable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HSTable.m; sourceTree = ""; }; - CE91F210113BC22D0010360B /* PyStatsLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PyStatsLabel.h; path = ../base/PyStatsLabel.h; sourceTree = SOURCE_ROOT; }; CE91F213113BC22D0010360B /* StatsLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StatsLabel.h; path = ../base/StatsLabel.h; sourceTree = SOURCE_ROOT; }; CE91F214113BC22D0010360B /* StatsLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StatsLabel.m; path = ../base/StatsLabel.m; sourceTree = SOURCE_ROOT; }; CE9777CB141F8C2500C13FB5 /* PrioritizeDialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PrioritizeDialog.h; path = ../base/PrioritizeDialog.h; sourceTree = ""; }; @@ -384,6 +389,18 @@ path = ../../cocoalib/xib; sourceTree = SOURCE_ROOT; }; + CE1D091314BE0C6400CA6B8C /* autogen */ = { + isa = PBXGroup; + children = ( + CE1D091414BE0C6400CA6B8C /* ObjP.h */, + CE1D091514BE0C6400CA6B8C /* ObjP.m */, + CE1D091614BE0C6400CA6B8C /* PyStatsLabel.h */, + CE1D091714BE0C6400CA6B8C /* PyStatsLabel.m */, + ); + name = autogen; + path = ../autogen; + sourceTree = ""; + }; CE76FDBD111EE37C006618EA /* views */ = { isa = PBXGroup; children = ( @@ -495,10 +512,10 @@ CEFC7FB00FC9518F00CD5728 /* dgbase */ = { isa = PBXGroup; children = ( + CE1D091314BE0C6400CA6B8C /* autogen */, CE6DD4E4124CA3070089A48D /* PyResultTable.h */, CE6DD4E5124CA3070089A48D /* ResultTable.h */, CE6DD4E6124CA3070089A48D /* ResultTable.m */, - CE91F210113BC22D0010360B /* PyStatsLabel.h */, CE91F213113BC22D0010360B /* StatsLabel.h */, CE91F214113BC22D0010360B /* StatsLabel.m */, CE76FDD1111EE3A7006618EA /* DirectoryOutline.h */, @@ -658,6 +675,8 @@ CE89240A14239CC30024CE4E /* PrioritizeList.m in Sources */, CE5335FC142BBFAF008E5374 /* HSQuicklook.m in Sources */, CE54A87E148046F9008EEA77 /* HSColumns.m in Sources */, + CE1D091814BE0C6400CA6B8C /* ObjP.m in Sources */, + CE1D091914BE0C6400CA6B8C /* PyStatsLabel.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };