Maxmad68 / PyTouchBar

A NSTouchBar Wrapper for Python
GNU General Public License v3.0
46 stars 11 forks source link

Hello World directions #4

Open dregaladodiaz opened 3 years ago

dregaladodiaz commented 3 years ago

I ran testTk() function but my touch bar didn't change at all. Am I missing something? If there is simpler way to run a hello world example, please give me some directions.

python touchbar.py
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.

Hardware Complete MacBook Pro 16-Inch "Core i7" 2.6 2019 Specs

OSX

❯ sw_vers
ProductName:    macOS
ProductVersion: 11.4
BuildVersion:   20F71

I just created a virtual environment an install following requirements requirements.txt

pyobjc==7.3
pyobjc-core==7.3
pyobjc-framework-Accessibility==7.3
pyobjc-framework-Accounts==7.3
pyobjc-framework-AddressBook==7.3
pyobjc-framework-AdServices==7.3
pyobjc-framework-AdSupport==7.3
pyobjc-framework-AppleScriptKit==7.3
pyobjc-framework-AppleScriptObjC==7.3
pyobjc-framework-ApplicationServices==7.3
pyobjc-framework-AppTrackingTransparency==7.3
pyobjc-framework-AuthenticationServices==7.3
pyobjc-framework-AutomaticAssessmentConfiguration==7.3
pyobjc-framework-Automator==7.3
pyobjc-framework-AVFoundation==7.3
pyobjc-framework-AVKit==7.3
pyobjc-framework-BusinessChat==7.3
pyobjc-framework-CalendarStore==7.3
pyobjc-framework-CallKit==7.3
pyobjc-framework-CFNetwork==7.3
pyobjc-framework-ClassKit==7.3
pyobjc-framework-CloudKit==7.3
pyobjc-framework-Cocoa==7.3
pyobjc-framework-Collaboration==7.3
pyobjc-framework-ColorSync==7.3
pyobjc-framework-Contacts==7.3
pyobjc-framework-ContactsUI==7.3
pyobjc-framework-CoreAudio==7.3
pyobjc-framework-CoreAudioKit==7.3
pyobjc-framework-CoreBluetooth==7.3
pyobjc-framework-CoreData==7.3
pyobjc-framework-CoreHaptics==7.3
pyobjc-framework-CoreLocation==7.3
pyobjc-framework-CoreMedia==7.3
pyobjc-framework-CoreMediaIO==7.3
pyobjc-framework-CoreMIDI==7.3
pyobjc-framework-CoreML==7.3
pyobjc-framework-CoreMotion==7.3
pyobjc-framework-CoreServices==7.3
pyobjc-framework-CoreSpotlight==7.3
pyobjc-framework-CoreText==7.3
pyobjc-framework-CoreWLAN==7.3
pyobjc-framework-CryptoTokenKit==7.3
pyobjc-framework-DeviceCheck==7.3
pyobjc-framework-DictionaryServices==7.3
pyobjc-framework-DiscRecording==7.3
pyobjc-framework-DiscRecordingUI==7.3
pyobjc-framework-DiskArbitration==7.3
pyobjc-framework-DVDPlayback==7.3
pyobjc-framework-EventKit==7.3
pyobjc-framework-ExceptionHandling==7.3
pyobjc-framework-ExecutionPolicy==7.3
pyobjc-framework-ExternalAccessory==7.3
pyobjc-framework-FileProvider==7.3
pyobjc-framework-FileProviderUI==7.3
pyobjc-framework-FinderSync==7.3
pyobjc-framework-FSEvents==7.3
pyobjc-framework-GameCenter==7.3
pyobjc-framework-GameController==7.3
pyobjc-framework-GameKit==7.3
pyobjc-framework-GameplayKit==7.3
pyobjc-framework-ImageCaptureCore==7.3
pyobjc-framework-IMServicePlugIn==7.3
pyobjc-framework-InputMethodKit==7.3
pyobjc-framework-InstallerPlugins==7.3
pyobjc-framework-InstantMessage==7.3
pyobjc-framework-Intents==7.3
pyobjc-framework-IOSurface==7.3
pyobjc-framework-iTunesLibrary==7.3
pyobjc-framework-KernelManagement==7.3
pyobjc-framework-LatentSemanticMapping==7.3
pyobjc-framework-LaunchServices==7.3
pyobjc-framework-libdispatch==7.3
pyobjc-framework-LinkPresentation==7.3
pyobjc-framework-LocalAuthentication==7.3
pyobjc-framework-MapKit==7.3
pyobjc-framework-MediaAccessibility==7.3
pyobjc-framework-MediaLibrary==7.3
pyobjc-framework-MediaPlayer==7.3
pyobjc-framework-MediaToolbox==7.3
pyobjc-framework-Metal==7.3
pyobjc-framework-MetalKit==7.3
pyobjc-framework-MetalPerformanceShaders==7.3
pyobjc-framework-MetalPerformanceShadersGraph==7.3
pyobjc-framework-MLCompute==7.3
pyobjc-framework-ModelIO==7.3
pyobjc-framework-MultipeerConnectivity==7.3
pyobjc-framework-NaturalLanguage==7.3
pyobjc-framework-NetFS==7.3
pyobjc-framework-Network==7.3
pyobjc-framework-NetworkExtension==7.3
pyobjc-framework-NotificationCenter==7.3
pyobjc-framework-OpenDirectory==7.3
pyobjc-framework-OSAKit==7.3
pyobjc-framework-OSLog==7.3
pyobjc-framework-PassKit==7.3
pyobjc-framework-PencilKit==7.3
pyobjc-framework-Photos==7.3
pyobjc-framework-PhotosUI==7.3
pyobjc-framework-PreferencePanes==7.3
pyobjc-framework-PushKit==7.3
pyobjc-framework-Quartz==7.3
pyobjc-framework-QuickLookThumbnailing==7.3
pyobjc-framework-ReplayKit==7.3
pyobjc-framework-SafariServices==7.3
pyobjc-framework-SceneKit==7.3
pyobjc-framework-ScreenSaver==7.3
pyobjc-framework-ScreenTime==7.3
pyobjc-framework-ScriptingBridge==7.3
pyobjc-framework-SearchKit==7.3
pyobjc-framework-Security==7.3
pyobjc-framework-SecurityFoundation==7.3
pyobjc-framework-SecurityInterface==7.3
pyobjc-framework-ServiceManagement==7.3
pyobjc-framework-Social==7.3
pyobjc-framework-SoundAnalysis==7.3
pyobjc-framework-Speech==7.3
pyobjc-framework-SpriteKit==7.3
pyobjc-framework-StoreKit==7.3
pyobjc-framework-SyncServices==7.3
pyobjc-framework-SystemConfiguration==7.3
pyobjc-framework-SystemExtensions==7.3
pyobjc-framework-UniformTypeIdentifiers==7.3
pyobjc-framework-UserNotifications==7.3
pyobjc-framework-UserNotificationsUI==7.3
pyobjc-framework-VideoSubscriberAccount==7.3
pyobjc-framework-VideoToolbox==7.3
pyobjc-framework-Virtualization==7.3
pyobjc-framework-Vision==7.3
pyobjc-framework-WebKit==7.3
PyTouchBar==0.2.0

