Replies: 2 comments
-
@scozzaro checkout the following sample, pretty sure it will guide you along the way: https://github.com/Embarcadero/DelphiFMX4Python/tree/main/samples/ControlsDesktop |
Beta Was this translation helpful? Give feedback.
0 replies
-
Not run in Mac OS.
Thanks
Vincenzo
I developer this code, this code run in windows but not run in mac os.
In this code I developer Menu Bar, Menu Bar is OK in Windows w Mac OS, but
Menu Bar not is Main Menu is as menu in button.
import sys
from delphifmx import *
from delphifmx import Application, Form, MainMenu, MenuItem, MenuBar,
Layout, Button, StyleBook
class MyForm(Form):
def __init__(self, owner):
self.SetProps(Caption="About CaptureOCR", Position="ScreenCenter",
ClientWidth=400, ClientHeight=300)
# --- Menu Principale (MainMenu) ---
# Questo è il tipo di menu che hai già provato, funziona su Windows
self.main_menu = MainMenu(self)
#self.main_menu = MainMenu(Application.MainForm )
self.main_menu.SetProps(Parent=self) # Imposta la Form come parent
#self.main_menu.SetProps(Parent=Application.MainForm) # Imposta la
Form come parent
# Voci del menu 'File' nel MainMenu
#self.mi_file_main = MenuItem(Application.MainForm)
self.mi_file_main = MenuItem(self.main_menu)
self.mi_file_main.SetProps(Parent=self.main_menu, Text="File (Main
Menu)")
self.mi_preferences_main = MenuItem(self.main_menu)
self.mi_preferences_main.SetProps(Parent=self.mi_file_main,
Text="Preferenze", OnClick=self.__menu_preferences_click)
self.mi_about_main = MenuItem(self.main_menu)
self.mi_about_main.SetProps(Parent=self.mi_file_main,
Text="Informazioni", OnClick=self.__menu_about_click)
self.mi_exit_main = MenuItem(self.main_menu)
self.mi_exit_main.SetProps(Parent=self.mi_file_main, Text="Esci",
OnClick=lambda sender: Application.Terminate())
# --- Menu Bar (Componente Bar) ---
# Questo è il componente 'MenuBar' che hai menzionato
self.menu_bar = MenuBar(self)
self.menu_bar.SetProps(
Parent=self,
Height=30, # Altezza della barra
)
# Puoi anche applicare uno StyleBook se hai stili personalizzati
# self.stylebook = StyleBook(self)
# self.stylebook.SetProps(Parent=self, FileName='YourStyle.style')
# Sostituisci con il tuo file di stile
# Application.StyleBook = self.stylebook
# Voci del menu 'Azioni' nella MenuBar
self.mi_actions_bar = MenuItem(self.menu_bar)
self.mi_actions_bar.SetProps(Parent=self.menu_bar, Text="Azioni
(Menu Bar)")
self.mi_action1_bar = MenuItem(self.menu_bar)
self.mi_action1_bar.SetProps(Parent=self.mi_actions_bar,
Text="Azione 1", OnClick=self.__action1_click)
self.mi_action2_bar = MenuItem(self.menu_bar)
self.mi_action2_bar.SetProps(Parent=self.mi_actions_bar,
Text="Azione 2", OnClick=self.__action2_click)
# Aggiungo un Layout per i contenuti sotto i menu
self.content_layout = Layout(self)
self.content_layout.SetProps(
Parent=self,
)
# Un semplice pulsante per mostrare che la finestra è attiva
self.test_button = Button(self.content_layout)
self.test_button.SetProps(
Parent=self.content_layout,
Text="Cliccami",
Width=150,
Height=40,
Position = Position(PointF(100, 100)),
OnClick=self.__button_click
)
def __menu_preferences_click(self, sender):
DialogService.ShowMessage("Hai cliccato 'Preferenze'!")
def __menu_about_click(self, sender):
DialogService.ShowMessage("Questa è un'applicazione di esempio
DelphiFMX Python.")
def __action1_click(self, sender):
DialogService.ShowMessage("Hai cliccato 'Azione 1' dalla MenuBar!")
def __action2_click(self, sender):
DialogService.ShowMessage("Hai cliccato 'Azione 2' dalla MenuBar!")
def __button_click(self, sender):
# Enum values (CHECK THE DELPHI DOCUMENTATION!)
MT_INFORMATION = 0 # Example - check Delphi docs
MT_WARNING = 1 # Example - check Delphi docs
MB_OKCANCEL = 1 # Example - check Delphi docs
MR_OK = 1 # Example - check Delphi docs
MR_NONE = 0 # Important: Need a value for mrNone
def my_message_dialog(AMessage: str, ADialogType, AButtons,
ADefaultButton):
"""
Replicates the Delphi myMessageDialog function using the
delphifmx library.
"""
mr = MR_NONE # Initialize modal result
mr_list = [mr] # Use a list to allow modification within the
callback
def close_dialog_callback(AResult):
"""Callback function to store the modal result."""
mr_list[0] = AResult # Update the modal result in the list
print(f"Callback: Dialog closed with result: {AResult}")
try:
DialogService.MessageDialog(
AMessage=AMessage,
ADialogType=ADialogType,
AButtons=AButtons,
ADefaultButton=ADefaultButton,
AHelpCtx=0,
ACloseDialogProc=close_dialog_callback
)
# Wait for the modal result (similar to
Application.ProcessMessages)
while mr_list[0] == MR_NONE:
# Simulate Application.ProcessMessages (very basic)
# In a real GUI framework, you'd use the framework's
event loop
time.sleep(0.01) # Small delay to avoid busy-waiting
#print("Processing messages...") # Optional: Show that
the loop is running
mr = mr_list[0] # Update mr from the list
result = mr_list[0] # Get the final result
return result
except Exception as e:
print(f"Error in my_message_dialog: {e}")
return -1 # Or some other error code
# Example usage:
result = my_message_dialog(
AMessage="This is a test message from Python!",
ADialogType=MT_INFORMATION,
AButtons=MB_OKCANCEL,
ADefaultButton=MR_OK
)
print(f"Dialog result: {result}")
if __name__ == '__main__':
Application.Initialize()
Application.MainForm = MyForm(Application) # Il form principale è
CaptureOcrForm
Application.MainForm.Show()
Application.Run()
Application.MainForm.Destroy() # Assicurati di distruggere il MainForm
alla chiusura
Il giorno mer 25 giu 2025 alle ore 13:53 Lucas Moura Belo <
***@***.***> ha scritto:
… @scozzaro <https://github.com/scozzaro> checkout the following sample,
pretty sure it will guide you along the way:
https://github.com/Embarcadero/DelphiFMX4Python/tree/main/samples/ControlsDesktop
—
Reply to this email directly, view it on GitHub
<#107 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEAQB4S4PKAHWS2LJVYU3KL3FKER5AVCNFSM6AAAAAB73A43H2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJXGI4DSNI>
.
You are receiving this because you were mentioned.Message ID:
<Embarcadero/DelphiFMX4Python/repo-discussions/107/comments/13572895@
github.com>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, please hel me with this:
self.mm_menu = MainMenu(Application)
self.mm_menu.SetProps(Name="mainMenu")
Thanks
Beta Was this translation helpful? Give feedback.
All reactions