touchbar.py

# from import *
from PyTouchBar import set_touchbar, TouchBarItems, Alignment, prepare_tk_windows
from tkinter import *

def testTk():
    fen = Tk()

    prepare_tk_windows(fen)
    btn = Button(fen, text="Hello")
    btn.pack()

    btn1 = TouchBarItems.SegmentedControls.Control(title='Hello', alignment = Alignment.left, selected = True, width = 100)
    btn2 = TouchBarItems.SegmentedControls.Control(title='World', alignment = Alignment.right, enabled = True, width = 100)

    def action(segCont):
        print (list(segCont.selectedItems()))
        pass

    segcon = TouchBarItems.SegmentedControls([
        btn1,
        btn2
    ], action = action, type = TouchBarItems.SegmentedControls.Type.select_one)

    set_touchbar([segcon])
    fen.mainloop()

if __name__ == '__main__':
    testTk()
Maxmad68 commented 3 years ago

Good morning, Sorry for the late response, Uh, that's strange... The touchbar normally changes when the window is focused, can you confirm the Tkinter window was on the front?

This is a simple "Hello World" program, it just shows a "Hello World!" label on the touchbar for an empty tkinter window:

from PyTouchBar import *

fen = Tk()

prepare_tk_windows(fen)

lbl = TouchBarItems.Label(text = "Hello World!")
set_touchbar([lbl])

fen.mainloop()
letsgo00 commented 2 years ago

Hi, this example does not work for me too, I get a blank touchbar on python 3.10

EDIT: Found the solution, after I added a label or something to the TK window the Label on the touchbar showed up

dregaladodiaz commented 2 years ago
from PyTouchBar import *

fen = Tk()

prepare_tk_windows(fen)

lbl = TouchBarItems.Label(text = "Hello World!")
set_touchbar([lbl])

fen.mainloop()

Using Python 3.8.2 and requirements.txt listed above it works me!, thanks @Maxmad68 . Hint: it didn't works with VSCode integrated terminal, use Terminal instead.

dregaladodiaz commented 2 years ago

Good morning, Sorry for the late response, Uh, that's strange... The touchbar normally changes when the window is focused, can you confirm the Tkinter window was on the front?

This is a simple "Hello World" program, it just shows a "Hello World!" label on the touchbar for an empty tkinter window:

from PyTouchBar import *

fen = Tk()

prepare_tk_windows(fen)

lbl = TouchBarItems.Label(text = "Hello World!")
set_touchbar([lbl])

fen.mainloop()

Any ideas to force Tkinter window to be in front?

SamyBencherif commented 2 years ago

Any ideas to force Tkinter window to be in front?

I recall another thread from a while ago (different project) where it was concluded that this is not possible in mac OS. Not saying that it's actually impossible... but I wouldn't get your hopes up.